SonarQube and GitLab Integration: Report Successfully Sent, But Code Smells Not Displayed on Dashboard
SonarQube - Community Edition - Version 10.3 (build 82913)
GitLab Runner 16.8.0
dotnet-sonarscanner (version 6.1.0)
**C# version 9.13.0.79967 **
.NET8
I am trying to analyze my project using GitLab CI/CD. I have updated and configured my .gitlab-ci.yml
file exactly as suggested in the (SonarScanner for .NET) -
GitLab integration (sonarsource.com)
I used “sonar/integration” as the test branch.
Please find my integration details below:
sonarqube-check:
stage: sonarqube-check
tags:
- build
rules:
- if: $CI_COMMIT_REF_NAME == "sonar/integration"
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "sonar/integration"
image: mcr.microsoft.com/dotnet/sdk:8.0
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:
- "apt-get update"
- "apt-get install --yes --no-install-recommends openjdk-17-jre"
- "dotnet tool install --global dotnet-sonarscanner --version 6.1.0"
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- echo $PATH
- echo $CI_PROJECT_PATH
- "dotnet sonarscanner begin /k:\"va-gateway-payment-api\" /d:sonar.token=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" /d:sonar.verbose=true "
- "dotnet build"
- "dotnet sonarscanner end /d:sonar.token=\"$SONAR_TOKEN\" "
allow_failure: true
I have entered some code smells, in order to tests.
Everything seems to work ok. I have ran the CI/CD job and got the following result(see full attached report)
CI-CD-Full-Report.txt (577.3 KB)
Analyzing the report, it seems that code smells were correctly detected.
16:43:27.713 INFO: Found 9 MSBuild C# projects: 7 MAIN projects. 2 TEST projects.
The report is correctly uploaded:
16:43:30.127 DEBUG: Upload report
16:43:30.342 DEBUG: POST 200 https://srv-fe-sonar.vittoriaassicurazioni.it/api/ce/submit?projectKey=va-gateway-payment-api | time=212ms
16:43:30.347 INFO: Analysis report uploaded in 219ms
However, the analysis doesn’t show code smells on my dashboard.
If I do the same thing locally (checking out the sonar/integration
branch) and execute the following commands, the code smells appear correctly on my dashboard:
dotnet sonarscanner begin /k:“va-gateway-payment-api” /d:sonar.host.url=“https://srv-fe-sonar.vittoriaassicurazioni.it” /d:sonar.token=“TOKEN” /d:sonar.verbose=true
dotnet build
dotnet sonarscanner end /d:sonar.token=“TOKEN”