4

We use TeamCity as our build server - how does one setup TeamCity to run SonarQube analysis for C# / .NET solutions?

I'm thinking we'll need to execute the MSBuild runner as a command line task since the TeamCity SonarQube runner doesn't call the MSBuild SonarQube runner.

(It would be great if http://docs.sonarqube.org/display/PLUG/C%23+Plugin described this scenario.)

EDIT

The URL in the original post has changed. Correct link is here.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
John
  • 43
  • 1
  • 3

2 Answers2

4

You're right: There are build step/tasks for the MSBuild SonarQube Runner available out-of-the-box for Team Foundation Server 2015 (and soon Jenkins) - but not for TeamCity. You indeed need to use the command line step/task to manually invoke the MSBuild SonarQube Runner begin and end phase, and MSBuild in between.

From there, the actual configuration and usage is identical to the command line scenario, which is why the TeamCity doesn't have its own documentation.

Dinesh Bolkensteyn
  • 2,971
  • 1
  • 17
  • 20
3

Here is what I did to run this via a build task

  1. Put the following command as a .cmd file in the solution root

    cd %system.agent.home.dir%
    C:\sonarqube\bin\MSBuild.SonarQube.Runner.exe begin /key:MyKey /name:MyProjectName /version:1
    "C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" MySolution.sln /t:Rebuild 
    C:\sonarqube\bin\MSBuild.SonarQube.Runner.exe end
    
  2. Create a "Command" task in TeamCity and execute the .cmd file

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Illuminati
  • 4,539
  • 2
  • 35
  • 55
  • so [this plugin](https://confluence.jetbrains.com/display/TW/SonarQube+Integration) is not using msbuild.sonarqube.runner?? then how do i integrate my nunit and dotcover part?? – harishr May 13 '16 at 11:45
  • The plugin you are referring to seems to be based on sonar runner 2.4. An older version of the SonarQube scanner. At least their latest TeamCity build for TC 10.x is based on this version: https://teamcity.jetbrains.com/viewType.html?buildTypeId=TeamCityPluginsByJetBrains_TeamCitySonarQubePlugin_Build100x – Alix Dec 22 '16 at 11:56
  • The answer did not solve it for me (end of logs): The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects. [11:53:51][Step 3/3] Possible causes: [11:53:51][Step 3/3] 1. The project has not been built - the project must be built in between the begin and end steps [11:53:51][Step 3/3] 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported [11:53:51][Step 3/3] 3. The begin, build or end steps have not all been launched from the same folder – Alix Dec 22 '16 at 11:58
  • Seems the error message is clear. Is it an option to upgrade the MSBuild version ? – Illuminati Dec 23 '16 at 22:09