The SonarCloud scan is analyzing the default master branch instead of the develop branch

1k Views Asked by At

How can I change the main branch to develop so that it directly publishes results on the SonarCloud dashboard, displaying the number of lines of code scanned, without the need to check the branch separately for viewing the results?

2

There are 2 best solutions below

3
On

You cannot change which branch is treated as the main branch on sonarcloud as per the sonarsourcer replied here.

But to display the result on overview page, checked on my side with DevOps pipeline, if you change the dev1 branch as default branch(commit c44b781b):

enter image description here

After pipeline(SonarCloudAnalyze@1 and SonarCloudPublish@1 tasks), on the sonarcloud overview page, it will show the result correctly. Although on sonar cloud -> branches page, it will show master as main branch.

enter image description here

0
On

In addition to the below about changing your default branch in your repositry, if using Github, on the .github/workflows/build.yml in your repo, update the section:

on:
  push:
    branches:
      - main    # The default branch

to have your specific branch.