In Jenkins I have a system groovy script build step. Is there any way to cancel a long running script, or to have some code within the system groovy script which can tell whether its build has been cancelled?
Jenkins will interrupt the thread which is running the script when you cancel the build.
So you can either manually check the thread's interrupt status and abort your script at certain points, e.g.
if (Thread.currentThread().interrupted()) {
throw new InterruptedException()
}
Or you can let Groovy do that for you by including the ThreadInterrupt annotation in your script, e.g.
@groovy.transform.ThreadInterrupt
Also make sure that none of your catch blocks will swallow an InterruptedException.
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