Catch Abort signal on hudson in shell script?

2019-04-29 13:52发布

问题:

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)?

回答1:

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.

JENKINS - Aborting a build

HUDSON - Aborting a build

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


标签: hudson