Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube quality gate stuck on pending when inside jenkins pipeline node

We're trying to add a Sonarqube scan as part of our Jenkins pipeline script. We have a multi-module maven project, and we're using the Maven Sonarqube plugin to run the aggregated scan. To initiate the scan we followed the instructions in Sonarqube's documentation as shown here (scroll down to the end of the page).

So the pipeline script looks something like this :

node {
    stage('SonarQube analysis') {
        withSonarQubeEnv('My SonarQube Server') {
            sh 'mvn clean package sonar:sonar'
        }
    }
}
stage("Quality Gate") {
    timeout(time: 1, unit: 'HOURS') { 
        def qg = waitForQualityGate() 
        if (qg.status != 'OK') {
            error "Pipeline aborted due to quality gate failure: ${qg.status}"
        }
    }
}

and it works as expected. But since we're using it in more than one file, we'd like to have as less duplicate code as possible, so we want to have it inside the node like this :

node {
    stage('SonarQube analysis') {
        withSonarQubeEnv('My SonarQube Server') {
            sh 'mvn clean package sonar:sonar'
        }
    }
    stage("Quality Gate") {
        timeout(time: 1, unit: 'HOURS') { 
            def qg = waitForQualityGate() 
            if (qg.status != 'OK') {
                error "Pipeline aborted due to quality gate failure: ${qg.status}"
            }
        }
    }
}

But for some reason, this gets the quality gate stuck on PENDING status until the timeout is reached. I'm trying to understand why this is happening, and what could be done to avoid moving the quality gate check outside the node.

Any help would be greatly appreciated!

like image 475
Eddie Avatar asked Feb 11 '18 15:02

Eddie


People also ask

How do you fail quality gate in SonarQube?

In order for the Quality Gate to fail on the GitLab side when it fails on the SonarQube side, the scanner needs to wait for the SonarQube Quality Gate status. To enable this, set the sonar. qualitygate. wait=true parameter in the .


1 Answers

waitForQualityGate performs an HTTP call to the SonarQube server.

Make sure your build node has HTTP access to your SonarQube instance (the Jenkins master having access to it does not imply build nodes also have it).

Regardless, as I said in a comment, using a waiting step inside a node is not a good idea in general.

like image 161
amuniz Avatar answered Oct 11 '22 09:10

amuniz