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

**URL:** <https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746>\
**Category:** SonarQube Server / Community Build\
**Tags:** csharp, sonarqube, scanner\
**Created:** [January 28, 2021, 11:21pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746 "2021-01-28T23:21:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![samovermars](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/samovermars/32/18793_2.png) [@samovermars](https://community.sonarsource.com/u/samovermars)\
**Post date:** [January 28, 2021, 11:21pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/1 "2021-01-28T23:21:00Z")

</div>

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-5.0.4.24009-net46
- GitLab: Version: 13.8.0

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/a/3/a307c6a763f7092f3018621fcc8deaea13fdfa45.png)

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](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/) )
- Sonar-Scanner added to Environment Variables’ ‘Path’:  
 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/9/c9473a8a348141fac383d064bf2e59b7d4ea527c.png)

And still the same error so I tried running Sonar-Scanner on its own:  
 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/9/19ff4aae4bb2e1f1ddf1971671fc63a8e94203cc.png)

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).

---

<div class="post-metadata">

**Author:** ![Mark\_Rekveld](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/mark_rekveld/32/11333_2.png) [@Mark\_Rekveld](https://community.sonarsource.com/u/Mark_Rekveld)\
**Post date:** [January 29, 2021, 9:39am UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/2 "2021-01-29T09:39:00Z")

</div>

Hi @samovermars

Welcome to the community.

Can you share your build pipeline?

Cheers,  
Mark

---

<div class="post-metadata">

**Author:** ![samovermars](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/samovermars/32/18793_2.png) [@samovermars](https://community.sonarsource.com/u/samovermars)\
**Post date:** [January 29, 2021, 3:43pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/3 "2021-01-29T15:43:59Z")

</div>

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

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  
- 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

00:00

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

/-/jobs/50367#L6)Preparing environment

00:01

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

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

00:04

/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

00:00

-/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

00:01

-/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.l…t/-/jobs/50367#L36)

(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.

---

<div class="post-metadata">

**Author:** ![samovermars](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/samovermars/32/18793_2.png) [@samovermars](https://community.sonarsource.com/u/samovermars)\
**Post date:** [January 29, 2021, 3:45pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/4 "2021-01-29T15:45:20Z")

</div>

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/0/50dda25d999f55bd2a9b86b2fc4d1cc1a7ab7cbc.png)

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/c/5cb625ae167f6bddaafdc19c740261dd30750c12.png)

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

---

<div class="post-metadata">

**Author:** ![Mark\_Rekveld](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/mark_rekveld/32/11333_2.png) [@Mark\_Rekveld](https://community.sonarsource.com/u/Mark_Rekveld)\
**Post date:** [January 29, 2021, 4:16pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/5 "2021-01-29T16:16:26Z")

</div>

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.

Cheers,  
Mark

---

<div class="post-metadata">

**Author:** ![samovermars](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/samovermars/32/18793_2.png) [@samovermars](https://community.sonarsource.com/u/samovermars)\
**Post date:** [February 1, 2021, 3:24pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/7 "2021-02-01T15:24:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [February 8, 2021, 3:25pm UTC](https://community.sonarsource.com/t/gitlab-ci-sonar-scanner-the-term-sonar-scanner-is-not-recognized-as-the-name-of-a-cmdlet-function/37746/8 "2021-02-08T15:25:26Z")

</div>

Closed on February 8, 2021, 3:25pm UTC

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