Hi,
I’m using Sonarcloud with a self-hosted Jenkins.
I want to implement marking a build as unstable if Sonarcloud fails the quality gate.
Currently, whenever Sonarcloud fails the a quality gate the build is marked as failure in Jenkins.
The portion of my Jenkinsfile is below:
stage('Build & Sonar Scan') {
steps {
script {
if (env.BRANCH_NAME == "development") {
withSonarQubeEnv('Sonarcloud') {
sh "mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -DskipTests -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=master"
}
} else if (env.BRANCH_NAME == "master") {
withSonarQubeEnv('Sonarcloud') {
sh "mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -DskipTests"
}
} else {
withSonarQubeEnv('Sonarcloud') {
sh "mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -DskipTests -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=development"
}
}
timeout(time: 5, unit: 'MINUTES') {
qualitygate = waitForQualityGate();
if (qualitygate.status != "OK") {
currentBuild.result = "UNSTABLE"
error "Pipeline job aborted due to Sonar Quality Gate failure"
}
}
}
}
}
I’ve also tried using:
waitForQualityGate abortPipeline: true
But that has the same issue.
The sample webhook payload looks like the following from Sonarcloud to my Jenkins:
“qualityGate”: {
“name”: “obfuscated”,
“status”: “ERROR”,
“conditions”: [
So it definitely is coming back as not “OK”.
Anyone have this problem or knows how to resolve it?
Thanks,
Terry