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" }
                    }
                }
        }

Hello @Ram_Krishna,

Note that I’ve also read your first post about it (Qualitygate failure with no boday to invoke jenkins pipeline error). There is something wrong in your Jenkins, the first example you showed is supposed to work (ofc with the full pipeline script).

What happens if you precisely copy/paste and execute this pipeline? (don’t do any modification, I made it compliant with your environment namings):

pipeline {
    agent any
    environment {
        scannerHome = tool 'ALM Sonar';
    }
    stages {
        stage('SCM') {
            steps {
                git branch: 'master',
                    credentialsId: 'github',
                    url: 'git@github.com:antoine-vigneau-sonarsource/test-js.git'
            }
        }
        stage('Sonarqube Analysis') {
            steps {
                withSonarQubeEnv('ALM Prod Sonar') {
                    sh "${scannerHome}/bin/sonar-scanner"
                }
            }
        }
        stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'MINUTES') {
                    waitForQualityGate abortPipeline: true
                }
            }
        }
    }
}

If this doesn’t work either, the issue is not in the pipeline, you have a problem in your Jenkins or something! I don’t know what to advise you, maybe reinstall it?

This happens to me too. I have pretty much similar pipeline in works here and I get JSON error.

Apparently it adds extra ‘/’ to the url and that’s what’s causing it. I don’t know how to fix that.

Caused: hudson.remoting.ProxyException: java.lang.IllegalStateException: Unable to parse response from https://url.to.our.sonarqube//api/ce/task?id=AYOsZqkw_c-SEI3q7HdS:

Ah this ended up being configuration error. If you add trailing slash to the Sonarqube installation URL it’ll add the extra slash after it and fails like that.