Issue
I have the following code in the Jenkinsfile which calls an "optional" method, and if it does not exists it just shall print a message
...
try {
verifyDeployment(pipelineParams)
} catch (err) {
echo "[INFO] No `verifyDeployment` defined, thus ignoring this step"
}
...
However when I run the pipeline the catch
seems not to work at I get the following error:
java.lang.NoSuchMethodError: No such DSL method 'verifyDeployment' found among steps
What do I miss?
Solution
You are using a wrong groovy syntax. See the correct groovy syntax for catching exceptions: Syntax catching exceptions
try {
//Protected code
} catch(ExceptionName e1) {
//Catch block
}
Answered By - Michael Kemmerzell
Answer Checked By - David Marino (JavaFixing Volunteer)