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

Plugin does not work - guidance on debug #93

Open fir3wall opened 6 years ago

fir3wall commented 6 years ago

Hello,

First of all great work on this plugin - and also on auth plugin. I've got issue that my plugin simply does not work, for sure it's user error just cannot find any gap in my config and also cannot see anything obvious in my log files. Would like some guidance on debugging if possible.

I'm using Gitlab 10.2.5, Sonar Gitlab Plugin 2.1.1 and Sonar 6.7 (LTS). I've successfully configured Auth plugin that works perfectly however Sonar plugin itself does not work.

This is definition from my .gitlab-ci.yml:

test-sonar:
  stage: test
  script:
    - cd bld-investor-ear
    - mvn clean install -D skipTests
    - mvn --batch-mode verify sonar:sonar -D skipTests -Dsonar.host.url=http://sonar.dionglobal.eu/
  only:
    - develop
  tags:
    - executor-docker
  dependencies:
    - prepare-cache

On my plugin settings I'm overriding following default settings:

What I would expect based on this settings is when user commits to branch develop plugin will add comment to his commit even if there is no new issues raised. However nothing like that happens.

I had a look on sonar.log and cannot see anything there, I believe plugin does not have his own log file so where should I look for errors?

Please not we are using build breaker plugin in Sonar - this is example of end of mvn output for one of our builds where there was no comment:

[INFO] Calculating CPD for 1084 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 1613ms, dir size=15 MB
[INFO] Analysis reports compressed in 2634ms, zip size=6 MB
[INFO] Analysis report uploaded in 830ms
[INFO] ANALYSIS SUCCESSFUL, you can browse https://sonar.dionglobal.eu/dashboard/index/bex4:bld-invest-ear
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at https://sonar.dionglobal.eu/api/ce/task?id=AWDmJtV*********
[INFO] Executing post-job org.sonar.plugins.buildbreaker.QualityGateBreaker
[INFO] Waiting for report processing to complete...
[INFO] Waiting for report processing to complete...
[INFO] Waiting for report processing to complete...
[INFO] Waiting for report processing to complete...
[INFO] Waiting for report processing to complete...
[INFO] Quality gate status: ERROR
[ERROR] New Issues: 6 > 0
[ERROR] [BUILD BREAKER] Project did not meet 1 conditions
...
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project bld-invest-ear: Project does not pass the quality gate. -> [Help 1]

Any help would be appreciated.

Thanks Dariusz

gabrie-allaigre commented 6 years ago

Hi, Plugin work only with preview or issue mode.

mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$CI_BUILD_REF -Dsonar.gitlab.ref_name=$CI_BUILD_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID
micheljung commented 6 years ago

@gabrie-allaigre I have the same problem. Interestingly, when I add the (deprecated) preview mode, no comment is created but when I run it in default mode, a comment is always created. However, the comment says:

SonarQube analysis indicates that quality gate is none.

SonarQube analysis reported no issues.

But when I check SonarQube, I see that 1 bug has been resolved.

tde-desc commented 6 years ago

Same problem here as @micheljung

gabrie-allaigre commented 6 years ago

@micheljung @tde-desc Hi, Have you log and command line ?

tde-desc commented 6 years ago
mvn --batch-mode verify sonar:sonar -DskipTests -Dsonar.analysis.mode=preview -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.user_token=FVv57X7GyiJH4F18dMns

