Search code examples
sonarqubesonarqube5.1tfvcsonarqube-msbuild-runner

How to configure SCM support for MSBuild SonarQube Runner?


I am using SonarQube 5.1 with MSBuild SonarQube Runner for our quality inspection. Currently SCM support is not there although I have already installed TFVC plugin. I get the following log from the analyze process

07:18:22  07:18:22.352 INFO  - Sensor SCM Sensor
07:18:22  07:18:22.352 INFO  - No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
07:18:22  07:18:22.352 INFO  - Sensor SCM Sensor (done) | time=0ms

Then I set the following properties in the general "sonar.properites" file loacated in \sonarqube-5.1.2\conf folder (which I might be doing wrong)

sonar.scm.enabled=true
sonar.scm.provider=tfvc
sonar.tfvc.username=myTFSusername
sonar.tfvc.password.secured=myTFSpassword

I guess these properties should be set in the "sonar-project.properties" file and passed at the time of analysis (correct me if I am wrong). But the problem is since I am using MSBuild SonarQube Runner, sonar-project.properties file is not used anymore and the project properties are passed at the analysis time. If that is the case how should I pass them in?

I searched a lot but could not find a proper solution in this manner and I'd be very glad if someone could help.

Thanks in advance.


Solution

  • Additional properties are passed to the MSBuild SonarQube Runner during its begin phase using the following syntax: /d:key=value.

    So, you can pass all of them:

    MSBuild.SonarQube.Runner begin /k:... /n:... /v:... /d:sonar.scm.enabled=true /d:sonar.scm.provider=tfvc /d:sonar.tfvc.username=... /d:sonar.tfvc.password.secured=....
    

    Auto-detection of the SCM will work if there is a $tf at the "project base dir" level. That directory is computed as the first ancestor path common to all your *.csproj files. You can see its value following the file generated during the end phase: .sonarqube\out\sonar-project.properties. Look for the sonar.projectBaseDir property value near the end of the file. See https://jira.sonarsource.com/browse/SONARMSBRU-8 for details.