Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: No such DSL method '$' found among steps

Tags:

jenkins

I have the following dsl

pipeline {
    agent {
        label 'test'
    }
    parameters {        
        booleanParam(defaultValue: false, description: 'This is a Release build', name: 'isRelease')
    }

    stages {
        stage('Build') {
            steps {
                 script {
                     if (${params.isRelease}) {
                          echo("This is a release")
                     }
                 }
            }
        }
    }
}

This fails with the following error

java.lang.NoSuchMethodError: No such DSL method '$' found among steps 

What I am doing wrong? I am using

  • Jenkins 2.89.4
  • Job DSL 1.68
  • Pipeline Job 2.20
  • Pipeline: API 2.27
  • Pipeline: Basic Steps 2.7
  • Pipeline: Build Steps 2.7
  • Pipeline: Declarative 1.2.9
like image 849
papanito Avatar asked May 11 '18 07:05

papanito


People also ask

What is DSL method in Jenkins?

Job DSL was one of the first popular plugins for Jenkins which allows managing configuration as code and many other plugins dealing with this aspect have been created since then, most notably the Jenkins Pipeline and Configuration as Code plugins.

What is the difference between declarative and scripted pipeline?

Basically, declarative and scripted pipelines differ in terms of the programmatic approach. One uses a declarative programming model and the second uses an imperative programming mode. Declarative pipelines break down stages into multiple steps, while in scripted pipelines there is no need for this.

What directive do you use for a declarative pipeline?

agent. The agent directive specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent directive is placed. The directive must be defined at the top-level inside the pipeline block, but stage-level usage is optional.


1 Answers

Ok the answer can already be found in Stackoverflow: Boolean parameter are in reality strings, so this works

if ("${params.isRelease}" == "true") {
    echo("This is a release")
}

Alternatively use the params-object

if (params.isRelease) {
    echo("This is a release")
}
like image 85
papanito Avatar answered Nov 15 '22 07:11

papanito