How to fix Pipeline-Script "Expected a step" error
You are missing a script{}
-step which is required in a declarative pipeline.
Quote:
The script step takes a block of Scripted Pipeline and executes that in the Declarative Pipeline.
stage('Check') {
steps {
script {
Boolean bool = fileExists 'NewFile.txt'
if (bool) {
println "The File exists :)"
} else {
println "The File does not exist :("
}
}
}
}
There are multiple reasons why you may get the "Expected a step"
error.
Mine occurred because I used single quotes '
to surround a step script instead of double quotes "
. For example:
stage("Build") {
steps {
sh "./build.sh ${SECRET_KEY}"
}
}
The string used above uses string interpolation (or I guess it's called a "templateable string"?), which won't work for a single-quoted string.
Thought I'd add this answer here in case someone comes from Google and the accepted answer doesn't work!