Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripted Jenkins pipeline: continue on fail

Is there a way to continue execution of the scripted pipeline even if the previous stage failed? I need to run specific commands (cleanup) when the build fails before the whole job fails.

like image 847
user2988257 Avatar asked Nov 03 '16 12:11

user2988257


1 Answers

The usual approach is to wrap your steps within a try block.

try {
  sh "..."
} catch (err) {
  echo "something failed"
}
// cleanup
sh "rm -rf *"

To ease the pain and make the pipeline code more readable, I've encapsulated this in another method here in my global library code.

Another approach, esp. created because of this very issue, are the declarative pipelines (blog, presentation).

like image 73
StephenKing Avatar answered Oct 04 '22 11:10

StephenKing