Integrating SonarQube with Jenkins

28 / Sep / 2016 by Navjot Singh 0 comments

Recently, we got a requirement where Grails Development team needs to have a one-click interface to run units test cases for their Grails application and send the results to SonarQube.

Image result for sonarqube

SonarQube is a web-based application which is used for centralized management of code quality. We decided to integrate it with Jenkins to provide a one click solution.

Scenario: Integrate SonarQube with Jenkins to run unit test cases and publish results to SonarQube.

Here is the step-by-step procedure to perform the scenario:

  1. Setup a Jenkins server if already not using.
  2. Goto plugin-manager of Jenkins to install “SonarQube Plugin”.
  3. Goto “System-configuration” of Jenkins to provide “SonarQube” server’s details as below.

  4. Create a Jenkins job and choose one source code management option (say git).
  5. Under build, add “Execute Shell” as build step and write commands to run unit tests. For example:

    cd /path/to/code/
    grails clean-all –non-interactive –plain-output;
    grails refresh-dependencies;
    grails -Dgrails.env=test test-app:unit –non-interactive –plain-output
    grails test-app -coverage -xml[/js]

  6. Add “Invoke Standalone SonarQube Analysis” as another build step and add below lines to “Analysis properties” block:

    [js]sonar.projectKey=App Name- Any Identifier
    sonar.projectDescription=Static analysis for the AppName
    sonar.sources=path/to/code/src, path/to/code/grails-app

  7. That’s all.

Now, run the Grails application job and results could be seen on SonarQube server after job completion. 


Leave a Reply

Your email address will not be published. Required fields are marked *