Are you using a self-hosted runner? If so, you need to ensure you have sonar-scanner CLI installed on that machine that contains the self-hosted runner. See SonarScanner | SonarQube Docs for more info.
@ahben Can you add a script to check the location of the sonar-scanner command and $PATH? Something like this:
whereis sonar-scanner
echo $PATH
EDIT: I just realized that you will probably get nothing with the whereis command because your screenshot already shows sonar-scanner cannot be found. Perhaps try find ~ -type f -name "sonar-scanner" instead.
so on further inspection this is a strangeness in gitlab-runner. Script: does not run in the docker container. In fact the image: piece is not used (from what i can tell) on runners that are not docker-in-docker runners.
So it seems the best solution would be for sonarqube to at least call that out as a requirement when walking through the gitlab setup instructions
Thanks for your reply. Can you clarify what you mean by…
Does this mean you were able to resolve your issue? At least when I set my example project up, I didn’t need to make any other adjustments to the pipeline yaml.
Here’s the script I used that worked for me, but it looks not much different from yours:
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
allow_failure: true
only:
- merge_requests
- master
- develop
- /^feature.*/
No, we are on a private gitlab instance which has different configurations. We will have to do some work on our end to get this to work, but I understand why people will have issues with this.