How to cancel groovy script system

In Jenkins, I have a groovy script build step. Is there a way to cancel a long running script or have some code in a groovy script system that can determine if its build has been canceled?

+5
source share
1 answer

Jenkins will interrupt the thread that runs the script when you cancel the assembly.

This way you can manually check the thread interrupt status and interrupt your script at specific points, for example.

if (Thread.currentThread().interrupted()) { throw new InterruptedException() } 

Or you can let Groovy do this for you by including a ThreadInterrupt annotation in the script, for example

 @groovy.transform.ThreadInterrupt 

Also, make sure that none of your catch blocks will catch an InterruptedException.

+2
source

Source: https://habr.com/ru/post/1232317/


All Articles