Jenkins 脚本管道声纳集成 [英] Jenkins Script Pipeline sonar Integration

查看:16
本文介绍了Jenkins 脚本管道声纳集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Jenkins 2.x Groovy Script Build Pipeline 开始 Sonar 项目分析.

i'd like to start a Sonar project analysis with Jenkins 2.x Groovy Script Build Pipeline.

我在 Maven 中配置了声纳,所以没什么大不了的:

I have sonar configured in Maven so thats no big deal:

withEnv(["JAVA_HOME=${javaHome}", "PATH + MAVEN=${mavenHome}/bin:${env.JAVA_HOME}/bin", "MAVEN_OPTS=${mavenOpts}"]) {
        sh 'mvn -B sonar:sonar'
}

但是我怎样才能从声纳中得到结果呢?或者更好的是,我如何确定是否达到了质量关口,以便我可以停止构建管道.

But how can i get results from sonar ? Or even better how can i determine if a quality gate was achived so that i can stop the build-pipeline.

据我所知,由于某些版本的声纳,构建断路器概念已过时.或者你会如何处理.

The build breaker concept is obsolet since some versione of sonar, as far as i know. Or how would you handle this.

我仍然认为,如果项目的底层代码太糟糕,停止/暂停构建管道是个好主意.

I still think it would be a good idea to stop/pause a build pipeline if the underlying code of a project is too bad.

推荐答案

不知道这是否理想,但我通过请求从 SonarQube api 获取状态(您可以使用 HttpRequest 插件来完成).

Don't know if this is ideal, but I'm getting the status from the SonarQube api with a request (which you can do with the HttpRequest plugin).

def response = httpRequest 'https://SONAR_USER:SONAR_PASSWORD@SONAR_URL/api/qualitygates/project_status?projectKey=PROJECT_KEY'
def slurper = new groovy.json.JsonSlurper()
def result = slurper.parseText(response.content)
if (result.projectStatus.status == "ERROR") {
    currentBuild.result = 'FAILURE'
}

这篇关于Jenkins 脚本管道声纳集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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