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!