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

How to break GitLab CI pipeline in preview mode? #240

Closed SruthiMohan2910 closed 5 years ago

SruthiMohan2910 commented 5 years ago

I need the GitLab 'code_quality' job to fail if it finds atleast 1 major issue in preview mode. But everytime the Job succeeds. I have already set the gitlab.max_major_issues_gate=0 inside sonar-scanner.properties, still it doesn't work. @gabrie-allaigre Please help!!!

GlSexecution

This is my .gitlab-ci.yml

stages:
- code_quality
variables:
  SONAR_LOGIN: "xyz"
  SONAR_PASSWORD: "xyz"
  SOURCE: "."

sonarqube_master_job:
  stage: code_quality
  tags:
    - docker
  only:
    - development

  script:
    - cd ..
    - sonar-scanner/bin/sonar-scanner -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD -Dsonar.sources=$SOURCE -Dsonar.analysis.mode=preview -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.failure_notification_mode=exit-code 
gabrie-allaigre commented 5 years ago

Hi, Plugin break only if critical or blocked issue, if you break others issue, set attributes

-Dsonar.gitlab.max_major_issues_gate=0
-Dsonar.gitlab.max_minor_issues_gate=0
-Dsonar.gitlab.max_info_issues_gate=0
SruthiMohan2910 commented 5 years ago

Thank you so much for the response. But this will only work on "publish" mode. I wanted the pipeline to break on "preview" mode. So I made a shortcut to fix my problem by making few changes in my pipeline (I am not sure if its an optimal solution):

stages:
- code_quality
variables:
  SONAR_LOGIN: "xyz"
  SONAR_PASSWORD: "xyz"
  SOURCE: "."
  PREVIEW_RES: ""

sonarqube_master_job:
  stage: code_quality
  tags:
    - docker
  only:
    - development
    - merge_requests

  script:
    - cd ..
    - PREVIEW_RES="$(sonar-scanner/bin/sonar-scanner -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD -Dsonar.sources=$SOURCE -Dsonar.analysis.mode=preview -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.failure_notification_mode=exit-code -Dsonar.projectVersion=$VERSION)"
#    - echo $PREVIEW_RES
    - (if [[ $PREVIEW_RES == *"No new issue"* ]]; then exit 0; else exit 1; fi);