在Shell脚本中在Hudson上捕获Abort信号? [英] Catch Abort signal on hudson in shell script?
问题描述
我们如何在hudson上捕获作业的中止信号,以便在中止的情况下可以执行一些后续步骤(我正在hudson上运行作业,而后台运行了shell脚本)?
How can we trap the abort signal of the job on hudson so that i can do some post steps in case of abort (I am running a job on hudson which has shell script running in background)?
推荐答案
我在Jenkins而非Hudson上经历过(Jenkins是Hudson的分支),Jenkins通过Sun的JRE java.lang.UnixProcess.destroyProcess在Unix上发送了SIGTERM在Windows上,这是通过TerminateProcess API完成的.
I have experienced with Jenkins, not hudson, (Jenkins is a fork of hudson) Jenkins sends a SIGTERM on Unix through Sun's JRE java.lang.UnixProcess.destroyProcess, on Windows, this is done through TerminateProcess API.
因此,您可以通过这种方式在shell脚本中使用陷阱"
So you can use "trap" in your shell script by this way
#!/bin/bash
getAbort()
{
echo "Abort detected"
# other commands here if any...
}
trap 'getAbort; exit' SIGTERM
这篇关于在Shell脚本中在Hudson上捕获Abort信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!