Ida*_*dar 8 jenkins jenkins-plugins sonarqube jenkins-pipeline sonarqube-scan
Jenkins 2.50中声明性管道中的以下SonarQube(6.3)分析阶段在控制台日志中出现此错误失败:http://pastebin.com/t2ja23vC.进一步来说:
此作业(SonarGate)中定义的SonarQube安装与任何已配置的安装都不匹配.可配置的安装数量:1.
更新:在Jenkins设置中将"SonarQube"更改为"SonarGate"后(在SonarQube服务器下,所以它将与Jenkins文件匹配),我得到一个不同的错误: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}"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还sonarqube-webhook用URL 创建了一个webhook http://****/sonarqube-webhook/.应该是这样,还是http://****/sonarqube/sonarqube-webhook?要访问我使用的服务器仪表板http://****/sonarqube.
在SonarQube的Quality Gates部分,我创建了一个新的质量门:
我不确定SonarGate中的设置是否正确.我使用jenkins-mocha生成一个lcov.info文件,该文件在Sonar中用于生成coverage数据.
也许质量门设置是错误的设置吗?如果不满足coverage%,最终结果是在Jenkins中失败.
最后,我不确定Jenkins系统配置中是否需要以下配置:
和
SonarQube Jenkins插件扫描两个特定行的构建输出,用于获取SonarQube报告任务属性和项目URL.如果您的调用sonar-scanner未输出这些行,则waitForQualityGate()调用将没有任务ID来查找它们.因此,您必须找出正确的设置,以使其更详细.
请参阅插件的SonarUtils类中的extractSonarProjectURLFromLogs和extractReportTask方法,以了解它们的工作原理:
ANALYSIS SUCCESSFUL, you can browse <project URL> 用于添加徽章的链接(在构建历史记录中)Working dir: <dir with report-task.txt>用于将任务ID传递给waitForQualityGate步骤这被发现是 Jenkins 的 SonarQube 扫描仪中的一个错误,当使用 Jenkins slave 进行作业时(如果作业在 master 上运行,它会工作)。您可以在此处阅读更多信息:https : //jira.sonarsource.com/browse/SONARJNKNS-282
我已经使用扫描仪插件 v2.61 的测试版本对此进行了测试,并发现它可以正常工作。解决方法是在发布时升级到v2.61。
这个阶段将起作用:
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}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17122 次 |
| 最近记录: |