Reputation: 621
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?
Upvotes: 5
Views: 15774
Reputation: 1
For me, this issue was solved with 3 solutions.
Upvotes: 0
Reputation: 710
I ran into a similar issue. In my case it was because of an extra slash (/) in SonarQube server URL. My Jenkins -> Configure System -> SonarQube servers -> Server URL was configured as http://sonarip:9000/
Once I removed the trailing slash and changed it to http://sonarip:9000
, the waitForQualityGate
started to work as expected.
Upvotes: 1
Reputation: 616
Inspired by a nice article on the subject, I was able to narrow down my particular problem — which had the same symptom described here — to SonarQube webhook security:
So, even if you're problem isn't exactly this one, I'd strongly suggest reviewing both Jenkins and SonarQube settings together as the root cause could be something as simple...
Upvotes: 1
Reputation: 7377
I solved this by creating a webhook in SonarQube.
p.s: If you erroneously get FAIL from SQ, verify that the url of your SonarQube server (in Jenkins settings) does not end in '/'
Upvotes: 2
Reputation: 1077
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.
Upvotes: 11
Reputation: 76
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.
Upvotes: 4
Reputation: 696
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.
Upvotes: 3