gabrie-allaigre / sonar-gitlab-plugin

Add to each commit GitLab in a global commentary on the new anomalies added by this commit and add comment lines of modified files
GNU Lesser General Public License v3.0
713 stars 207 forks source link

Unable to use global setting for Gitlab user token #159

Closed Andrew-Stubbs closed 6 years ago

Andrew-Stubbs commented 6 years ago

This seems to be the same issue experienced by @vuza in this closed issue: https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/89#issuecomment-385245321

I have added a GitLab User Token within

General Settings -> GitLab in SonarQube, that was generated from an admin account within GitLab.

When I run my jobs from GitLab with the following command:

mvn sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID

I see the following error message:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project cars-service: Failed to execute project builder: com.talanlabs.sonar.plugins.gitlab.CommitProjectBuilder: Unable found project for highways-england/c ars-service Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project -> [Help 1]

However when I use this command (Specifying the same user token as I already added to the SonarQube settings):

mvn compile sonar:sonar -Dsonar.gitlab.user_token=$GITLAB_TOKEN -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID

The project builds and receives comments from SonarQube as expected.

Why does the global setting not seem to be being applied (I am using plugin v3.0.1)?

Thanks.

gabrie-allaigre commented 6 years ago

Hi, Are you sur for :

mvn sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID

Because error message say : Unable found project for highways-england/cars-service

$CI_PROJECT_ID=highways-england/cars-service ? It's impossible, gitlab get a number

Andrew-Stubbs commented 6 years ago

Sorry @gabrie-allaigre , you are correct, I have been playing with calling the integration locally as well as via gitlab while trying to diagnose the problem.

Two outputs directly from GitLab: Failing:

$ mvn compile sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID

20501 [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project cars-service: Failed to execute project builder: com.talanlabs.sonar.plugins.gitlab.CommitProjectBuilder: Unable found project for 184 Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project -> [Help 1]

Succeeding:

$ mvn compile sonar:sonar -Dsonar.gitlab.user_token=$GITLAB_TOKEN -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID

gabrie-allaigre commented 6 years ago

Ok thanks,

Are you sur save 2 times user_token in admin. There was a bug in sonar 7.0 with password fields

https://groups.google.com/forum/#!searchin/sonarqube/gabriel$20%7Csort:date/sonarqube/h5lvM4Iwll8/eG6RV1h1AQAJ

Andrew-Stubbs commented 6 years ago

You're a lifesaver, thanks @gabrie-allaigre

The problem does seem to be that I never actually saved the Gitlab User Token, despite it looking like I had.

Apologies for wasting your time with user error!