SonarQube does not upload successful analysis on a specific branch

Hi, we have the following problem and we’re out of ideas:

We implemented an Azure pipeline to automatically scan .net code on branches (we work with feature branches), and everything works fine, except on our main branch (which is not actually set as MAIN_BRANCH in SQ, instead we use develop for this). Specifically, both the analysis and publication succeed, but we are unable to access the analysis in the SonarQube portal.

I’ve tried running our pipeline for main and another branch, feature/test-sq, which is a copy of main (I just did git checkout -b feature/test-sq while on main). In both branches the analysis and publication succeed, but we can only see the feature/test-sq branch in the UI.

This is the relevant piece of our pipeline:


  - stage: 'SonarQubeAnalysis'

    displayName: 'SonarQube Analysis'

    dependsOn: []

    jobs:

      - job: SonarQubeAnalyze
        steps:
          - task: UseDotNet@2
            displayName: 'Use .NET 6 Core sdk'
            inputs:
              version: 6.0.x
          - task: NuGetToolInstaller@1
            displayName: 'Install NuGet'
            inputs:
              versionSpec:
          - task: NodeTool@0
            displayName: 'Install Node 20'
            inputs:
              versionSpec: '20.x'
          - script: |
              sudo apt-get update
              sudo apt-get install -y openjdk-17-jdk
            displayName: 'Install JDK 17'
          - task: SonarQubePrepare@5
            continueOnError: true
            inputs:
              SonarQube: '$(sonarQubeServiceConnectionName)'
              scannerMode: 'MSBuild'
              projectKey: 'PROJECT_KEY(REDACTED)'
              projectName: 'PROJECT_NAME(REDACTED)'
              extraProperties: |
                sonar.sources=charts/PROJECT_NAME
                sonar.exclusions=src/COMPANY_NAME.PROJECT_NAME.EntityFrameworkCore.DbMigrations/Migrations/**/*,src/COMPANY_NAME.PROJECT_NAME.HttpApi.Host/wwwroot/libs/**/*
          - task: DotNetCoreCLI@2
            displayName: 'Backend build'
            inputs:
              command: 'publish'
              publishWebProjects: false
              projects: '$(backendSolution)' # Expands to: 'aspnet-core/src/COMPANY_NAME.PROJECT_NAME.HttpApi.Host/COMPANY_NAME.PROJECT_NAME.HttpApi.Host.csproj'
          - task: SonarQubeAnalyze@5
            inputs:
              jdkversion: 'JAVA_HOME_17_X64'
            continueOnError: true
          - task: SonarQubePublish@5
            continueOnError: true
            inputs:
              pollingTimeoutSec: '300'

There aren’t any errors on the tasks’ executions. The SonarQube Analyze task does not output anything relevant to the console.
As far as I can tell, the behaviour on all branches seems identical, except that we can’t access the reports on main.

Any idea what we can do to fix the problem?

Extra information Information:

  • SonarQube edition: Developer
  • Deployed on Kubernetes
  • DevOps platform: Azure DevOps
  • SQ version: 10.4.1.88267

Hi,

What are you trying and what does or doesn’t happen?

Analysis should give you a URL to the analyzed branch at the end. What happens when you access it?

 
Ann

When I access the URL given at the end of the analysis (which conforms to this pattern: https:///dashboard?id= ) the project dashboard is displayed, with the analysis report for develop (our default branch).

I can’t switch to main as it doesn’t show on the dropdown for the branches nor in the “Branches & Pull Requests” page, even though the analysis was marked as successful as well as it’s publication.

Main doesn’t show up here (as I’d expect) even after a successful analysis and publication in my pipeline:
image

I’ve tried running the pipeline again, and I still can’t see the report for main. However, I can see a report for a branch which is identical to main ( feature/try-sq on the picture).

Hi,

This may be about this:

Are you passing a sonar.branch.name parameter with main’s analysis?

The integrations pick up branch and PR parameter values automatically, but your non-main main may be confusing matters. Could you try adding this explicitly?

 
Ann

Hi,

We were able to fix the issue. We realized that analysis performed in main (our DevOps main branch) were uploaded to SonarQube’s main branch (develop in our configuration).

We also misunderstood the difference between reference branch and main branch (we though they were the same). To fix the issue, we kept develop as our reference branch, but configured main to be our main branch in SonarQube (and thus DevOps main branch == SonarQube main branch == main).

As SonarQube didn’t allow us to set main as main branch until we had an analysis on said branch, we needed to set the sonar.branch.name parameter as you suggested.

Thank you for the help,
Rafael.

1 Like