GitLab-CI: sonar-scanner : The term 'sonar-scanner' is not recognized as the name of a cmdlet, function,

Trying to integrate SonarQube into GitLab-CI and perform analysis on merge requests/branch.

  • SonarQube Version: Developer Edition Version 8.6 (build 39681)
  • SonarScanner: sonarscanner-for-msbuild - sonar-scanner-msbuild-
  • GitLab: Version: 13.8.0

Note: GitLab-Runner, Sonar-Scanner and SonarQube are all installed on the same Windows server.

My first thought was, it can’t find the runner, installation/permission problem. So…

I have verified:

  • SonarQube Service run as Admin and has full access to Sonar-Scanner directory
  • GitLab Runner Service as Admin and has full access to Sonar-Scanner directory
  • Sonar-Scanner Installation double checked (Standalone executable: sonarscanner-for-msbuild) (installed per SonarScanner for .NET | SonarQube Docs )
  • Sonar-Scanner added to Environment Variables’ ‘Path’:

And still the same error so I tried running Sonar-Scanner on its own:

and that seems to run ok. But GitLab still produces the same issue. Maybe I’m using the wrong Sonar-Scanner?

I’m fairly new to SonarQube/GitLab-CI’s Runner so any guidance/suggestions you can offer is greatly appreciated. Not sure where else to look (I’ve read everything/anything remotely related).

Hi @samovermars

Welcome to the community.

Can you share your build pipeline?


1 Like

Thank you. I think by build pipeline , you mean my yml?

name: sonarsource/sonar-scanner-cli:latest
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 cache: key: "{CI_JOB_NAME}”
- .sonar/cache
- sonar-scanner
allow_failure: true
- merge_requests
- master
- develop"

Log lines of Job:

" Running with gitlab-runner 13.8.0 (775dd39d)

-/jobs/50367#L2) on docker qD8JT9NU

/jobs/50367#L3)Preparing the “shell” executor


-/jobs/50367#L4)Using Shell executor…

/-/jobs/50367#L6)Preparing environment


-/jobs/50367#L7)Running on DOCKER…

/jobs/50367#L9)Getting source from Git repository


/jobs/50367#L10)Fetching changes…

-/jobs/50367#L11)Reinitialized existing Git repository in C:/GitLab-Runner/builds/lawdepot/lawdepot/SA-sonarqube-yml-changes/0/.git/

-/jobs/50367#L12)Checking out ab65b50d as refs/merge-requests/5916/head…

-/jobs/50367#L13)git-lfs/2.7.2 (GitHub; windows amd64; go 1.12.2; git 08a08ae0)

-/jobs/50367#L14)Skipping Git submodules setup

-/jobs/50367#L15)Restoring cache


-/jobs/50367#L16)Version: 13.8.0

-/jobs/50367#L17)Git revision: 775dd39d

-/jobs/50367#L18)Git branch: 13-8-stable

/jobs/50367#L19)GO version: go1.13.8

-/jobs/50367#L20)Built: 2021-01-20T13:32:55+0000

-/jobs/50367#L21)OS/Arch: windows/amd64

-/jobs/50367#L22)Checking cache for sonarqube-check…

-/jobs/50367#L23)Runtime platform arch=amd64 os=windows pid=4420 revision=775dd39d version=13.8.0

-/jobs/50367#L24)No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.

-/jobs/50367#L25)Successfully extracted cache

-/jobs/50367#L26)Executing “step_script” stage of the job script


-/jobs/50367#L27)$ sonar-scanner

-/jobs/50367#L28)sonar-scanner : The term ‘sonar-scanner’ is not recognized as the name of a cmdlet, function,

-/jobs/50367#L29)script file, or operable program. Check the spelling of the name, or if a path was included,

-/jobs/50367#L30)verify that the path is correct and try again.

-/jobs/50367#L31)At C:\Users\GitLabRunner-dev\AppData\Local\Temp\build_script610507701\script.ps1:303 char:1

-/jobs/50367#L32)+ sonar-scanner

-/jobs/50367#L33)+ ~~~~~~~~~~~~~

/jobs/50367#L34) + CategoryInfo : ObjectNotFound: (sonar-scanner:String) , CommandNotFoundException

/jobs/50367#L35) + FullyQualifiedErrorId : CommandNotFoundException


(gitlab1…/-/jobs/50367#L37)ERROR: Job failed: exit status 1"

I really appreciate you taking a look, please let me know if I misunderstood or missed something.


Please let me know if I missed something, thank you again!

Hi @samovermars

Yeah I did indeed mean the yml.
From the looks of it it does look correct.

Let me find someone internally who has more Gitlab experience than me.


1 Like

My issue was related to environment path. I have multiple accounts.

  • GitLab Runner Service as Admin and has full access to Sonar-Scanner directory

The account that GitLab runner was using was not not the account that had the environment variables. Once SonarScanner directory was added to the user environment variables (Path) of the GitLab runner windows account, it worked as expected, although the scanner ran, analysis is not showing up in sonar scanner.

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