TeamCity integration with SonarQube is implemented via the open-source SonarQube plugin for TeamCity.
The plugin provides a simple user interface for configuring connection between TeamCity and SonarQube servers, and allows you to trigger analysis using the SonarQube Runner as a build step in TeamCity.
When the analysis is completed, the results are automatically published to the SonarQube server.
This page explains how to configure and use TeamCity integration with SonarQube.
On this page:
Installing Plugin
Download the plugin from the public TeamCity server and install it as described here.
After the SonarQube Runner plugin is installed, the SonarQube Servers page appears in the project settings and the SonarQube Runner is added to the list of the available runners for a Build Step.
TeamCity 8.1 or greater is supported
Configuring SonarQube Server Connection
To enable the integration, you need to create at least one connection to a SonarQube Server. The connection will be used by TeamCity to send data to the SonarQube Server.
SonarQube Servers connections are managed in the SonarQube Servers page of the Project Settings, where the SonarQube server name and URL as well as the database settings are specified.
For details on the database settings, see the SonarQube documentation. Example settings for different databases can be found here.
The connection defined in a project will be available to all its build configurations and subprojects.
Configuring SonarQube Build Step
After the integration is enabled, you can add and configure the SonarQube Build Runner as the final step of the build you want to run analysis on.
Triggerring the analysis with Maven is not directly supported. To use the SonarQube runner with a Maven project, add the
sonar:sonar
goal to your project. See SonarQube documentation for detals.
In the runner settings, you need to select a connection to the server to send the data to. Other fields are to be configured as described in the SonarQube Runner documentation. sonar-project.properties
are partially supported.
It is also recommended to provide paths to directories containing your sources root, test root, and binaries.
You can add more parameters for the SonarQube Runner in the "Additional parameters" field of the Advanced Options.
The plugin will trigger the SonarQube analysis with a SonarQube Runner and publish the results to the SonarQube server.
Viewing analysis results
Once the build is finished, the View in sonar link appears on the Build Results page allowing you to navigate to the SonarQube dashboard to view the results of the analysis.
SonarQube Build Breaker is supported by the TeamCity plugin: the Build Breaker messages are parsed by TeamCity and added as Build Problems.
Configuring SonarQube Runner with:
ReSharper inspections (Inspections (.NET) runner)
- Add
/output=%system.teamcity.build.tempDir%\inspectReport.xml
to the 'Additional inspectCode.exe arguments' - In SonarQube Runner step, add the following to the 'Additional parameters' field:
-Dsonar.resharper.cs.reportPath=%system.teamcity.build.tempDir%\inspectReport.xml
-Dsonar.resharper.solutionFile=pathToSolutionFile
14 Comments
Nick Sorokin
Hi,
I'm just curious: when SonarQube plugin will be published as Maven Release instead of SNAPSHOT version currently available for download from public TeamCity server? I would prefer to install the stable version but not a development one.
Regards,
Nick Sorokin
Harish Rathi
this plugin is not updating my sonarqube with nunit/dotcover results, how do i do that?
Andrey Titov
The main problem is to make nunit and dotcover running under TeamCity generate report files which could be recognized by SonarQube runner. Try to refer this post: http://stackoverflow.com/a/13193132. Please ask me any questions if you'll have problems (better on https://github.com/JetBrains/TeamCity.SonarQubePlugin/issues). In the meantime I'll make a new wiki page describing your case.
Ilsa Loving
Why does teamcity need direct access to the SonarQube database? That doesn't seem right to me.
Andrey Titov
TeamCity supports legacy SonarQube Runner which used direct access. Current SonarQube Scanner uses other scheme to publish data so database config is not mandatory.
Domingos Silva
Hi,
The plugin supports MSBuild Runner for SonarQube?
Since it is necessary to Start the MSBuild Runner before the build and then stop it afterwards (when done manually) it is not clear whether or not this actually supports that since it explicitly says to be put at the end of the build process.
Thanks!
Andrey Titov
Currently this plugin doesn't support SonarQube MSBuild Runner. You can still try using this plugin (some functionality can be inaccessible) or use TC command line runner to manually start and finish the SQ Runner.
Vu Ngoc Quang
I am using Jacoco Coverage runner in my TeamCity Gradle build step. In the next step I have SonarQube runner, but I don't know where the coverage report in the previous step gets stored ( I have no access to TeamCity build agent at my company ) so I wonder where the default location is so I can point
-Dsonar.jacoco.reportPaths
to it?Also, what about IntelliJ coverage runner? how should I feed the report to the next step (SonarQube runner)? Thank you
Andrey Titov
Actually SonarQube Plugin should autodiscover jacoco coverage file and pass needed properties to the Scanner like this:
Vu Ngoc Quang
Yes, it works now. Thank you!
ivy liu
It looks like SonarQube Runner don't read sonar properties in pom.xml. We need add additional parameters in SonarQube runner step to make it work. Does it work as design? Will it be improved in the future?
Andrey Titov
You can pass any additional properties through Additional Parameters field or through sonar-project.properties file (see https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner)
Gaurav Sharma
Can this plugin run/support analysis for javascript (ReactJs) based project with SonarQube ?
Andrey Titov
The plugin just provides UI to configure analysis and runs SonarQube Scanner on agent. So if the Scanner supports ReactJs then the TeamCity SonarQube Plugin does.