Gitlab Pipeline Job Token Fail

Viewed 1578

I have Gitlab Community and I am trying to integrate it with SonarQube. The Sonar is hosted on Azure VM Ubuntu in a Docker container. The problem is that I really don't know how to write gitlab-ci.yml. I already try sonar, but locally hosted on a Windows machine. Here is my current gitlab-ci.yml.

When I change sonar host with my current and I am not sure what I need to put on sonar. Login then throws an error:

SonarScanner for MSBuild 5.0.4
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
18:35:07.168 Updating build integration targets...
18:35:07.394 The token you provided doesn't have sufficient rights to check license.

sonar-check:
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  dependencies:
    - build
  script:
    - choco install sonarqube-scanner.portable
    - SonarScanner.MSBuild.exe begin /k:"somefile" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="8f6658e7684de225a4f45c7cf3466d462a95c1c7"   
    - nuget restore -ConfigFile .\nuget.config
    - MsBuild.exe ./Process /t:Rebuild
    - SonarScanner.MSBuild.exe end /d:sonar.login="8f6658e7684de225a4f45c7cf3466d462a95c1c7"
  only:
    - merge_requests
    - master
    - develop
    - GitLabQualityTool
2 Answers

For anyone coming here for a similar problem where you had things set up correctly and suddenly they stopped working, I just experienced this. I had to generate a new auth token and that got things working correctly. I don't have an explanation for why that occurred though, but this is a troubleshooting step one could take.

I found the solution. You need to go to your sonar MyAccount->Security->Generate Token. This token must be added here:

- SonarScanner.MSBuild.exe begin /k:"somefile" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="8f6658e7684de225a4f45c7cf3466d462a95c1c7" 
- SonarScanner.MSBuild.exe end /d:sonar.login="8f6658e7684de225a4f45c7cf3466d462a95c1c7"

and your sonar URL.

Related