[jenkins pipeline] waitForQualityGate 404 with incorrect analysis ID

The version:

SonarQube: 10.3
Jenkins: 2.399
[plugin]Sonar Quality Gates Plugin:1.3.1
[plugin]SonarQube Scanner: 2.15

The config:

stage('sonar') {
            agent any
            steps {
                script {
                    withSonarQubeEnv('sonar') {
                        sh '''cd cm-commons-model_$BUILD_NUMBER && /var/jenkins_home/sonar-scanner/bin/sonar-scanner \
                              -Dsonar.login=admin \
                              -Dsonar.password=admin123 \
                              -Dsonar.projectName=cm-commons-model \
                              -Dsonar.projectKey=cm-commons-model \
                              -Dsonar.projectVersion=$app_version \
                              -Dsonar.branch.name=$build_branch \
                              -Dsonar.sourceEncoding=UTF-8 \
                              -Dsonar.language=java \
                              -Dsonar.forceAnalysis=true \
                              -Dsonar.sources=src/main/java \
                              -Dsonar.java.binaries=target/classes \
                              -Dsonar.java.libraries=/var/jenkins_home/lib/*.jar
                            '''
                    }
                    timeout(1) {
                        def qg = waitForQualityGate('sonar')
                        if (qg.status != 'OK') {
                            error "sonar failed"
                        }
                    }
                }
            }
        }

The error logs:

INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://10.64.4.74:9000/dashboard?id=cm-commons-model&branch=master
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://10.64.4.74:9000/api/ce/task?id=AY3oXqAr3yTQwqRetYu-
INFO: Analysis total time: 12.834 s
...
Checking status of SonarQube task 'AY3laNW53yTQwqRetYtc' on server 'sonar'
SonarQube task 'AY3laNW53yTQwqRetYtc' status is 'SUCCESS'
...
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 75b1c1ca-04e1-42c8-97e6-96c97a19e76e
org.sonarqube.ws.client.HttpException: Error 404 on http://10.64.4.74:9000/api/qualitygates/project_status?analysisId=AY3laNlDdqBTVeFTKdok : {"errors":[{"msg":"Analysis with id \u0027AY3laNlDdqBTVeFTKdok\u0027 is not found"}]}
...

http://10.64.4.74:9000/api/ce/task?id=AY3oXqAr3yTQwqRetYu- can access normally,but waitForQualityGate failed with 404

Welcome :slight_smile:

you don’t need an additional plugin beside the Sonarqube Jenkins plugin which provides
the waitForQualityGate() pipeline step that works combined with Sonarqube webhooks.

see

Supported versions of Sonarqube are the 9.9.4 LTS or the latest 10.4.1
Uninstall the Sonar Quality Gates Plugin, update Sonarqube, configure webhooks and come back if any problems / questions.

Gilbert

Okay, I’ve already given up on using waitForQualityGate to get the results, and request the api interface instead

You might use the property sonar.qualitygate.wait doing the polling for you, see

thank you very,and i have another question:the coverage is always 0 …

here is the config,and the jacoco.xml has been generated

        stage('compile') {
            agent any
            steps {
                script {
                    sh '''cd ${ref_module}_$BUILD_NUMBER \
                       && export PATH=/home/cowave/dev/java/jdk17.0.6/bin:/home/cowave/dev/maven/apache-maven-3.8.5/bin:$PATH \
                       && export JAVA_HOME=/home/cowave/dev/java/jdk17.0.6 \
                       && mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true 
                       '''
                }
            }
        }

        stage('analyze') {
            agent any
            steps {
                script {
                    catchError(buildResult: 'FAILURE', stageResult: 'FAILURE'){
                    withSonarQubeEnv('sonar') {
                        sh '''cd ${ref_module}_$BUILD_NUMBER \
                              && /home/cowave/dev/sonar-scanner/bin/sonar-scanner \
                              -Dsonar.login=admin \
                              -Dsonar.password=admin123 \
                              -Dsonar.projectName=$app_name \
                              -Dsonar.projectKey=$app_name \
                              -Dsonar.projectVersion=$app_version \
                              -Dsonar.branch.name=$ref_branch \
                              -Dsonar.sourceEncoding=UTF-8 \
                              -Dsonar.language=java \
                              -Dsonar.forceAnalysis=true \
                              -Dsonar.sources=mql-parser/src,mql-commons/src,mql-client/src,mql-wrapper/src,mql-script/mql-groovy/src,mql-script/mql-js/src,mql-script/mql-py/src,plugins/mql-redis/src,plugins/mql-cm/src \
                              -Dsonar.java.binaries=mql-parser/target/classes,mql-commons/target/classes,mql-client/target/classes,mql-wrapper/target/classes,mql-script/mql-groovy/target/classes,mql-script/mql-js/target/classes,mql-script/mql-py/target/classes,plugins/mql-redis/target/classes,plugins/mql-cm/target/classes \
                              -Dsonar.java.libraries=/home/cowave/dev/sonar-scanner/libs/*.jar \
                              -Dsonar.qualitygate.wait=true \
                              -Dsonar.coverage.jacoco.xmlReportPaths=$(find "$(pwd)" -type f -name '*jacoco.xml' -print0 | xargs -0 printf "%s," | sed 's/,$//')
                            '''
                    }
                    }

    .......
                }
            }
        }

If you don’t change the standard setttings in pom and the report files are created correctly, it should work out of the box.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.