| I have created the following demo script:
#!/bin/sh -ex
trap cleanup "TERM"
set +x
cleanup() {
echo "Caught signal, cleaning up..."
exit 1
}
echo "Sleeping..."
while true; do
sleep 0.1
done
# should not get here due to while true
echo "EOF"
When running in a terminal without jenkins, it catches the signal as expected (e.g. with "pkill -TERM trapscript.sh"):
$ ./trapscript.sh
+ trap cleanup TERM
+ set +x
Sleeping...
Caught signal, cleaning up...
On Jenkins 2.150.2, it does not run the cleanup function:
[TEST_trap_in_jenkins_job] $ /bin/sh -ex /tmp/jenkins5365212366501463498.sh
+ trap cleanup TERM
+ set +x
Sleeping...
Build was aborted
Aborted by Oliver Smith
Terminated
Finished: ABORTED
The server is configured to run all jobs on nodes, so this might be the same problem that Martin d'Anjou pointed out above: when it runs on a node, the signal is not received (or not sent?). It would be great if somebody could look into this, thanks! |