简体   繁体   English

步骤之间未找到此类DSL方法“ waitForQualityGate”

[英]No such DSL method 'waitForQualityGate' found among steps

I have problem with method waitForQualityGate() . 我对方法waitForQualityGate()有问题。 I got an error "No such DSL method 'waitForQualityGate' found among steps". 我收到一个错误“在步骤之间找不到这样的DSL方法'waitForQualityGate'”。 Another strange thing is that I must use parameter -DX for sonarscanner. 另一个奇怪的是,我必须使用参数-DX为sonarscanner。 I don't know what is wrong. 我不知道怎么了 Thanks for help. 感谢帮助。

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

} }

This will not be an immediate answer, but the reason for the error is, you are calling a custom method without even loading it initially. 这不是一个立即的答案,但是出现错误的原因是,您在调用自定义方法时甚至没有在最初加载它。 Load the groovy file that have the method, which jenkins is complaining that dsl doesn't exist... only when you load the groovy file/the class, then you can instantiate it. 加载具有该方法的groovy文件,詹金斯抱怨说dsl不存在...仅当加载groovy文件/类时,才可以实例化它。

Cannot do this, without loading it ... def qg = waitForQualityGate() If its a method, u have to call it and it should return something... 如果不加载它,则无法执行此操作... def qg = waitForQualityGate()如果它是一种方法,则必须调用它,并且它应该返回一些内容...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM