如何在 Jenkins Pipeline 中对 SonarQube 质量门做出反应 [英] How to react on SonarQube Quality Gate within Jenkins Pipeline

查看:24
本文介绍了如何在 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

提前致谢

推荐答案

使用 SonarQube Scanner for Jenkins 2.8.1 解决方案是开箱即用的:

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}"
    }
  }
}

这篇关于如何在 Jenkins Pipeline 中对 SonarQube 质量门做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