Search code examples
sonarqubejenkins-pluginssonar-runner

FxCop analysis using Jenkins SonarQube plugin?


I'm trying to get FxCop analysis for .NET projects within a Jenkins build (Invoke Standalone SonarQube Analysis).

Configuration looks like this:

  • SonarQube 5.1.2
  • C# 4.2
  • sonar-runner 2.4
  • Jenkins: SonarQube Plugin 2.2.1

And the main problem is that when I enable FxCop rules in SonarQube I get the error:

java.lang.IllegalArgumentException: The property "sonar.cs.fxcop.assembly" must be set and the project must have been built to execute FxCop rules. This property can be automatically set by the Analysis Bootstrapper for Visual Studio Projects plugin, see: http://docs.codehaus.org/x/TAA1Dg.If you wish to skip the analysis of not built projects, set the property "sonar.visualstudio.skipIfNotBuilt".

However, if I explicitly set sonar.cs.fxcop.assembly in sonar-project.properties to point at an assembly (.dll) I get the analysis for that one, but the project has multiple assemblies for which I'd like the FxCop analysis. Even if it's possible to set a list of assemblies as an argument (is it?) this is not an elegant/generic solution and patterns are not an accepted value.

I understand that MSBuild SonarQube Runner could solve this problem (no need to set sonar.cs.fxcop.assembly), but it looks like it's not a good candidate for the Jenkins plugin (under SonarQube Runner installations), as only sonar-runner installations are allowed.

Is there any way I could get FxCop working using the Jenkins plugin and sonar-runner without setting the sonar.cs.fxcop.assembly property?


Solution

  • Indeed, MSBuild projects should be analyzed using the MSBuild SonarQube Runner, for which there is currently no dedicated build step in Jenkins yet: You can use the Execute Windows batch command step to execute MSBuild.SonarQube.Runner.exe begin ... and MSBuild.SonarQube.Runner.exe end in between the call to msbuild.

    With the upcoming release of the Jenkins SonarQube plugin version 2.3, there will be two dedicated build steps, one for the MSBuild SonarQube Runner's begin call, and another one for the end call. See https://jira.sonarsource.com/browse/SONARJNKNS-219

    You should not use the sonar-runner, nor the Invoke Standalone SonarQube Analysis Jenkins build step (which simply calls the sonar-runner) to analyze .NET projects: The MSBuild SonarQube Runner is the way to go.