如何对詹金斯管道内的SonarQube质量门做出反应 [英] How to react on SonarQube Quality Gate within Jenkins Pipeline
本文介绍了如何对詹金斯管道内的SonarQube质量门做出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Jenkins管道中,我需要在SonarQube质量门上做出反应. 有没有一种更简单的方法可以做到这一点,而是在Sonar-Scanner日志中查找结果页面(例如 https://mysonarserver/sonar/api/ce/task?id = xxxx )并从那里解析JSON结果?
Within my Jenkins Pipeline I need to react on the SonarQube Quality Gate. Is there an easier way to achieve this but looking in the Sonar-Scanner log for the result page (e.g. https://mysonarserver/sonar/api/ce/task?id=xxxx) and parse the JSON Result from there?
我使用Jenkins 2.30和SonarQube 5.3
I use Jenkins 2.30 and SonarQube 5.3
预先感谢
推荐答案
使用适用于Jenkins 2.8.1的SonarQube扫描仪该解决方案可立即使用:
Using SonarQube Scanner for Jenkins 2.8.1 the solution is available out of the Box:
stage('SonarQube analysis') {
withSonarQubeEnv('My SonarQube Server') {
sh 'mvn clean package sonar:sonar'
} // SonarQube taskId is automatically attached to the pipeline context
}
}
stage("Quality Gate"){
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
这篇关于如何对詹金斯管道内的SonarQube质量门做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文