Versions
- SonarQube Developer Edition Version 8.1
- GitLab Community Edition 12.0.3
- sonarsource/sonar-scanner-cli:latest
What are you trying to achieve
I am trying to report to SonarQube using GitLab CI from any branch.
What have you tried so far to achieve this
SonarQube see the report:
- From
Default Branch
within GitLab CI - Localy (using docker) with any branch name (it add a new branch to SonarQube when I set
sonar.branch.name
to a new name):
docker run -it -v "C:\SRC-PATH:/usr/src" -e SONAR_HOST_URL='https://HOSTNAME' -e SONAR_TOKEN='TOKEN' sonarsource/sonar-scanner-cli:latest
When it work, I can read in the log:
[...]
INFO: Load global settings
DEBUG: GET 200 https://HOSTNAME/api/settings/values.protobuf
[...]
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
But when I push to an other branch than the default branch (even if that branch name exist in SonarQube), I read this in the log and the job fail:
[...]
INFO: Load global settings
DEBUG: GET 401 https://HOSTNAME/api/settings/values.protobuf
[...]
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
I have provided SONAR_HOST_URL and SONAR_TOKEN as CI variables.
Here is my sources files:
sonar-project.properties
sonar.projectKey=PROJECT-KEY
sonar.sources=.
sonar.branch.name=tmp
.gitlab-ci.yml
stages:
- quality
sonarqube-check:
stage: quality
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
script:
- sonar-scanner -X -Dsonar.qualitygate.wait=true -Dsonar.branch.name="${CI_COMMIT_REF_NAME}"
allow_failure: true
Hypothesis
- Is there any GitLab environment variables that interfere with sonar-scanner?
- Is there any other SONAR tag that need to be set in order to report to a specific branch in SonarQube? (or to create a new branch when it is not yet a SonarQube branch?)
Thanks in advance.