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

Quality Gate Report in GitLab comment #120

Open Grey2k opened 6 years ago

Grey2k commented 6 years ago

Hi, in manual there is nice report from quality gate , but can I can get it ?

Gate Report

I use script from manual

"Test project sonar":
  stage: analysis
  only:
    - test-sonar
  image: ciricihq/gitlab-sonar-scanner
  script:
    - gitlab-sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.projectKey=test -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_REF -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME

GitLab Plugin posts comment but without quality gate info (default template)

gabrie-allaigre commented 6 years ago

Hi, What is version use ?

Grey2k commented 6 years ago

Sonarqube 7.0 , GItlab 10.4 , Where is difference in comments depends on version of Sonarqube?

gabrie-allaigre commented 6 years ago

And sonar-gitlab-plugin version ?

gabrie-allaigre commented 6 years ago

also logs of the sonar-scanner execution

whedro commented 6 years ago

I have same problem... SQ 7, Gitlab 10.5, sonar-scanner in docker... Log:

Running with gitlab-runner 10.5.0 (80b03db9)
  on Docker runner 2cead0e2
Using Docker executor with image ciricihq/gitlab-sonar-scanner ...
Pulling docker image ciricihq/gitlab-sonar-scanner ...
Using docker image sha256:770b0d9119fdb66c2522ee91b12dafa6348966fe653e3727dc3ef74066e78f1a for ciricihq/gitlab-sonar-scanner ...
Running on runner-2cead0e2-project-99-concurrent-0 via 43345d1c22d2...
Fetching changes...
Removing .scannerwork/
HEAD is now at 039d9b6 Merge branch 'development' into '#55'
From http://service.mlox.eu/eventimer/webportal
 * [new branch]      #57        -> origin/#57
Checking out 53e28307 as #57...
Skipping Git submodules setup
$ unset CI_BUILD_REF && /usr/bin/sonar-scanner-run.sh
grep: sonar-project.properties: No such file or directory
INFO: Scanner configuration file: /sonar-scanner-3.0.3.778/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_151 Oracle Corporation (64-bit)
INFO: Linux 3.16.6-042stab126.666 amd64
INFO: User cache: /root/.sonar/cache
INFO: Issues mode
WARN: 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=353ms
INFO: Server id: AWB1oZsO8K6PvcucIZI1
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=94ms
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=5665ms
INFO: SonarQube server 7.0.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=262ms
INFO: Scanning only changed files
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=69ms
INFO: Load active rules
INFO: Load active rules (done) | time=1131ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=87ms
INFO: Project key: Eventimer
INFO: -------------  Scan Eventimer
INFO: Load server rules
INFO: Load server rules (done) | time=132ms
INFO: Base dir: /builds/eventimer/webportal
INFO: Working dir: /builds/eventimer/webportal/.scannerwork
INFO: Source paths: src
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: 62 files indexed
INFO: Quality profile for php: Sonar way
WARN: ----------------------------------------------------------------
WARN: Sonargraph Integration: Skipping project Eventimer [Eventimer], since no Sonargraph rules are activated in current SonarQube quality profile [SonarQube].
WARN: ----------------------------------------------------------------
WARN: ----------------------------------------------------------------
WARN: Sonargraph Integration: Skipping project Eventimer [Eventimer], since no Sonargraph rules are activated in current SonarQube quality profile [SonarQube].
WARN: ----------------------------------------------------------------
INFO: Sensor Sonar-Sonargraph-Plugin [3.5] [Sonargraph]
INFO: ----------------------------------------------------------------
INFO: Sonargraph: Skipping project Eventimer [Eventimer], since no Sonargraph rules are activated in current SonarQube quality profile.
INFO: ----------------------------------------------------------------
INFO: Sensor Sonar-Sonargraph-Plugin [3.5] [Sonargraph] (done) | time=3ms
INFO: Sensor Embedded CSS Analyzer Sensor [css]
INFO: 0 source files to be analyzed
INFO: Sensor Embedded CSS Analyzer Sensor [css] (done) | time=101ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=2ms
INFO: Sensor PHP sensor [php]
INFO: 0/0 source files have been analyzed
INFO: 10 source files to be analyzed
INFO: 10/10 source files have been analyzed
INFO: No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
INFO: No PHPUnit coverage reports provided (see 'sonar.php.coverage.reportPaths' property)
INFO: Sensor PHP sensor [php] (done) | time=1828ms
INFO: Sensor Analyzer for "php.ini" files [php]
INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=5ms
INFO: Load server issues
INFO: Load server issues (done) | time=96ms
INFO: Performing issue tracking
INFO: 80/80 components tracked
INFO: ANALYSIS SUCCESSFUL
INFO: Task total time: 9.946 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 22.388s
INFO: Final Memory: 50M/371M
INFO: ------------------------------------------------------------------------
Job succeeded
whedro commented 6 years ago

In version SQ 6.7 it works..

h4wkmoon commented 6 years ago

I guess my pb is related :

sonar-scanner -Dsonar.projectKey=$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG -Dsonar.sources=. -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME

Sonarqube reports in WebUI 10 issues Plugin says 0.

log :

