QG step uses wrong task ID

Hi All,

Today I just tried to integrate sonarqube + sonar scanner + jenkins + android kotlin + gradle sonarqube.

sonarqube V CE 7.4
sonar scanner V 3.2.0.1227
jenkins V 2.156
sonarqube gradle V 2.6.2

below is my pipeline

    stage('SonarQube analysis') {
        steps {
            withSonarQubeEnv('SonarQube') {
                // requires SonarQube Scanner for Gradle 2.1+
                // It's important to add --info because of SONARJNKNS-281
                sh './gradlew --info sonarqube'
            }
        }
    }
    stage("Quality Gate"){
        post {
            failure {
                echo 'Pipeline aborted due to quality gate failure'
            }
        }
        steps {
            timeout(time: 1, unit: 'HOURS') {
                script  {
                    def qg = waitForQualityGate()
                    echo gg
                    if (qg.status != 'OK') {
                        error "Pipeline aborted due to quality gate failure: ${qg.status}"
                    }
                }
            }
        }
    }

When the “SonarQube analysis” step is finished, on my log, it will return task id = http://localhost:9000/api/ce/task?id=**AWgSZMUhePsewb-VCnub**. But on “Quality Gate” step always try to get with task id = http://localhost:9000/api/ce/task?id=**AWgOMDNbrTp5N9edQqAD**.

Please help me, Thanks

Hi,

I’m no expert in this area, but I do notice a few things. First, you’re using v2.6.2 of the Gradle scanner. The 2.7 version fixes SONARJNKNS-281, so an upgrade might be helpful.

Second you’ve got a lot more structure (nested curly brace pairs) than in the example. Since you’re having trouble, it might be helpful to pare back to what’s shown in the docs, and then build your structure back up if needed.

And finally, your post step does exactly what the qg.status != 'OK' condition does & so seems redundant.

Also, I notice that you echo gg. Did you mean echo qg?

 
Ann

Hi,

Ok, I will try update the script. I have used the script from the example, But the result still same, return different task-id.

I can’t find the sonarqube gradle plugin version 2.7.

Hi,

Finally, my integration working well. Update my pipeline to below code :grinning:

    stage('SonarQube analysis') {
        steps {
            withSonarQubeEnv("My SonarQube Server") {
                // requires SonarQube Scanner for Gradle 2.1+
                // It's important to add --info because of SONARJNKNS-281
                sh './gradlew --info sonarqube'
            }
        }
    }
    stage("Quality Gate"){
        steps {
            timeout(time: 5, unit: 'MINUTES') {
                script {
                    sh "curl GET -H 'Accept: application/json' {URL_SONARQUBE_SERVER}/api/qualitygates/project_status?projectKey={PROJECT_KEY} > status.json"
                    def statusJson = readJSON file: 'status.json'
                    def status = statusJson.projectStatus.status
                    if (status != 'OK') throw new hudson.AbortException('SonarQube Quality Gate Failed')
                }
            }
        }
    }