I have used sonarQube in jenkins pipeline. I have installed all plugin related to sonarqube in jenkins. In the jenkins configure system, I configured the sonarqube server properly and jenkins global tool configuration I configured SonarQube Scanner properly.
This is jenkins pipeline code ..
node{
stage('git checkout process'){
echo 'started checkout'
git 'https://github.com/ramkumar/sampleproject'
echo 'completed sucessfully'
}
stage('compile package'){
def mvnTool = tool name: 'Maven', type: 'maven'
sh "${mvnTool}/bin/mvn clean install"
}
stage('SonarQube analysis') {
withSonarQubeEnv('sonarqube') {
mvnHome = '/opt/apache-maven/bin'
sh "${mvnHome}/mvn sonar:sonar"
}
}
stage("Quality Gate"){
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
emailext body: 'Your code was failed due to sonarqube quality gate', subject: 'Jenkins Failed Report', to: '[email protected]'
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
I also configured the webhooks in sonarqube. But when I build the job the 3 stage waitForQualityGate() is not returning ok status back to jenkins rather it shows Checking status of SonarQube task 'AWrQj5In7abK9JVZ9' on server 'sonarqube' SonarQube task 'AWrQj5In7abK9JVZ9' status is 'IN_PROGRESS'
and it is continously loading it is not getting completed. When I check in sonarqube server it shows Response: Server Unreachable. I am not running sonarqube on local it is running on docker. What may be problem?
Configure SonarQube webhook for quality gate
Administration > Configuration > Webhooks > Create
The URL should point to your Jenkins server http://{JENKINS_HOST}/sonarqube-webhook/
This is solved for me. as i was unaware of this hook. Once i configured this, everything went well.
Try to put sleep(60) command before the check:
sleep(60)
timeout(time: 1, unit: 'MINUTES') {
def qg = waitForQualityGate()
print "Finished waiting"
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
It solved same problem for me.
As suggested in the official docs here and here, I was able to get the waitForQualityGate() working correctly by configuring a webhook to the Jenkins instance on SonarQube Server.
Add a webhook of the form your <your-jenkins-instance>/sonarqube-webhook/
in your SonarQube server configuration, pointing to your Jenkins instance. Note the trailing slash is important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With