<div class="table-wrap"><table style="line-height: 1.4285715;" class="confluenceTable"><tbody><tr><td class="highlight-grey confluenceTd" data-highlight-colour="grey">By <a target="_top" href="http://www.sonarsource.com">SonarSource</a> – GNU LGPL 3 – <a target="_top" href="http://jira.sonarsource.com/browse/SONARJNKNS">Issue Tracker</a> – <a target="_top" href="https://github.com/SonarSource/jenkins-sonar-plugin">Sources</a> <br> <div> <div style="padding-top:10px;padding-bottom:5px"> <span style="font-size:larger;"><strong>SonarQube Scanner for Jenkins 2.3</strong></span> <!-- – Compatible with SonarQube 4.5.4+ (LTS)--> <br> </div> </div> </div> </td></tr></tbody></table></div>
You can trigger SonarQube analysis from Jenkins using either a:
SonarQube Scanner for Jenkins
Install the SonarQube Scanner for Jenkins via the Jenkins Update Center.
You can define as many SonarQube servers as you wish. Then for each Jenkins job, you will be able to choose which server to use for the SonarQube analysis.
To add a SonarQube server, just follow the three steps below:
This step is mandatory if you want to trigger any of your SonarQube analyses with the SonarQube Scanner.
You can define as many SonarQube Scanner launchers as you wish. Then for each Jenkins job, you will be able to choose with which launcher to use to run the SonarQube analysis.
To add a SonarQube Scanner:
If you don't see a drop down list with all available SonarQube Runner versions but instead see an empty text field then this is because Jenkins still hasn't downloaded the required update center file (default period is 1 day). You may force this refresh by clicking 'Check Now' button in Manage Plugins >> Advanced tab.
This step is mandatory if you want to trigger SonarQube analyses using the SonarQube Scanner for MSBuild.
You can define as SonarQube Scanners for MSBuild as you want. The tool can be automatically installed by Jenkins, or you can define the path where it is installed by unchecking "Install automatically".
For each Jenkins job, you will then be able to choose which launcher to use. If there is only one launcher defined, it will be implicitly selected.
In the global configuration page, you can add installations of the SonarQube Scanner for MSBuild:
If the ability to inject SonarQube configurations as variables in jobs is enabled in the Jenkins' global configuration, you will have ability to activate it in your job. If multiple SonarQube instances are configured, you will be able to choose which one to use.
|Press the help button to learn which variables you can use in your build.|
You may then use any of the SonarQube Scanners to perform the analysis, such as Maven, Gradle, Ant, etc. An example using maven:
When analyzing with SonarQube Scanner for MSBuild, there are typically 3 steps:
The begin and end steps are specific job types provided by Sonar Jenkins Plugin:
To perform the rebuild with MSBuild ('msbuild /t:Rebuild'), either configure it with the Jenkins MSBuild plugin, or execute it as a Windows batch command.
Therefore, a typical configuration of a job will have 3 steps:
Go to the Build section, click on Add build step and choose Invoke Standalone SonarQube Analysis:
Configure the SonarQube analysis. You can either point to an existing sonar-project.properties file or set the analysis properties directly in the Project properties field:
|The Post-build Action for Maven analysis is deprecated.|
Use the Build Environment option "Prepare SonarQube Scanner environment" (this option is only available if it has been enabled at the Global level by a Jenkins administrator) to inject SonarQube-related values as environment variables, such as:
SONAR_MAVEN_GOAL- defaults to sonar:sonar, but may vary depending on the sonar-maven-plugin specified for the selected SonarQube server
Use the help icon () to see the full list of available variables. Some values will be blank, depending on what was defined for the server.
Once the environment variables are available, use them in a standard Maven build step: