Specifications (all in Jenkins is up to date with latest)
Jenkins version: 2.190.3
Sonar Quality Gates Plugin: 1.3.1
SonarQube Scanner for Jenkins: 2.10
What I’m trying to achieve is get a build in a determinate state (OK/FAIL) depending in SonarQube execution.
To test this,
SonarQube Quality Gates reduced to get a “Passed”
WebHook created in SonarQube as mentioned in SonarQube page (is showing last delivery when I execute Jenkins job, so is working properly)
Created Jenkinsfile stage for Sonar and Quality Gate
Added sleep because my feeling is timeout is not working.
Problem:
When I execute the build with Sonar and Quality Gate, always fails, seems is not waiting for SonarQube WebHook response, or is not getting it properly.
JenkinsFile.groovy:
node {
deleteDir();
checkout scm;
try {
stage('Build') {
dir("myDir") {
sh './gradlew build :MyProject'
}
}
stage('SonarQube Scan') {
withSonarQubeEnv('AWS SonarQube') {
dir("myDir") {
sh './gradlew sonarqube'
}
}
sleep(40)
}
stage("Quality Gate"){
timeout(time: 5) { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
} catch (err) {
currentBuild.result = 'FAILED'
notifyFailed()
}
}
Jenkins Output
…
BUILD SUCCESSFUL in 25s
8 actionable tasks: 1 executed, 7 up-to-date
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] sleep
Sleeping for 40 sec
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gate)
[Pipeline] timeout
Timeout set to expire in 5 min 0 sec
[Pipeline] {
[Pipeline] waitForQualityGate
Checking status of SonarQube task ‘sonarconfiguredtaskid’ on server ‘AWS SonarQube’
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] emailext
Warning: asd@asd.com is not a recognized user, but sending mail anyway
Sending email to: asd@asd.com
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE
assuming you’re using a recent version of Sonarqube as 7.9.1 LTS or 8.0
This plugin is not needed, seems it has been built for an earlier version of Sonarqube - similar
to the Build Breaker plugin.
Uninstall this plugin. Then with proper webhook configuration and communication between
Jenkins ↔ Sonarqube it should work.
The waitForQualityGate() method is provided by SonarScanner for Jenkins
Are there any proxies or firewalls involved !?
Checking status of SonarQube task ‘AW6xD4nMhUUnInpM’ on server ‘AWS SonarQube’
SonarQube task ‘AW6xD4nMhUUnInpM’ status is ‘SUCCESS’
SonarQube task ‘AW6xD4nMhUUnInpM’ completed. Quality gate is ‘OK’
If communication between Sonarqube > Jenkins works - think of proxies, firewall and nonProxyHost
settings - no sleep between Sonarqube analysis and waitForQualityGate() should be needed.