'sonar-scanner is not recognized in gitlab ci

I'm trying to integrate SonarQube to our project in GitLab. I already have a project properties file.

# .gitlab-ci.yml file
stages:
  - analyze

sonarqube-check:
  stage: analyze
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: ['']
  variables:
    SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar'
    GIT_DEPTH: 0
  cache:
    key: '${CI_JOB_NAME}'
    paths:
      - .sonar/cache
  script:
    - sonar-scanner
  only:
    - master

But somehow I am getting this error.

$ sonar-scanner
sonar-scanner : The term 'sonar-scanner' is not recognized as the name of a cmdlet, function, script file, or operable 
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\windows\TEMP\build_script495425181\script.ps1:205 char:1
+ sonar-scanner
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (sonar-scanner:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1

I have also added a SONAR_HOME_URL and SONAR_TOKEN in the variables.

I am fairly new to this CI/CD process.

Is there anything I need to install first so it can recognize sonar-scanner command?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source