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

Master branch CI build status is failed even though branch build passed with preview analysis #143

Closed amimas closed 6 years ago

amimas commented 6 years ago

Hello,

I have the plugin setup and working. My gitlab-ci.yml file looks like this:

stages:
        - build
        - validation

sonarqube_preview:
        stage: validation
        script:
                - sh gradlew sonarqube -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
        except:
                - master

sonarqube:
        stage: validation
        script:
                - sh gradlew sonarqube
        only:
                - master

This works fine. I wanted to clean up the script a little bit. So, I moved the sonar.gitlab.xxx properties from gitlab-ci.yml file to my gradle script, whose snippet is below:

new gitlab-ci.yml script:

stages:
        - build
        - validation

sonarqube_preview:
        stage: validation
        script:
                - sh gradlew sonarqube -Dsonar.analysis.mode=preview
        except:
                - master

sonarqube:
        stage: validation
        script:
                - sh gradlew sonarqube
        only:
                - master

build.gradle script:

sonarqube {
   properties {
        property 'sonar.gitlab.project_id', System.getenv("CI_PROJECT_ID")
        property 'sonar.gitlab.commit_sha', System.getenv("CI_COMMIT_SHA")
        property 'sonar.gitlab.ref_name', System.getenv("CI_COMMIT_REF_NAME")
   }
}

However now, with the pipeline of the master branch is keep failing. It's reporting something like this in the failure:

SonarQube analysis indicates that quality gate is failed.

Security Rating on New Code is failed: Actual value 4 > 1
Reliability Rating on New Code is passed: Actual value 1
Maintainability Rating on New Code is passed: Actual value 1
SonarQube analysis reported 47 issues

ā›” 1 blocker
šŸš« 20 critical
āš  4 major
šŸ”½ 22 minor

With my new change, why is the master branch suddenly being reported as a failure? I understand the overall project quality did not pass, but my pipeline in Gitlab CI shouldn't be failing for the master branch.

amimas commented 6 years ago

Resolved it by modifying my build.gradle script like this so that those properties do not get applied if we're not running preview analysis. Otherwise, my original post will apply those properties to master branch also, which doesn't run "preview analysis"

sonarqube {
     properties {
        if(System.getenv('sonar.analysis.mode') == "preview") {
           property 'sonar.gitlab.max_blocker_issues_gate', 1
                   property 'sonar.gitlab.max_critical_issues_gate', 1
                   property 'sonar.gitlab.project_id', System.getenv("CI_PROJECT_PATH")
                       property 'sonar.gitlab.commit_sha', System.getenv("CI_COMMIT_SHA")
                       property 'sonar.gitlab.ref_name', System.getenv("CI_COMMIT_REF_NAME")
        }
     }
}