{"id":40992,"date":"2016-09-28T10:34:13","date_gmt":"2016-09-28T05:04:13","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=40992"},"modified":"2024-01-02T17:44:33","modified_gmt":"2024-01-02T12:14:33","slug":"integrating-sonarqube-with-jenkins","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/integrating-sonarqube-with-jenkins\/","title":{"rendered":"Integrating SonarQube with Jenkins"},"content":{"rendered":"<p>Recently, we got a requirement where <a title=\"Grails and Groovy developers\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails Development team<\/a> needs to have a\u00a0one-click interface to run units test cases for their Grails application and send the results to SonarQube.<\/p>\n<p><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/sonarqube_logo_720.png\" alt=\"Image result for sonarqube\" \/><\/p>\n<p><span style=\"font-weight: 400;\"><strong>SonarQube<\/strong> is a web-based application which is used for centralized management of code quality.\u00a0<\/span>We decided to integrate it with Jenkins to provide a one click solution.<\/p>\n<p><strong>Scenario<\/strong>: Integrate SonarQube with Jenkins to run unit test cases and publish results to SonarQube.<\/p>\n<p><span style=\"font-weight: 400;\">Here is the <strong>step-by-step procedure<\/strong> to perform the scenario:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Setup a Jenkins server if already not using.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Goto plugin-manager of Jenkins to install \u201cSonarQube Plugin\u201d.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Goto \u201cSystem-configuration\u201d of Jenkins to provide \u201cSonarQube\u201d server\u2019s details as below.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-40993 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/sonar.png\" alt=\"sonar\" width=\"962\" height=\"513\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/sonar.png 962w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/sonar-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/sonar-624x332.png 624w\" sizes=\"(max-width: 962px) 100vw, 962px\" \/><\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a Jenkins job and choose one source code management option (say git).<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Under build, add \u201cExecute Shell\u201d as build step and write commands to run unit tests. For example:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p>[js]#!\/bin\/bash<br \/>\ncd \/path\/to\/code\/<br \/>\ngrails clean-all &#8211;non-interactive &#8211;plain-output;<br \/>\ngrails refresh-dependencies;<br \/>\ngrails -Dgrails.env=test test-app:unit &#8211;non-interactive &#8211;plain-output<br \/>\ngrails test-app -coverage -xml[\/js]<\/p>\n<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add \u201cInvoke Standalone SonarQube Analysis\u201d as another build step and add below lines to \u201cAnalysis properties\u201d block:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p>[js]sonar.projectKey=App Name- Any Identifier<br \/>\nsonar.projectName=Project1<br \/>\nsonar.projectVersion=1.0.0<br \/>\nsonar.projectDescription=Static analysis for the AppName<br \/>\nsonar.sources=path\/to\/code\/src, path\/to\/code\/grails-app<br \/>\nsonar.groovy.cobertura.reportPath=path\/to\/code\/target\/test-reports\/cobertura\/coverage.xml<br \/>\nsonar.language=grvy<br \/>\nsonar.sourceEncoding=UTF-8[\/js]<\/p>\n<\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">That\u2019s all. <\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Now, run the <a title=\"Grails Development\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails application<\/a> job and results could be seen on SonarQube server after job completion.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we got a requirement where Grails Development team needs to have a\u00a0one-click interface to run units test cases for their Grails application and send the results to SonarQube. SonarQube is a web-based application which is used for centralized management of code quality.\u00a0We decided to integrate it with Jenkins to provide a one click solution. [&hellip;]<\/p>\n","protected":false},"author":154,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":35},"categories":[2348,1],"tags":[4056,1593,1892,14,3043,1682,1638,4057],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40992"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/154"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=40992"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40992\/revisions"}],"predecessor-version":[{"id":59830,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40992\/revisions\/59830"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=40992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=40992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=40992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}