简体   繁体   中英

Sonarqube quality gate status check fail in Jenkins pipeline

Im new to jenkins pipeline scripting and sonarqube. it would be great if I can get some help with the question below. I want to fail the Jenkins declarative pipeline job when quality gate check fails. As per sonar documentation ( https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/#header-6 ), I tried with below two scenrions but both are seems not working and failing with errors. sonarqube analysis is working fine but it failing at QualityGate check. I created webhook in sonarserver which is returning json output. Not sure what Im missing here. Version I using Sonrscanner version - 3.0.0.702

scenario 1:

Getting error “Invalid parameter “abortPipeline”, did you mean “null”?” when run below code. I saprated with

stage('Sonarqube Analysis') {
            environment {
                scannerHome = tool 'ALM Sonar'
            }
            steps {
                withSonarQubeEnv('ALM Prod Sonar') {
                    sh "${scannerHome}/bin/sonar-scanner"
                }
            }
        }
        stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
                waitForQualityGate abortPipeline: true }
            }
        }

scenario 2:

Getting error “Invalid JSON String”. Below analysis, its going till the “test2” further its failing to read status waitForQualityGate(). Please advise. I put the script quality gate in saparate stage still its failing with same error.

stage('Sonarqube Analysis') {
            environment {
                scannerHome = tool 'ALM Sonar'
            }
            steps {
                withSonarQubeEnv('ALM Prod Sonar') {
                    sh "${scannerHome}/bin/sonar-scanner"
                  }
                sleep time: 30000, unit: 'MILLISECONDS'
                echo "test1"
                script {
                        echo "test2"
                        def qg = waitForQualityGate()
                        if (qg.status != 'OK') {
                            error "Pipeline aborted due to quality gate failure: ${qg.status}"
                            echo "test3" }
                    }
                }
        }

You can try below code as a work around.

stage('Sonarqube Analysis') {
            environment {
                scannerHome = tool 'Sonar scanner'
            }
            steps {
                withSonarQubeEnv('Sonarserver') {
                    sh "${scannerHome}/bin/sonar-scanner"
                  }
                if ("${json.projectStatus.status}" == "ERROR") {
                            currentBuild.result = 'FAILURE'
                            error('Pipeline aborted due to quality gate failure.')
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM