Scanner build wrapper does not publish correct branch

Hello,

We are using SonarQube v10.7 Developer Edition. When I publish results for a mixed C#/C++ project using the SonarScanner.MSBuild + build-wrapper the corresponding branch is not matched and always publishes to master.

This used to work before the upgrade to v10.6/v10.7. I think it was 8.9 LTS.

We are building and analyzing in an Azure DevOps pipeline but for this project it is not using the Sonar Agent Tasks and instead is using command line scripts to make proper use of the build wrapper as that is what the documentation reads.

All other projects that are strictly C# and not using the build wrapper do not have this issue and the branch is published properly.

Is there something new I need to add to the sonarscanner /begin command or build-wrapper?

Thank you,

Ken

Hi Ken,

Welcome to the community!

Could you share the pipeline, redacted as necessary for this job and for one that works as expected?

 
Thx,
Ann

Hi there and thank you!

The pipeline which doesn’t honor the branch name is a command line task with the following steps:
And this is for a C# mixed with C++ projects.

  1. SonarScanner.MSBuild.exe begin /k:"myproject_myproject_b37ff3b8-3ea9-4963-a8de-5f5984424d5c" /n:"MyProject" /v:"1.0" /d:sonar.cfamily.build-wrapper-output="$(Agent.BuildDirectory)\bw-output" /d:sonar.exclusions="**/things-we-do-not-want"
  2. build-wrapper-win-x86-64.exe --out-dir "$(Agent.BuildDirectory)\bw-output" MSBuild.exe "$(Build.SourcesDirectory)\MyProject.sln" /p:platform="x86" /p:configuration="Release" /t:Rebuild /nodeReuse:False"
  3. SonarScanner.MSBuild.exe end

All other pipelines which are pure C# use the official Sonar AzureDevops Tasks with no special options. The only config is the project key, name, and version.

  1. Prepare Analysis Configuration (official Task)
  2. Run Code Analysis (official Task)
  3. Publish Quality Gate Result (official Task)

Hi,

Thanks for the pipeline details.

The integrations pick up the branch/PR properties from your environment and pass them forward automatically. Since your C#/C++ analysis is fully manual, that part will need to be manual too. You’ll need to explicitly set sonar.branch.name in your analysis properties (the begin step, I believe). And for completeness, the docs are here.

 
HTH,
Ann

Will try that out thank you Ann