Support different default branch in Jenkins?

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 :slight_smile:
To answer you properly, I need some more information :

  1. What edition of SonarQube do you use? (FYI Community Edition doesn’t provide the support for branches)
  2. What is the DevOps Platform where your code is hosted?
  3. What is your build tool? (Maven, gradle, .NET, etc)

Also,

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.

Kind regards,
Christophe

Hi,

thanks for the answer:

  1. We are using Developer Edition
  2. The code is hosted on an on-premise GitLab instance
  3. 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…

Regards, Tobias

1 Like

Ok, well if it’s on your side… :sweat_smile:
I guess I can mark your post as the solution :wink:
Please come back to our community if you need anything more :wink:

Kind regards,
Christophe

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.