Bash: line 120: sonar-scanner: command not found

Hi I am trying to implement sonarqube using gitlab. I followed tutorial and videos to setup. But I end up with following error while pipeline is running at gitlab.

Checking cache for sonarqube-check…
Runtime platform arch=amd64 os=linux pid=1599937 revision=32fc1585 version=15.2.1
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing “step_script” stage of the job script
$ sonar-scanner
bash: line 120: sonar-scanner: command not found
Cleaning up project directory and file based variables
ERROR: Job failed: exit status 1

P.S while I tried to run sonar-scanner command through project directory then it is executing successfully. I don’t know what is it I am missing? My file is as below:-

sonar.token = {token}

Hey there.

What version of SonarQube are you using? Can you share your exact GitLab CI YML file?

Hey Colin,
I am using sonarqube-
Also file content is below:-

    - sonarqube-check
    - sonarqube-vulnerability-report

  stage: sonarqube-check
    name: sonarsource/sonar-scanner-cli:5.0
    entrypoint: [""]
    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
    key: "${CI_JOB_NAME}"
      - .sonar/cache
    - sonar-scanner
  allow_failure: true
    - merge_requests
    - master
    - main
    - develop

  stage: sonarqube-vulnerability-report
    - 'curl -u "${SONAR_TOKEN}:" "${SONAR_HOST_URL}/api/issues/gitlab_sast_export?projectKey=ykumar_sonarqube_proj_AYs4JUiReU29FP23saJ&branch=${CI_COMMIT_BRANCH}&pullRequest=${CI_MERGE_REQUEST_IID}" -o gl-sast-sonar-report.json'
  allow_failure: true
    - merge_requests
    - master
    - main
    - develop
    expire_in: 1 day
      sast: gl-sast-sonar-report.json
    - sonarqube-check


Are you using a self-hosted Gitlab runner?

Hey Colin,
I don’t know how to use that? I just followed the steps mentioned in docs.
Can you please help how to make it run?

This is an appropriate question to ask the Gitlab admins in your organization.

Is this you are asking? I have setup in runner in gitlab

Hello @Yogesh_Dubey

Thanks for the information that you provided.

We tried to reproduce the issue by running the scanner on with the default runners.
We got a slightly different output from GitLab. We have some extra lines on our output with the docker image used.

I suggest that you try to run on a GitLab default runner and see if the issue still persists.
Also, can you send us a screenshot of the logs in GitLab or the complete file to help us understand better if the image is downloaded or not?

Hi @dimitris.kavvathas ,
Thanks for responding. I did use GitLab default runner and issue still persists. Please check screenshot.

SonarQube is hosted at my local system. [ http://localhost:9000]
Please help me here

Hello @Yogesh_Dubey,

We managed to reproduce your issue by configuring a runner that only supports a shell executor and allowing it to run untagged jobs.

All the suggested gitlab-ci.yml configurations that we provide for SonarQube can only run on runners that implement a docker executor. You can see more information about executors in the GitLab documentation.

In your case, as you can see in your logs, your runner doesn’t implement a docker executor and falls back to a shell executor which fails. The solution is to configure a runner with a docker executor to properly use the image that is provided in the CI file.

I created a ticket for improving our GitLab documentation that you can track here.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.