SonarQube is a popular open source platform for managing quality in the scope of an application life cycle. It covers the seven axes of quality around the source code, namely — code clones, unit testing, complexity, potential source of bugs, adherence to static rules, documentation in the form of comments, and architecture and design. The beauty of SonarQube is not only its ability to combine matrices for better correlation and analysis, but also to mix them with historical results. SonarQube is extensible using plugins and provides out-of-the-box support for multiple languages including C#. It also offers a plugin for MS Build, letting you integrate SonarQube with Team Build definitions in TFS and making code debt analysis part of your build definitions.
To configure SonarQube for TFS, first you can download SonarQube.
Next you can download the C# and MS Build plugins.
Note that you will need Java running on your system to configure and run SonarQube.
Extract the downloaded package to a local folder in your system and place the C# plugin jar file under the extensions\plugins directory. Run the StartSonar.bat file in the bin folder to start the SonarQube server. SonarQube by default runs on the 9000 port. Once the server is started you can navigate to the http://localhost:9000 url to access the SonarQube portal.
Next extract the MS Build plugin package to a local folder and verify that the sonar.host.url property in the SonarQube.Analysis.xml file has the correct SonarQube server address configured.
You are now ready to configure SonarQube analysis with your TFS Team build definition. Modify your team build definition to set the Pre-build script path under advance properties to the full path to MSBuild.SonarQube.Runner.exe file. Also set the Pre-build script arguments to contain the following four arguments:
- /k: [the project key of the SonarQube project]
- /n: [the project name]
- /v: [the project version]
Also set the Post-test script path to the full path to MSBuild.SonarQube.Runner.exe, and the Post-test script arguments to contain the argument "end".
You are all set. Once you run the build, in the build report you will see the SonarQube analysis summary and a link to see the analysis results that will direct you to the dashboard.
ALM, Team Foundation Server, application lifecycle management, application life cycle management, SonarQube, TFS 2015