Integrating SonarQube Metrics into a TFS build – Intro

I have been working on getting SonarQube integrated into our nightly build which is run out of TFS. If you don’t know what SonarQube is check it out. Its a good way to centralise information about your code which is good for capturing and tracking metrics for those people who care about KPIs (if we must have them at least they can be about something positive towards code quality) whilst giving those people that don’t a central place to see issues with code quality etc that they can improve upon.

Previously we had a separate Jenkins build reading source from TFS but we wanted to get rid of this additional build and just do it once in TFS – seemed a bit wasteful and time consuming to sort out Jenkins as well as TFS. It turns out I have had pretty good timing as (at the time of writing) it is only recently that Sonar can handle the upload of Microsoft’s test results and coverage files (.trx and .coverage respectively) – http://docs.codehaus.org/display/SONAR/C%23+Plugin.

The approach – use standard TFS Build toolkit

Unfortunately integrating SonarQube into a TFS build was not the most straight forward process. There are custom activities out there already that can do the scan and upload aspects for you (http://www.vlaquest.com/2013/10/sonar-build-activity-for-tfs-updated/). I’m not overly fond of custom assemblies because you then need to create a project to manage your template with lots of references to remove all the warnings and errors and actually allow you to configure the imported activity, and from that point on it becomes a need to edit your template from a project – I know .. its no big deal .. but I’d rather keep it as a simple editable workflow. Then you need to make the assemblies available to the build controller which I prefer to avoid needing to do – plus I’ve had issues getting this to work with the hosted Team Foundation Service in the past which has historically made me avoid them.

Taking these points into account I’ve gone for an approach that means most of the work can be done in the build template using the standard activities – with the rest being done in a few batch files that can sit in source.

I’ll lead you through the process.

Overview of the steps required

There are quite a few steps to this and there is quite a bit to digest so I will split this across a few blog posts with the major topics being:

  1. Make TFS output the required test and coverage results files.
  2. Setup your project to use Sonar.
  3. Integrate the “Sonar Runner” into your build.

The solution demonstrated was adequate for the purpose of what I was trying to achieve but you may wish to rearrange a few of the steps to fit your scenario. There will be a bit of discussion around the steps to help you understand any decisions I have taken and provide a bit of background but if all you are interested in is how to do this then ignore this text and just follow the steps.

Good luck with your integration.


Advertisements

4 thoughts on “Integrating SonarQube Metrics into a TFS build – Intro

  1. Thank you very much for the extensive documentation! In fact, we’re going to incorporate the described changes into our default build templates.

    Have you added the SonarQube analysis step to Visual Studio’s default templates? If so, could you consider providing a download of the particular .xaml files?

    • Hi Sebastian. I achieved my integration of Sonar in an existing and heavily modified build template (that I can’t share). I haven’t added it to a standard build template as yet and I have since moved onto other things than capturing metrics. If I revisit at some point in the near future I’ll knock one up and share it but I wouldn’t wait for me to do one as it may not happen any time soon. Thanks for reading and hope your own efforts to integrate go well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s