【发布时间】:2019-12-19 16:05:36
【问题描述】:
我已将 SonarQube 与 Jenkins 集成,并且运行良好。现在我需要从管道中获取 SonarQube 项目 URL。我检查了文档,没有提及。下面是 SonarQube 分析和质量门对应的流水线阶段。
stage('SonarQube Analysis'){
dir('.tmp'){
withSonarQubeEnv('dev2-sonarqube') {
withMaven(maven:'maven 3.5.3') {
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}"
print "Quality Gate failed, but building is allowed for now"
// send to email
recipientList = committers.concat(env.tl_email)
emailext (
subject: "$env.JOB_NAME - Build #$env.BUILD_NUMBER - ${qg.status}",
body: '''${SCRIPT,template="qg-fail.template"}''',
to: "${recipientList}"
)
}
}
}
我正在尝试将 SonarQube 项目 URL 传递给质量失败电子邮件,以便开发人员可以直接从邮件跳转到相关项目。知道如何在管道中获取 SonarQube 项目 URL?
【问题讨论】: