问题描述
Jenkins 2.50 中声明性管道中的以下 SonarQube (6.3) 分析阶段失败,控制台日志中出现此错误:
我不确定 SonarGate 中的设置是否正确.我确实使用 jenkins-mocha 来生成一个 lcov.info 文件,该文件在 Sonar 中用于生成覆盖数据.
也许质量门设置是错误的设置?如果不满足覆盖率 %,最终结果是 Jenkins 中的工作失败.
最后,我不确定Jenkins系统配置中是否需要以下配置:
和
(这是 9000 而不是 900...截屏中的文字)
这被发现是 Jenkins 的 SonarQube 扫描仪中的一个错误,当使用 Jenkins slave 进行作业时(如果作业在 master 上运行,它'd 工作).您可以在此处阅读更多信息:https://jira.sonarsource.com/browse/SONARJNKNS-282一个>
我已经使用扫描仪插件 v2.61 的测试版本对此进行了测试,发现它可以正常工作.解决方案是发布后升级到v2.61.
然后这个阶段将起作用:
stage ("SonarQube 分析") {脚步 {withSonarQubeEnv('SonarQube') {sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"}def qualitygate = waitForQualityGate()if (qualitygate.status != "OK") {错误管道因质量门覆盖失败而中止:${qualitygate.status}"}}}
The following SonarQube (6.3) analysis stage in a declarative pipeline in Jenkins 2.50 is failing with this error in the console log: http://pastebin.com/t2ja23vC. More specifically:
Update: after changing "SonarQube" to "SonarGate" in the Jenkins settings (under SonarQube servers, so it'll match the Jenkinsfile), I get a different error: http://pastebin.com/HZZ6fY6V
The stage is a modification of the example from the SonarQube docs: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline
stage ("SonarQube analysis") {
steps {
script {
STAGE_NAME = "SonarQube analysis"
if (BRANCH_NAME == "develop") {
echo "In 'develop' branch, don't analyze."
}
else { // this is a PR build, run sonar analysis
withSonarQubeEnv("SonarGate") {
sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"
}
}
}
}
}
stage ("SonarQube Gatekeeper") {
steps {
script {
STAGE_NAME = "SonarQube Gatekeeper"
if (BRANCH_NAME == "develop") {
echo "In 'develop' branch, skip."
}
else { // this is a PR build, fail on threshold spill
def qualitygate = waitForQualityGate()
if (qualitygate.status != "OK") {
error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
}
}
}
}
}
I also created a webhook, sonarqube-webhook
, with the URL http://****/sonarqube-webhook/
. Should it be like that, or http://****/sonarqube/sonarqube-webhook
? To access the server dashboard I use http://****/sonarqube
.
In SonarQube's Quality Gates section I created a new quality gate:
I am not sure if the setting in SonarGate is correct. I do use jenkins-mocha to generate an lcov.info file that is used in Sonar to generate the coverage data.
Perhaps the quality gate setting is the wrong setting to do? The end result is to fail the job in Jenkins if coverage % is not met.
Finally, I am not sure if the following configurations in the Jenkins system configuration are at all required:
And
(It's 9000 not 900... cut text in the screen shot)
This was discovered to be a bug in the SonarQube scanner for Jenkins, when using a Jenkins slave for jobs (if the job is run on the master, it'd work). You can read more here: https://jira.sonarsource.com/browse/SONARJNKNS-282
I have tested this using a test build of v2.61 of the scanner plug-in and found it working.The solution is to upgrade to v2.61 when released.
This stage will then work:
stage ("SonarQube analysis") {
steps {
withSonarQubeEnv('SonarQube') {
sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"
}
def qualitygate = waitForQualityGate()
if (qualitygate.status != "OK") {
error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
}
}
}
这篇关于在 Jenkins 声明式管道中使用 waitForQualityGate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!