【发布时间】:2018-01-24 05:21:00
【问题描述】:
我对方法waitForQualityGate() 有疑问。我收到一个错误“在步骤中找不到这样的 DSL 方法 'waitForQualityGate'”。另一个奇怪的事情是我必须使用参数-DX 用于声纳扫描器。我不知道出了什么问题。感谢您的帮助。
pipeline {
agent { label 'builders' }
tools {
maven 'maven 3.3.9'
}
stages {
stage ('Checkout'){
steps {
git branch: 'develop', credentialsId: 'credential', url: 'ssh://repository'
}
}
stage ('Build'){
steps {
withMaven (
maven: 'maven 3.3.9',
mavenSettingsConfig: 'cc86690e-095d-4714-92b2-b61861241c7a'){
sh 'mvn -U clean package -DskipTests'
}
}
}
stage ('SonarQube Scan'){
steps {
withSonarQubeEnv('SonarQube') {
withMaven (
maven: 'maven 3.3.9',
mavenSettingsConfig: 'cc86690e-095d-4714-92b2-b61861241c7a'){
sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar ' +
'-DX' +
'-Dsonar.login=login' +
'-Dsonar.password=password' +
'-Dsonar.issuesReport.json.enable=true' +
'-Dsonar.report.export.path=sonar-report.json'
}
} // SonarQube taskId is automatically attached to the pipeline context
}
}
stage ('Quality Gate') {
steps {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
script {
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
}
}
【问题讨论】:
-
这看起来比example in the docs 更复杂。例如,您是否需要质量门步骤中的
script { ... }?此外,'-Dsonar.login=login' + '-Dsonar.password=password'看起来不正确,参数之间没有空格。顺便说一句,您不需要指定sonar.login和sonar.password,因为它们应该来自withSonarQubeEnv。我建议创建尽可能小的工作示例,然后逐步丰富配置以找出它是如何中断的以及在什么时候中断 -
我需要 'script {}' 因为我使用声明性管道。是的,我删除了 'sonar.login, sonar.password'。
标签: jenkins sonarqube jenkins-pipeline quality-gate