Skip to content

Commit bf5912b

Browse files
[Green dragon] add a SIGINT handler to error when jenkins kills the process (#874)
Jenkins will kill the processes on stage timeouts via SIGINT, however we ignore errors in the subprocesses to defer to the junit plugin, so instead detect SIGINTS and exit with a nonzero exit https://docs.python.org/3/library/signal.html#note-on-signal-handlers-and-exceptions
1 parent 37ca0c0 commit bf5912b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

zorg/jenkins/build.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@
1212
import math
1313
import re
1414
from pathlib import Path
15+
import signal
1516

1617
import requests
1718
from contextlib import contextmanager
1819

20+
_received_sigint = False
21+
22+
23+
def _sigint_handler(signum, frame):
24+
global _received_sigint
25+
_received_sigint = True
26+
27+
28+
signal.signal(signal.SIGINT, _sigint_handler)
29+
1930
BUCKET = os.environ.get("S3_BUCKET")
2031

2132
NINJA = "/usr/local/bin/ninja"
@@ -932,6 +943,8 @@ def run_cmd(working_dir, cmd, env=None, sudo=False, err_okay=False):
932943
subprocess.check_call(cmd)
933944
os.chdir(old_cwd)
934945
except subprocess.CalledProcessError as excpt:
946+
if _received_sigint:
947+
raise excpt
935948
if not err_okay and not ignore_errors_override:
936949
raise excpt
937950
else:

0 commit comments

Comments
 (0)