Hi everyone,
We are trying to add SonarQube to our CI pipeline and we found some problems.
We know this format is not ideal, but for test purposes we are deploying Sonar as a local service in docker (image [sonarqube:9.9.5-community]) running in localhost:9000 and then executing our CI task using a local GitLab runner (executor: shell(powershell)) on Windows and connecting to our Sonar local service.
Gitlab Conf:
Version: 16.11.1
Git branch: 16-11-stable
GO version: go1.21.9
Built: 2024-05-03T15:52:47+0000
OS/Arch: windows/amd64
In this way, we manage to connect to our Sonar server (configuring the Sonar token and URL) and execute the sonar analysis, but we have a problem regarding the Project key: even if we indicate it as a flag in our sonar:sonar
command, it’s replaced during the command’s execution by the Maven project name.
This is our CI task:
sonarqube-check:
image: maven:3.6.3-jdk-11
tags:
- test1
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:
- mvn clean verify sonar:sonar -Dsonar.projectKey=MyRESTAPI123
allow_failure: true
only:
- my-test-branch
In this way, when the script is executed, we have as log:
[INFO] 15:57:45.354 Project key: Maven-Project-Name123
instead of Project key: MyRESTAPI123
In this way, when it tries to upload the report to the Sonar server we got:
[INFO] 15:57:57.898 Analysis report generated in 351ms, dir size=180.6 kB
[INFO] 15:58:00.395 Analysis report compressed in 2496ms, zip size=60.2 kB
[INFO] 15:58:00.395 Analysis report generated in C:\GitLab-Runner\...\scanner-report
[DEBUG] 15:58:00.395 Upload report
[DEBUG] 15:58:00.415 POST 403 http://localhost:9000/api/ce/submit?projectKey= Maven-Project-Name123 | time=19ms
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
Cleaning up project directory and file based variables
ERROR: Job failed: exit status 1
Does anyone knows how we can solve this problem ? Is it related with the Sonar version we use ? Is related with GitLab executor ? Any guidance will be really appreciated.
Thank you all,
Ignacio