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.
I have an answer that feels more like a work-around, but seems to work. Within SonarQube, I can rename the main branch. This is more than just a cosmetic change. I set the value to develop
, and the next SonarQube analysis with sonar.branch.name=develop
was accepted as the main branch. This works – for now – but does not seem to be the documented and preferred way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With