Is there a possible way / plugin that can run a post build script when a Jenkins job is aborted. I do see that the post build plugin provides an action to execute a set of scripts, but these can be run only on 2 options either a successful job or a failed job.
You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.
This question is positively answered here.
The Post Build Task plugin is run even if a job is aborted.
Use it to search the log text for "Build was aborted" and you can specify a shell script to run.
Works like a charm. :-)
For a declarative Jenkins pipeline, you can achieve it as follows:
pipeline { agent any options { timeout(time: 2, unit: 'MINUTES') // abort on exceeding the timeout } stages { stage('Echo 1') { steps { echo 'Hello World' } } stage('Sleep'){ steps { sh 'sleep 180' } } stage('Wake up'){ steps { echo "Woken up" } } } // this post part is executed if job is aborted post { aborted { script{ echo "Damn it. I was aborted!" } } } }
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