[英]SonarQube does not return status of waitForQualityGate() to jenkins?
I have used sonarQube in jenkins pipeline.我在 jenkins 管道中使用了 sonarQube。 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.
我已经在jenkins中安装了所有与sonarqube相关的插件。在jenkins配置系统中,我正确配置了sonarqube服务器和jenkins全局工具配置我正确配置了SonarQube Scanner。
This is jenkins pipeline code..这是 jenkins 管道代码..
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: 'prakashpp666666@gmail.com'
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'我还在 sonarqube 中配置了 webhooks。但是当我构建作业时,3 阶段的 waitForQualityGate() 没有将ok状态返回到 jenkins,而是显示Checking status of SonarQube task 'AWrQj5In7abK9JVZ9' on server 'sonarqube' ‘88195818 taskJ5AIn17928正在处理'
and it is continously loading it is not getting completed.并且它不断加载它没有完成。 When I check in sonarqube server it shows Response: Server Unreachable .
当我签入 sonarqube 服务器时,它显示Response: Server Unreachable 。 I am not running sonarqube on local it is running on docker .
我没有在本地运行 sonarqube 它在docker上运行。 What may be problem?
可能是什么问题?
Configure SonarQube webhook for quality gate为质量门配置 SonarQube webhook
Administration > Configuration > Webhooks > Create
管理 > 配置 > Webhook > 创建
The URL should point to your Jenkins server http://{JENKINS_HOST}/sonarqube-webhook/
该 URL 应指向您的 Jenkins 服务器
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)命令:
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.正如官方文档here和here中所建议的那样,我能够通过为SonarQube Server上的Jenkins实例配置一个webhook来让waitForQualityGate()正常工作。
Add a webhook of the form your <your-jenkins-instance>/sonarqube-webhook/
in your SonarQube server configuration, pointing to your Jenkins instance.在您的 SonarQube 服务器配置中添加您的
<your-jenkins-instance>/sonarqube-webhook/
,指向您的 Jenkins 实例。 Note the trailing slash is important.请注意尾部斜杠很重要。
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/
在我的例子中,这是因为 SonarQube 服务器 URL 中有一个额外的斜线 (/)。我的 Jenkins -> 配置系统 -> SonarQube 服务器 -> 服务器 URL 配置为
http://sonarip:9000/
Once I removed the trailing slash and changed it to http://sonarip:9000
, the waitForQualityGate
started to work as expected.一旦我删除尾部斜杠并将其更改为
http://sonarip:9000
, waitForQualityGate
开始按预期工作。
I solved this by creating a webhook in SonarQube.我通过在 SonarQube 中创建一个 webhook 解决了这个问题。
ps: If you erroneously get FAIL from SQ, verify that the url of your SonarQube server (in Jenkins settings) does not end in '/' ps:如果您从 SQ 错误地得到 FAIL,请验证您的 SonarQube 服务器的 url(在 Jenkins 设置中)不以 '/' 结尾
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 :受到一篇关于该主题的好文章的启发,我能够将我的特定问题(与此处描述的症状相同)缩小到SonarQube webhook 安全性:
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...因此,即使您的问题不完全是这个问题,我强烈建议您同时查看 Jenkins 和 SonarQube 设置,因为根本原因可能很简单......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.