[INFO] SonarQube version: 6.7.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Issues mode
[WARNING] The use of the issues mode (sonar.analysis.mode=issues) is deprecated. This mode will be dropped in the future.
[INFO] Load global settings
[INFO] Load global settings (done) | time=103ms
[INFO] Server id: AWANk4bmIacdvPUgdjHs
[WARNING] Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
[WARNING] Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
[WARNING] Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
[INFO] User cache: /root/.sonar/cache
[INFO] Exclude plugins: devcockpit, ldap, authgithub, authbitbucket, pdfreport, authaad, googleanalytics, governance
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=70ms
[INFO] Download checkstyle-sonar-plugin-4.10.jar
[INFO] Download qualinsight-sonarqube-smell-plugin-4.0.0.jar
[INFO] Download sonar-dependency-check-plugin-1.0.3.jar
[INFO] Download sonar-findbugs-plugin-3.6.0.jar
[INFO] Download sonar-scm-git-plugin-1.4.1.1128.jar
[INFO] Download sonar-gitlab-plugin-3.0.0.jar
[INFO] Download sonar-groovy-plugin-1.5.jar
[INFO] Download sonar-pitest-plugin-0.9.jar
[INFO] Download qualinsight-sonarqube-badges-3.0.1.jar
[INFO] Download sonar-softvis3d-plugin-1.0.1.jar
[INFO] Download sonar-java-plugin-5.5.0.14655.jar
[INFO] Download sonar-web-plugin-2.6.0.1053.jar
[INFO] Download sonar-xml-plugin-1.5.1.1452.jar
[INFO] Process project properties
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=116ms
[INFO] Scanning only changed files
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=909ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=23ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=208ms
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=25ms
[INFO] Project key: de.thalia.ecp.newsletterservice:parent
[INFO] -------------  Scan eCP Newsletterservice - Optivo
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice/optivo
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/optivo/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Test paths: src/test/java
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Load server rules
[INFO] Load server rules (done) | time=42ms
[INFO] Index files
[INFO] 33 files indexed
[INFO] Quality profile for java: KIM way (Sonar way with Findbugs)
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=2ms
[INFO] -------------  Scan eCP Newsletterservice - Core
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice/core
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/core/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] 14 files indexed
[INFO] Quality profile for java: KIM way (Sonar way with Findbugs)
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
[INFO] -------------  Scan eCP Newsletterservice - Application
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice/application
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/application/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] 9 files indexed
[INFO] Quality profile for java: KIM way (Sonar way with Findbugs)
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=1ms
[INFO] -------------  Scan eCP Newsletterservice - Business
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice/business
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/business/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Test paths: src/test/java
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] 33 files indexed
[INFO] Quality profile for java: KIM way (Sonar way with Findbugs)
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=1ms
[INFO] -------------  Scan Newsletterservice - SoapUI-Tests
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice/soapui
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/soapui/target/sonar
[INFO] Source paths: pom.xml
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] 1 file indexed
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=1ms
[INFO] -------------  Scan eCP Newsletterservice
[INFO] Base dir: /builds/kim/thalia_ecp_newsletterservice
[INFO] Working dir: /builds/kim/thalia_ecp_newsletterservice/target/sonar
[INFO] Source paths: pom.xml
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] 1 file indexed
[INFO] Quality profile for xml: Sonar way
[INFO] Excluded sources for coverage: 
[INFO]   <no value>
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
[INFO] Load server issues
[INFO] Load server issues (done) | time=32ms
[INFO] Performing issue tracking
[INFO] 133/133 components tracked
[INFO] ANALYSIS SUCCESSFUL
[INFO] Executing post-job GitLab Commit Issue Publisher
[INFO] Report status=success, desc=SonarQube reported no issues
[INFO] Task total time: 3.656 s
gabrie-allaigre commented 6 years ago

@tde-desc Report status=success, desc=SonarQube reported no issues

no issues, no comment

If you add comment for no issues add -Dsonar.gitlab.comment_no_issue=true

tde-desc commented 6 years ago

@gabrie-allaigre my problem is, that SonarQube Web-UI is (correctly) showing 2 minor issues which I intentionally produced. In contrast the plugin says it didn't find any issues.

gabrie-allaigre commented 6 years ago

The preview mode shows only the new issues compared to the last complete analysis. If view issue in SonarQube Web-UI then you don't see in preview mode.

tde-desc commented 6 years ago

The commit I pushed to gitlab, contains issues which did not exist in the last published analysis. Even though in SonarQube 6.7 u can also see preview analysis results in the Web-UI. In so far the Web-UI results differ from those of this plugin.

tde-desc commented 6 years ago

According to https://docs.sonarqube.org/display/PLUG/GitHub+Plugin sonar.analysis.mode seems to be deprecated.

tde-desc commented 6 years ago

Somehow its working today...

[INFO] Report status=success, desc=SonarQube reported 2 issues, with 2 minor

The only thing i changed, is the following. Previously I had the following entry in my .gitlab-ci.yml:

artifacts:
  paths:                  
    - target/*.jar

After deleting this entry, it worked...