devxlogo

Managing Code Debt in Team Foundation Server with SonarQube

Managing Code Debt in Team Foundation Server with SonarQube

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 extensionsplugins?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:

  • begin
  • /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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist