We are using SonarQube Enterprise 7.9. We’ve set up a SonaQube webhook to notify Jenkins the code scan result, and it works well. Our code is like below, exactly follow the official document.
stage("Sonarqube Quality Gate") {
steps {
timeout(time: 60, unit: 'SECONDS') {
waitForQualityGate abortPipeline: true
}
}
And the result is like this: when time out, the pipeline is aborted. The only thing I’m not quite happy with is that - it’s still showing GREEN!
What I want: this pipeline should show RED (fail)
I manage to turn it RED by a try-catch clause. It works but I’m curious if there is any better approach.
stage("Sonarqube Quality Gate") {
steps {
script {
try {
timeout(time: 60, unit: 'SECONDS') {
waitForQualityGate abortPipeline: true
}
}
catch (err) {
error 'Exceeded timeout'
}
}
}
}