Hi, I am trying to run Sonar Scanner docker image in Gitlab runner as part of our pipeline
and get the error
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey
My configuration:
In the root of the project I have 2 files
I think you might be overcomplicating things when ultimately, this is all you need
a sonar-project.properties file that defines sonar.projectKey=foo
SONAR_TOKEN and SONAR_HOST_URL environment variables set
the following in your .gitlab-ci.yml
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
allow_failure: true
only:
- merge_requests
- master # or the name of your main branch
- develop
Thanks for getting back. I am running gitlab runner with shell executor. I changed the
gitlab-ci.yml file to like what you have provided. However get the message
"sonar-scanner: command not found"
My gitlab job looks like below now
sonarqube-check:
stage: scan
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar”
GIT_DEPTH: “0”
SONAR_TOKEN:
SONAR_HOST_URL:
allow_failure: true
script:
- pwd
- sonar-scanner
Hi Colin ,as mentionned by kavitharanga , this “official” configuration does not work, I also have “sonar-scanner: command not found”. Can you please check and provide a solution ?