Graceful job termination / cleanup before abort

9 views
Skip to first unread message

Dorin Bogdan

unread,
Nov 4, 2022, 12:42:27 PM11/4/22
to jenkin...@googlegroups.com
Hi all,

This matter is quite important for us, so any help is appreciated.
I'm not sure if this is a Jenkins bug or limitation.
Apparently the challenge looks like JENKINS-17116 but in essence is pretty different.
I'm working on:hpe-application-automation-tools-plugin and need to assure a graceful job termination on user's abort action.

During the job build, the flow is reaching the following step (common for both: free-style job and pipeline job):

On line 111 from AlmToolsUtils.java we launch a long-executing process (C# executable with arguments):
int returnCode = launcher.launch().cmds(args).stdout(out).pwd(file.getParent()).envs(envs).join();

Where the method join() is defined in hudson.Launcher:
// Starts the process and waits for its completion.
public int join() throws IOException, InterruptedException {
...
final int returnCode = procHolderForJoin.join();
...
}
Where the method procHolderForJoin.join() is defined in hudson.Proc.LocalProc:
// Waits for the completion of the process.
public int join() throws InterruptedException, IOException {
...
try { int r = proc.waitFor(); ...
return r; } catch (InterruptedException e) { // aborting. kill the process destroy(); throw e; } finally { t.setName(oldName); }
}

If the user aborts the job (so that the InterruptedException is automatically fired by Jenkins), is there a way to call a cleanup (callback) method before the process is killed by destroy()?
(I mean a callback method defined on either plugin-side or C# process-side).

Any suggestions?

Please advise.

Thanks,
Dorin.

Jesse Glick

unread,
Nov 4, 2022, 1:30:41 PM11/4/22
to jenkin...@googlegroups.com
While you could probably intercept this somehow on the Jenkins plugin side, Jenkins should be sending SIGTERM (on Unix; not sure about Windows) so it would seem most appropriate to have the native command handle that gracefully. You would need to ask in another forum how best to do that in C#.
Reply all
Reply to author
Forward
0 new messages