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
712 stars 207 forks source link

Plugin posts results to SonarQube, but not to GitLab #261

Closed thanarino closed 4 years ago

thanarino commented 4 years ago

Hello, I am trying to integrate SonarQube to GitLab through this plugin, but it does not create commit/merge request comments. The scan finishes and updates the project results in the SonarQube deployment, but GitLab only reports that the Job has finished. I am using GitLab Community Edition, the latest one found at GitLab.com. Is this plugin still compatible with that version? Also, I am using version 4.1.0 of the plugin and version 7.6 of SonarQube.

Here is my .gitlab-ci.yml:

image: maven:latest

stages:
- analysis

sonarqube_master_job:
  stage: analysis
  only:
    - merge_requests
    - branches
  script:
    - mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.analysis.mode=publish -Dsonar.projectKey=maven_java_web_example -Dsonar.gitlab.api_version=v4 -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.ci_merge_request_iid=$CI_MERGE_REQUEST_IID -Dsonar.gitlab.merge_request_discussion=true

My SonarQube GitLab plugin config is the following:

sonar.gitlab.comment_no_issue=true
sonar.gitlab.global_template=(the sample template in readme)
sonar.gitlab.inline_template=(the sample template in readme)
sonar.gitlab.all_issues=true
sonar.gitlab.load_rules=true

I have also tried using the gitlab-sonar-scanner, and here is my .gitlab-ci.yml config when I used it:

stages:
- analysis

sonarqube_job:
  stage: analysis
  image: ciricihq/gitlab-sonar-scanner
  variables:
    SONAR_ANALYSIS_MODE: preview
    SONAR_PROJECT_VERSION: $CI_JOB_ID
    SONAR_TOKEN: $SONAR_LOGIN
    SONAR_SOURCES: .
    SONAR_PROJECT_KEY: <PROJECT_KEY>
    SONAR_GITLAB_PROJECT_ID: <PROJECT_ID>
    CI_BUILD_REF: $CI_COMMIT_SHA
    CI_BUILD_REF_NAME: $CI_COMMIT_REF_NAME
  script:
  - gitlab-sonar-scanner

sonarqube-reports:
  stage: analysis
  image: ciricihq/gitlab-sonar-scanner
  variables:
    SONAR_ANALYSIS_MODE: publish
    SONAR_PROJECT_VERSION: $CI_JOB_ID
    SONAR_TOKEN: $SONAR_LOGIN
    SONAR_SOURCES: .
    SONAR_PROJECT_KEY: <PROJECT_KEY>
    SONAR_GITLAB_PROJECT_ID: <PROJECT_ID>
    CI_BUILD_REF: $CI_COMMIT_SHA
    CI_BUILD_REF_NAME: $CI_COMMIT_REF_NAME
  script:
  - gitlab-sonar-scanner

Is there something wrong with my configuration? Also, is it better to use gitlab-sonar-scanner or should I just skip using it? Thank you very much.

thanarino commented 4 years ago

Update: I turned on the Debug logs, and it turns out I also need to provide SONAR_URL in the command: gitlab-sonar-scanner -X -Dsonar.gitlab.url=https://gitlab.com but, the job now takes too long to execute Executing post-job 'GitLab Commit Issue Publisher'. There are also no logs after that, and the job just times out at 1 hour. Are there ways to see where the post-job is stuck? Any other suggestions are appreciated. Thank you very much.

thanarino commented 4 years ago

Update 2: Added sonar.gitlab.user_token=$GITLAB_LOGIN to the command, and it worked. Thanks.