Jenkins Script Pipeline sonar Integration

你说的曾经没有我的故事 提交于 2019-12-07 10:26:16

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/39977138/jenkins-script-pipeline-sonar-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!