2
votes

I have a parent job that triggers many downstream jobs dynamically.

I use python code to generate the list of jobs to be triggered, write it to a properties file, Inject the file using EnvInject plugin and then use the "Parameterized trigger plugin" with the job list variable (comma separated) variable to launch the jobs (If anyone know an easier way of doing this I would love to hear that also!).

It works great except when killing the parent job, the triggered jobs continue to run, and I want them dead also when killing the parent.

Is there a plugin or way to implement this? Maybe a hook that is called when a job is killed?

EDIT: Sorry for the confusion, I wasn't clear about what I meant with "killing" the job. I mean clicking the red 'x' button in the Jenkins gui, not the Unix signal.

Thanks in advance.

2
How do you kill the parent job? It is possible to set signal handlers, at least in Linux... - aychedee

2 Answers

2
votes

Instead of killing the job, have another job that programmatically terminates all the required jobs. You could reuse the same property file to know which all jobs to be killed. You could use groovy script to terminate jobs.

1
votes

To catch SIGTERM inside your process you could use the following code (unix specific):

import signal

def kill_children(*args, **kwargs):
    # some code that uses the stored list of children procs to kill them

signal.signal(signal.SIGTERM, kill_children)

There are lots of other signals that a process can receive. SIGKILL is the most obvious in your situation. So it would just be a matter of working out what signal was killing the parent and handling it.