詹金斯脚本管道声纳集成 [英] Jenkins Script Pipeline sonar Integration
问题描述
我想用Jenkins 2.x Groovy Script Build Pipeline开始一个Sonar项目分析。
我在Maven中配置了声纳,所以没什么大不了的:
withEnv([JAVA_HOME = $ {javaHome},PATH + MAVEN = $ {mavenHome} / bin:$ {env.JAVA_HOME} / bin,MAVEN_OPTS = $ {mavenOpts}]){
sh'mvn -B sonar:sonar'
}
但是我怎样才能得到结果声纳?或者甚至更好,我如何确定质量门是否已达到,以便我可以停止生成管道。
如果项目的底层代码太糟糕,我仍然认为停止/暂停构建管道是个好主意。
不知道这是否理想,但我从SonarQube api获得了状态您可以使用HttpRequest插件)。
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 = =错误){
currentBuild.result ='FAILURE'
}
i'd like to start a Sonar project analysis with Jenkins 2.x Groovy Script Build Pipeline.
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.
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'
}
这篇关于詹金斯脚本管道声纳集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!