3

I have problem with method waitForQualityGate(). I got an error "No such DSL method 'waitForQualityGate' found among steps". Another strange thing is that I must use parameter -DX for 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}"
                    }
                }
            }
        }   
    }
}

}

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • This looks more complicated than the [example in the docs](https://jenkins.io/doc/pipeline/steps/sonar/). For example do you need the `script { ... }` inside the quality gate step? Also, the `'-Dsonar.login=login' + '-Dsonar.password=password'` looks incorrect without a space between parameters. And btw you should not need to specify `sonar.login` and `sonar.password`, as these should come from `withSonarQubeEnv`. I suggest to create the smallest possible working example, and then keep enriching the config step by step to find how it breaks and at what point – janos Aug 16 '17 at 13:11
  • I need 'script {}' because I use declarative pipeline.Yes, I removed 'sonar.login, sonar.password'. – Michal Propílek Aug 17 '17 at 08:41

1 Answers1

0

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.

Cannot do this, without loading it ... def qg = waitForQualityGate() If its a method, u have to call it and it should return something...

OK999
  • 1,353
  • 2
  • 19
  • 39