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:
- Make TFS output the required test and coverage results files.
- Setup your project to use Sonar.
- 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.
- Part 1 – Make TFS output the required test and coverage results files.
- Part 2 – Setup your project to use Sonar.
- Part 3 – Integrate the “Sonar Runner” into your build.