It seems that SonarQube is hardcoding the name “master” as the default branch somewhere when using CI auto-configuration (I looked through sonarqube/sonar-scanner-engine/src/main/java/org/sonar/scanner/ci at master · SonarSource/sonarqube · GitHub but couldn’t quite figure out how the default branch is selected) - when analysing a project with a different default branch for the first time, that branch is created as a non-default branch. Since [SONAR-11853] Auto-configuration pull requests on Jenkins - SonarSource suggests no configuration should be necessary, would it be possible for SonarQube to auto-detect the default branch in a repository? Jenkins is providing the variable
BRANCH_IS_PRIMARY since branch-api 2.6.4, so that could be used to implement this feature.
As an aside (until auto-configuration works properly): What is the minimal configuration I need to pass to the scanner to avoid auto-configuration? Previously, we were setting
scm.branch for non-default branches, but how do I force a branch to BE the default branch?
Hi @TobiX ,
Thank you for your feedback
To answer you properly, I need some more information :
- What edition of SonarQube do you use? (FYI Community Edition doesn’t provide the support for branches)
- What is the DevOps Platform where your code is hosted?
- What is your build tool? (Maven, gradle, .NET, etc)
when analysing a project with a different default branch for the first time, that branch is created as a non-default branch
I’m surprised. Normally the default branch should be fetched automatically by SonarQube. It’s retrieved from the SCM you use, when available (the git protocol itself doesn’t know the principle of a “default branch”).
The SonarQube plugin should pass the branch name automatically to the scanner when triggering the analysis.
thanks for the answer:
- We are using Developer Edition
- The code is hosted on an on-premise GitLab instance
- This build is running with Maven
I just realized there might be something wrong on my side - since our Jenkins setup is a bit “special” (okay, which Jenkins setup isn’t?), which might impact the scanner’s ability to detect the “correct” repository and branch…
Ok, well if it’s on your side…
I guess I can mark your post as the solution
Please come back to our community if you need anything more
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.