【问题标题】:No such DSL method 'waitForQualityGate' found among steps在步骤中找不到这样的 DSL 方法“waitForQualityGate”
【发布时间】: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.loginsonar.password,因为它们应该来自withSonarQubeEnv。我建议创建尽可能小的工作示例,然后逐步丰富配置以找出它是如何中断的以及在什么时候中断
  • 我需要 'script {}' 因为我使用声明性管道。是的,我删除了 'sonar.login, sonar.password'。

标签: jenkins sonarqube jenkins-pipeline quality-gate


【解决方案1】:

这不会是一个直接的答案,但错误的原因是,您正在调用自定义方法,甚至最初都没有加载它。加载具有该方法的 groovy 文件,詹金斯抱怨 dsl 不存在......只有当您加载 groovy 文件/类时,您才能实例化它。

不能这样做,不加载它...def qg = waitForQualityGate() 如果它是一个方法,你必须调用它并且它应该返回一些东西......

【讨论】:

  • 也许,一件重要的事情,我正在使用从代理。
猜你喜欢
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
  • 2018-05-13
  • 1970-01-01
  • 2018-09-17
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多