Default branch from Azure DevOps is incorrectly getting displayed on SonarCloud

Template for a good new topic, formatted with Markdown:

  • ALM used (Azure DevOps)
  • CI system used (Azure DevOps)
  • Scanner command used when applicable (private details masked)
  • Languages of the repository - DotNet

Hello,

We recently moved from SonarQube and SonarCloud and started seeing this issue with default branch.
We had our default branch set to 1.12.0 in Azure DevOps. But when we ran our first analysis from the Release_1.13.0 branch, SonarCloud decided to make a new Main branch called Release_1.12.0. Not exactly what we were expecting!
We tried to fix it by changing the default branch on Azure DevOps to 1.13.0, but SonarCloud kept pushing all the metrics to the Release_1.12.0 branch. We even created a new branch, Release_9.9.9, and made it the default, but no luck. SonarCloud still shows Release_1.12.0 as the default branch.

We found a suggestion to rename the Release_1.12.0 branch on SonarCloud to Release_1.13.0, but that means we’d have to do this every time we create a new branch in Azure DevOps. That’s not really a practical solution for us.

Could you please advise?

Thanks.

Hi,

I’m not sure I understand. Could you share a screenshot that shows this?

 
Thx,
Ann

Main branch in this project is set to Release_1.12.0.

But the sha link (in red), takes me to the Release_1.13.0 branch on Azure DevOps.

The linking between Azure DevOps and SonarCloud is not working as expected. SonarCloud is not able to recognize that the metrics that are coming from Azure DevOps are coming from Release_1
13.0 branch and not Release_1.12.0 branch.

Thanks.

Hi,

Can you share your pipeline, please?

 
Thx,
Ann

Hello,

Here’s the short yaml with all the important tasks…

- task: SonarCloudPrepare@1
  displayName: 'Prepare Sonar Cloud'
  inputs:
    SonarCloud: 'SonarCloud'
    organization: 'xxx'
    scannerMode: 'MSBuild'
    projectKey: 'yyy'
    projectName: 'zzz'
    extraProperties: |
      sonar.coverageReportPaths=$(Build.SourcesDirectory)/coverlet/reports/SonarQube.xml
      #sonar.test.inclusions=**/*.Tests/**,**/*.Test/**,**/*.tests/**,**/*.test/**
      sonar.exclusions=**/lib/**/*.*,**/css/**/*.css,**/css/*.css,**/js/*.js,**/js/**/*.js
      #sonar.coverage.exclusions=**/Program.cs

- task: DotNetCoreCLI@2
  displayName: 'Run Unit Tests'
  inputs:
    command: 'test'
    projects: '**/*Test*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "XPlat Code coverage"'

- task: reportgenerator@5
  displayName: 'Generate cobertura report'
  inputs:
    reports: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
    targetdir: '$(Build.SourcesDirectory)/coverlet/reports'
    reporttypes: 'HtmlInline_AzurePipelines;Cobertura;SonarQube'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:  
    codeCoverageTool: Cobertura  
    summaryFileLocation: '$(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml'

- task: SonarCloudAnalyze@1
  displayName: 'Run Code Analysis'
  inputs:
    jdkversion: 'JAVA_HOME_21_X64'

- task: SonarCloudPublish@1
  displayName: 'Publish Quality Gate Result'
  inputs:

Hi,

I was hoping for the full pipeline.

You see, analysis should be picking up branch identity automatically from the environment. Since your actual analysis tasks look okay, the fact that it’s not signals that something is likely off in the environment.

Can you also share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann