C# Code missing when specifying a target branch with MSBuild Scanner

549 views
Skip to first unread message

kri...@gmail.com

unread,
May 25, 2018, 12:09:41 PM5/25/18
to SonarQube
I'm using the Sonar MSBuild Scanner to analyze a C# project. It seems that whenever I specify a target branch, the results, code, and files do not show up on that branch in the SonarQube server. If I don't specify the sonar.branch.target parameter (so it will default to main branch) then the issues/code/etc. do appear.

My Environment
  • SonarQube Server: 7.1
  • Branch Plugin: 7.1
  • Sonar C# Plugin: 7.1.0.5212
  • Sonar MSBuild Scanner: 4.2.0.1214
  • MSBuild: 14.0.25420.1
  • Visual Studio: 2015
  • .NET: 4.6.01590
Steps to Reproduce
  1. Create a new project on the server, let's give it name and ID "test" and assume it has the main branch of "master".
  2. Execute the "begin" command of a short-lived branch using the MSBuild scanner:
    SonarScanner.MSBuild.exe begin /key:test /version:1.0 /d:sonar.branch.name=short_lived_branch /d:sonar.branch.target=master

  3. Perform the build:
    MSBuild.exe /t:Rebuild

  4. Execute the "end" command of the MSBuild scanner:
    SonarScanner.MSBuild.exe end

  5. Browse the short lived branch on the project on the SonarQube server. In my case, I see no code, issues, etc.
  6. Let's repeat, but don't specify a target branch.
  7. Execute the "begin" command of a short-lived branch using the MSBuild scanner:
     SonarScanner.MSBuild.exe begin /key:test /version:1.0 /d:sonar.branch.name=short_lived_branch

  8. Perform the build:
    MSBuild.exe /t:Rebuild

  9. Execute the "end" command of the MSBuild scanner:
    SonarScanner.MSBuild.exe end

  10. Now if you browse the short lived branch on the project on the SonarQube server, you should see your code and any issues that exist.
  11. If your perform the analysis again with the target branch specified, your code/issues/etc will disappear again.
Expected Behavior
  • I would expect the code from my short-lived branch analysis to be visible when I specify a target branch.
Notes
  • The appears to occur regardless if main branch (which I'm targeting) is actually populated with an analysis or not.
  • I have not tested this with the CLI scanner or other languages.

Amaury Leve

unread,
May 28, 2018, 9:35:07 AM5/28/18
to kri...@gmail.com, SonarQube
Hi,

I have followed these steps and I do see code, issues....

1. Create a new project on the server, let's give it name and ID "test" and assume it has the main branch of "master". 

2. Create a new console application (ConsoleApp23 in my case)

3. Run the "begin" step
SonarScanner.MSBuild.exe begin /k:test /d:sonar.branch.name=short_lived_branch /d:sonar.branch.target=master

4. Build:
MSBuild.exe /t:Rebuild

5. Run the "end" step
SonarScanner.MSBuild.exe end

6. Browse the project page:


image.png

7. Open the "master" dropdown on the right of the project name 
image.png

8. Select "short_lived_branch"
image.png

See the issues.

Is there anything different on your side when doing the same steps?

Cheers,
Amaury

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/30528f05-3acc-4238-b70b-c7de316ce46c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Amaury Levé | SonarSource

Software Developer - .Net Team

http://sonarsource.com


Are you using SonarLint in your IDE? 

kri...@gmail.com

unread,
May 29, 2018, 4:48:00 PM5/29/18
to SonarQube
I figured out what was occurring.

I was adding static analysis support on a new branch in an existing git repository. This meant only the build script was changing, not any of the source files. So because this was a short-lived branch and none of the source files changed from the target branch (master); no files were analyzed. If I changed some of the source files, then they would get scanned.

Amaury Leve

unread,
May 30, 2018, 1:05:41 AM5/30/18
to kri...@gmail.com, SonarQube
Indeed we only analyze the diff between branches. 

Cheers 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages