Override SonarQube automatic branch detection
00:37 05 Oct 2022

SonarQube has the concept of a main branch irrespective of its actual name. According to the documentation, the key is not to pass the sonar.branch.name property to the analysis.

So far, so good. However, when my Gradle build in Github does not set the property, then automatic branch detection kicks in and I get:

Detected branch/PR in 'GitHub Action'
Auto-configuring branch 'develop'

Well, that’s unfortunate, because now sonar.branch.name is set to develop, and SonarQube will not accept it as the main branch. This develop is set as the default branch in Github, but the scanner seems not able to detect this. Automatic detection will not happen when I set the property explicitly, but then of course it is still set to something.

The question is now: Can I skip branch detection in the Sonarscanner without setting sonar.branch.name? Can I influence the branch detection so it will correctly detect it is on the default branch?

We are using Github actions in a GitHub Enterprise Server 3.5.5, for reference.

gradle sonarqube github-actions sonarqube-scan