I am interested in including quality gate for my projects. Once built at Jenkins, I have added a script that creates a project on SonarQube server and decides if quality of testing is sufficient (code origin can be found here). Script is bellow
stage('SonarCloud') {
steps {
withSonarQubeEnv('SonarQube') {
sh 'mvn clean package sonar:sonar '
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 15, unit: 'MINUTES') { // If analysis takes longer than indicated time, then build will be aborted
waitForQualityGate abortPipeline: true
script{
def qg = waitForQualityGate() // Waiting for analysis to be completed
if(qg.status != 'OK'){ // If quality gate was not met, then present error
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
The problem is that my build never finishes itself (it gets aborted after timeout. Removing timeout makes it run forever it seems. That being said, the analysis gets created and placed on SonarQube server). This is the message that I see before timeout:
SonarQube task 'AXUx0uqFm6myUuXQbknO' status is 'IN_PROGRESS'
Cancelling nested steps due to timeout
My problem is that I am not an admin of our SonarQube server, so I cannot add a webhook that would solve this problem. I wonder if there is a work around?
I tried replacing
sh 'mvn clean package sonar:sonar '
with
sh 'mvn clean package sonar:sonar -Dsonar.webhooks.project=https://my-jenkins-server.com/sonarqube-webhook/'
but didn't get anywhere.
I also tried to adapt this code, discussed in the similar question, but didn't get far either.