Wednesday, 24 February 2016

Using custom Quality Profiles with SonarQube and the new Team Build

When you analyse a project with SonarQube you are running the analyser with a predefined set of rules – they are the most commonly used rules, but not the most comprehensive.

clip_image002

This has a lot of sense, because you might not want to end up cluttering the dashboard with tons of information you don’t actually need or that you can’t work on now.

Here is where custom Quality Profiles come into play. For example, I might want a specific build definition to be used for Code Analysis with all the rules enabled.

After creating a new, empty Quality Profile all I need to do is to search for the rules I want and add them to my custom profile. Searching is quite a powerful experience – you can rely on really a lot of criteria, aside from the simple search on the name.

But in this case, the name (CA, which is the code for each Code Analysis rule ran by Visual Studio) will do:

clip_image004

Here you can select which rules you want to go into the profile. If you want all of them, just go for the Bulk Change button on the top right hand side:

clip_image006

You need to type in the name of the profile now:

clip_image008

That’s it!

clip_image010

Now you need to create a new SonarQube project to use this custom quality profile:

clip_image012

From the Administration menu, select Quality Profiles so you can change the default one with your custom profile:

clip_image014

clip_image016

Eventually, configure the new build definition with the same parameters for the SonarQube analyser:

clip_image018

Now you can run the build as usual, and this project will have different results (of course!).

clip_image020

1 comment:

  1. SonarQube is great, but I created a free and easily installable static code analysis task based on the Resharper CLT. I think it's a good starting point for teams looking to enforce code quality standards and naming consistency

    https://marketplace.visualstudio.com/items?itemName=alanwales.resharper-code-analysis

    ReplyDelete