Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Jenkin's "Abort build" gracefully?

Tags:

python

jenkins

I am trying to salvage test data from an aborted Jenkins build. The documentation (https://wiki.jenkins-ci.org/display/JENKINS/Aborting+a+build) appears to throw an interrupt and so I attempted to catch it with a custom handler:

signal.signal(signal.SIGINT, signal_handler)

Running my program through CMD and sending crtl-c stimulates the signal_handler function. However, when running this through Jenkins, the interrupt signal is not captured. Are there any plugins that alter Jenkins abort signal, or is there a way to handle it gracefully?

like image 330
Anthony Bane Avatar asked Oct 27 '25 08:10

Anthony Bane


1 Answers

Well, I know this a bit late, but jenkins sends a TERM signal when aborting. Basically you just gotta register that signal

signal.signal(signal.SIGTERM, signal_handler)

Info obtained from: https://gist.github.com/datagrok/dfe9604cb907523f4a2f

where it says:

Jenkins

When a Jenkins job is cancelled, it sends TERM to the process group of the process it spawns, and immediately disconnects, reporting "Finished: ABORTED," regardless of the state of the job.

This causes the spawned process and all its subprocesses (unless they are spawned in new process groups) to receive TERM.

This is the same effect as running the job in your terminal and pressing CTRL+C, except in the latter situation INT is sent, not TERM.

Since Jenkins disconnects immediately from the child process and reports no further output:

  • it can misleadingly appear that signal handlers are not being invoked. (Which has mislead many to think that Jenkins has KILLed the process.)

  • it can misleadingly appear that spawned processes have completed or exited, while they continue to run.

like image 149
notihs Avatar answered Oct 29 '25 22:10

notihs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!