【发布时间】:2017-08-12 01:49:07
【问题描述】:
Jenkins 2.50 中声明性管道中的以下 SonarQube (6.3) 分析阶段失败,控制台日志中出现此错误:http://pastebin.com/t2ja23vC。更具体地说:
在此作业 (SonarGate) 中定义的 SonarQube 安装与任何已配置的安装不匹配。可配置的安装数量:1。
更新:在 Jenkins 设置中将“SonarQube”更改为“SonarGate”(在 SonarQube 服务器下,因此它将与 Jenkinsfile 匹配)后,我得到一个不同的错误:http://pastebin.com/HZZ6fY6V
java.lang.IllegalStateException:无法获取 SonarQube 任务 ID 和/或服务器名称。请使用“withSonarQubeEnv”包装器来运行您的分析。
该阶段是对 SonarQube 文档中示例的修改: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}"
}
}
}
}
}
我还创建了一个 Webhook sonarqube-webhook,其 URL 为 http://****/sonarqube-webhook/。应该是这样,还是http://****/sonarqube/sonarqube-webhook?要访问服务器仪表板,我使用http://****/sonarqube。
在 SonarQube 的质量门部分,我创建了一个新的质量门:
我不确定 SonarGate 中的设置是否正确。我确实使用 jenkins-mocha 来生成一个 lcov.info 文件,该文件在 Sonar 中用于生成覆盖数据。
也许质量门设置是错误的设置?如果不满足覆盖率 %,最终结果是 Jenkins 中的工作失败。
最后,我不确定Jenkins系统配置中是否需要以下配置:
和
【问题讨论】:
-
Do not post images of code or errors! 图片和屏幕截图可以很好地添加到帖子中,但请确保帖子在没有它们的情况下仍然清晰有用。如果您发布代码或错误消息的图像,请确保您还复制并粘贴或直接在帖子中输入实际代码/消息。
-
帖子中没有代码截图。帖子超级清晰。
标签: jenkins sonarqube jenkins-plugins jenkins-pipeline sonarqube-scan