I did a complete setup of a CI/CD pipeline in order to get closer to your setup but this is still not enough for reproducing the issue.
Everything points to my local SonarQube, so for that reason I used a public URL pointing to my machine in GitLab, while the sonar.core.serverBaseURL
points to localhost:9000.
With this setup I can see in the logs of the GitLab job the expected URL with the value defined in sonar.core.serverBaseURL
. I am using the latest (4.8.0) sonar-scanner-cli running on docker.
Running with gitlab-runner 15.9.0~beta.115.g598a7c91 (598a7c91)
on blue-4.shared.runners-manager.gitlab.com/default J2nyww-s, system ID: s_5425356d8adf
feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor
Using Docker executor with image sonarsource/sonar-scanner-cli:latest ...
Pulling docker image sonarsource/sonar-scanner-cli:latest ...
Using docker image sha256:b54a89b534a10f0af24dab4d4b1e2d1d92ebfd15880b456e9039f05f92f70c87 for sonarsource/sonar-scanner-cli:latest with digest sonarsource/sonar-scanner-cli@sha256:589613d01625fb0a891eec712850f0ca0d0046e032e9ec8834885fc1c19f5736 ...
...
...
INFO: ------------- Check Quality Gate status
INFO: Waiting for the analysis report to be processed (max 300s)
INFO: QUALITY GATE STATUS: PASSED - View details on http://localhost:9000/dashboard?id=matteo.mara_testproject_AYf7h9jrxIZ12fPmiaON&pullRequest=1
INFO: Analysis total time: 34.695 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 38.695s
INFO: Final Memory: 14M/56M
INFO: ------------------------------------------------------------------------
Saving cache for successful job
Creating cache sonarqube-check-non_protected...
.sonar/cache: found 22 matching artifact files and directories
Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/45/sonarqube-check-non_protected
Created cache
Cleaning up project directory and file based variables
00:01
Job succeeded
The same URLs can be seen in the MR decoration (that is the case also with your setup).
At this point I tried to redefine the sonar.core.serverBaseURL in a way that only the scanner could fetch, and I modified the .gitlab-ci.yml by adding the definition of the sonar.core.serverBaseURL there too (overriding the one defined in my instance)
script:
- sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.core.serverBaseURL=http://wrongUrl
Here the full file:
sonarqube-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.core.serverBaseURL=http://wrongUrl
allow_failure: true
rules:
- if: $CI_COMMIT_REF_NAME == 'main' || $CI_PIPELINE_SOURCE == 'merge_request_event'
With this setup in place I managed to have two different values, in the scanner logs and in the decoration of the MR.
INFO: ------------- Check Quality Gate status
INFO: Waiting for the analysis report to be processed (max 300s)
INFO: QUALITY GATE STATUS: PASSED - View details on http://wrongurl/dashboard?id=matteo.mara_testproject_AYf7h9jrxIZ12fPmiaON&pullRequest=1
INFO: Analysis total time: 31.423 s
INFO: ------------------------------------------------------------------------
I would expect at this point that your gitlab-ci.yml
file looks simlar to this and redefines the value of the serverBaseURL. Is there a reason why you are not relying on the value of the serverBaseURL returned by your SQ instance?