Jenkins – java.lang.NoSuchMethodError: No such DSL method ‘$’ found among steps

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

Best Answer

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")
}
Related Topic