INFO: Scanner configuration file: /sonar-scanner-3.0.3.778-linux/conf/sonar-scanner.properties INFO: Project root configuration file: NONE INFO: SonarQube Scanner 3.0.3.778 INFO: Java 1.8.0_121 Oracle Corporation (64-bit) INFO: Linux 4.4.0-119-generic amd64 INFO: User cache: /root/.sonar/cache INFO: Publish mode INFO: Load global settings INFO: Load global settings (done) | time=161ms INFO: Server id: xxxxxxxxxxxxx INFO: User cache: /root/.sonar/cache INFO: Load plugins index INFO: Load plugins index (done) | time=46ms INFO: Download sonar-flex-plugin-2.3.jar INFO: Download sonar-l10n-fr-plugin-1.14.2.jar INFO: Plugin [l10nfr] defines 'l10nen' as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2. INFO: Download sonar-scm-git-plugin-1.4.0.1037.jar INFO: Download sonar-gitlab-plugin-3.0.0.jar INFO: Download sonar-auth-gitlab-plugin-1.3.1.jar INFO: Download sonar-ldap-plugin-2.2.0.608.jar INFO: Download qualinsight-sonarqube-badges-3.0.1.jar INFO: Download sonar-scm-svn-plugin-1.5.0.715.jar INFO: Download sonar-csharp-plugin-6.6.0.3969.jar INFO: Download sonar-javascript-plugin-4.1.0.6085.jar INFO: Download sonar-java-plugin-5.3.0.13828.jar INFO: Download sonar-php-plugin-2.11.0.2485.jar INFO: Download sonar-python-plugin-1.9.1.2080.jar INFO: Download sonar-xml-plugin-1.4.3.1027.jar INFO: Download sonar-web-plugin-2.5.0.476.jar INFO: SonarQube server 6.7.1 INFO: Default locale: "en_US", source code encoding: "UTF-8" INFO: Process project properties INFO: Load project repositories INFO: Load project repositories (done) | time=108ms INFO: Execute project builders INFO: Execute project builders (done) | time=452ms INFO: Load quality profiles INFO: Load quality profiles (done) | time=64ms INFO: Load active rules INFO: Load active rules (done) | time=1222ms INFO: Load metrics repository INFO: Load metrics repository (done) | time=41ms INFO: Project key: xxxxxxxxxxxxxxx INFO: ------------- Scan xxxxxxxxxxxxxxxxxxxxxxxxx INFO: Load server rules INFO: Load server rules (done) | time=56ms INFO: Base dir: xxxxxxxxxxxxxxxxxxx INFO: Working dir: xxxxxxxxxxxxxxxxxxxxx INFO: Source paths: . INFO: Source encoding: UTF-8, default locale: enUS INFO: Index files INFO: Excluded sources: INFO: venv/ INFO: coverage/ INFO: test*.py INFO: 10 files indexed INFO: 8531 files ignored because of inclusion/exclusion patterns INFO: Quality profile for py: Sonar way INFO: Sensor Python Squid Sensor [python] INFO: Python test coverage INFO: Parsing report 'xxxxxxxxxxxxxxxxxxxxx'' INFO: Sensor Python Squid Sensor [python] (done) | time=969ms INFO: Sensor PythonXUnitSensor [python] INFO: Sensor PythonXUnitSensor [python] (done) | time=51ms INFO: Sensor SonarJavaXmlFileSensor [java] INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms INFO: Sensor Analyzer for "php.ini" files [php] INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=3ms INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=16ms INFO: Sensor CPD Block Indexer INFO: Sensor CPD Block Indexer (done) | time=0ms INFO: Calculating CPD for 6 files INFO: CPD calculation finished INFO: Analysis report generated in 109ms, dir size=179 KB INFO: Analysis reports compressed in 18ms, zip size=50 KB INFO: Analysis report uploaded in 68ms INFO: ANALYSIS SUCCESSFUL, you can browse xxxxxxxxxxxx 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 xxxxxxxxxxxxxxxxx INFO: Executing post-job GitLab Commit Issue Publisher INFO: Waiting quality gate to complete... INFO: Waiting quality gate to complete... INFO: Waiting quality gate to complete... INFO: Quality gate status: ERROR ERROR: Security Rating on New Code: 2 > 1 INFO: Reliability Rating on New Code : 1 ERROR: Maintainability Rating on New Code: 3 > 1 INFO: Coverage on New Code : 0.0 INFO: Duplicated Lines on New Code (%) : 0.0 INFO: Report status=failed, desc=SonarQube reported QualityGate is error, with 2 error and 3 ok, no issues INFO: Task total time: 8.915 s INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 13.432s INFO: Final Memory: 52M/353M INFO: ------------------------------------------------------------------------

gabrie-allaigre commented 6 years ago

Hi, Use Branch plugin in SonarQube ?

h4wkmoon commented 6 years ago

Hi, I don't.

disfluxly commented 6 years ago

Hello,

I'm also having a similar issue that seems to be related.

SonarQube Version: 7.1 GitLab Plugin Version: 3.0.1

I've tested both Publish & Preview mode against a brand-new SonarQube Project. Here's what I get for each:

Preview Mode:

Publish Mode:

I've traced this down a bit, and it seems to be an issue with the Template function that grabs the newIssueCount. <#assign newIssueCount = issueCount() notReportedIssueCount = issueCount(false)>

The "issueCount()" function seems to always return a 0 in Publish Mode, thus the list of issues never gets populated, resulting in this IF statement getting executed:

<#if newIssueCount == 0> SonarQube analysis reported no issues.

I've tried removing the Quality Gate section from the Default Template, in the event that this was causing the issues. However, I get the same result.

I'm not sure why the template function works in Preview mode, but fails in Publish mode.

mibcadet commented 6 years ago

Same here with developer edition. It never gets count of open issues from quality gate, it takes fixed 0 value.

michaelvdnet commented 6 years ago

This is most likely a sonar-scanner issue, as the symptoms reported here align with those reported in this issue (does work in preview, not in publish).

EDIT: According to this comment it's by design. However the quoted text is no longer in the linked documentation.