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
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.
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.
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.
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With