简体   繁体   English

如何取消系统groovy脚本

[英]How does one cancel a system groovy script

In Jenkins I have a system groovy script build step. 在Jenkins中,我有一个系统groovy脚本构建步骤。 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? 有没有办法取消长时间运行的脚本,或者在系统groovy脚本中有一些代码可以判断它的构建是否已被取消?

Jenkins will interrupt the thread which is running the script when you cancel the build. 取消构建时,Jenkins将中断正在运行脚本的线程。

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通过在脚本中包含ThreadInterrupt注释来为你做这件事,例如

@groovy.transform.ThreadInterrupt

Also make sure that none of your catch blocks will swallow an InterruptedException. 还要确保没有任何catch块会吞下InterruptedException。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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