SonarQube 8.9 - Git default branch not being passed

Must-share information (formatted with Markdown):

  • which versions are you using: 8.9 Developer Edition
  • what are you trying to achieve: Default branch in gitlab is ‘develop’ but sonarqube says ‘master’

Per 8.9 LTS release notes:

Q. How can I specify the default branch for each repository? We frequently have master identifed in Github but would like to treat the dev branch as the default one in SonarQube.
A. With project import, new projects show the same name for the main branch that’s used in your DevOps platform. So if it’s ‘Develop’ in GitHub, it’ll be ‘Develop’ in SonarQube.

This should mean that if in gitlab we have develop as default branch, on initial project scan via the docker sonar-scanner, it will create the project and then set develop to be the default branch. However, this is not the case. It is still utilizing the old method of setting master as default, and just adding develop as a new branch.

This is the code we are using to run scans/initialize

- sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.projectKey=${CI_PROJECT_NAMESPACE}-${CI_PROJECT_NAME}${SONAR_HOST_URL} -Dsonar.login=${SONAR_TOKEN}


How old is this project? Was it originally imported into a very recent version of SonarQube?


This project and others have never existed prior to our upgrade to 8.9. I have since tried initializing/importing multiple new projects and all have the same behaviour. Sonar seems to be ignoring Gitlab’s default branch behaviour and just using “master” instead.


Thanks for the followup. I’m going to refer this internally.