简体   繁体   中英

How does one cancel a system groovy script

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, eg

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

Or you can let Groovy do that for you by including the ThreadInterrupt annotation in your script, eg

@groovy.transform.ThreadInterrupt

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM