Unability to disable main branch auto detection on Jenkins


SonarQube version: 8.5.0

When the property sonar.branch.name is not passed when calling SonarQube gradle plugin, expected behaviour is to assume the branch name is master and set it as main branch in sonar project. This feature works fine when running the plugin locally, but when running it on Jenkins, branch name is autoconfigured. In our case the main branch name is main and described behaviour causes SonarQube to detect branch as main and still assume main project branch as master which leads to following error:

“master” branch has not been analyzed yet and you have multiple branches already. It looks like it is not your Main Branch, check your configuration.

Is there any way to disable autoconfiguration on Jenkins or mark branch as main when running the scanner?


Hi @janup ,

Right now, there’s no way to disable this auto-detection feature. And the main branch in SonarQube should always correspond to the name of your actual main branch.

What you can do is “rename” your master branch in SonarQube.

Warning: this will mean you lose any existing history on your main branch.

  • Go to your project in SonarQube, and click on Project Settings > Branches & Pull Requests.
  • Find you main branch, and under Actions, choose Delete branch.
  • Find your master branch, and under Actions, choose Rename branch. Call it “main”.

This way, the analysis will correctly be detected as targeting the main branch.

We know this isn’t an ideal solution, and we have plans to address it in the 9.x series.

Also, note that in 8.8, we’ve introduced auto-detection of the main branch name when you set up a new project, if you use SonarQube in conjunction with GitHub, GitLab, Bitbucket or Azure DevOps. This should limit this kind of issues for new projects at least.