詹金斯杀死所有子进程 [英] Jenkins kill all child processes

查看:37
本文介绍了詹金斯杀死所有子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 bash 脚本的 jenkins 工作.

I have a jenkins job that runs a bash script.

在 bash 脚本中,我有效地执行了两个操作,例如

In the bash script I perform effectively two actions, something like

java ApplicationA &
PID_A=$!
java ApplicationB
kill $PID_A   

但如果作业被手动中止,ApplicationA 将保持活动状态(如节点机器上的 ps -ef 所示).我不能使用诱捕等,因为如果 jenkins 发送 9 信号(诱捕对 9 不起作用),这将不起作用.

but if the job is manually aborted, the ApplicationA remains alive (as can be seen with a ps -ef on the node machine). I cannot use trapping and so on, because that won't work if jenkins sends a 9 signal (trapping doesn't work for 9).

如果可以将此作业配置为简单地终止它产生的所有进程,那将是理想的,我该怎么做?

It would be ideal if this job could be configured to simply kill all processes that it spawns, how can I do that?

推荐答案

其实,默认情况下,Jenkins 有一个功能叫做 ProcessTreeKiller 负责确保在作业执行后没有 进程仍在运行.

Actually, by default, Jenkins has a feature called ProcessTreeKiller which is responsible to make sure there are no processes left running after the job execution.

上面的链接解释了如何禁用该功能.你确定你没有以某种方式错误地禁用了它?

The link above explain how to disable that feature. Are you sure you don't have that disabled by mistake somehow?


根据作者的评论,根据关于禁用ProcessTreeKiller的信息,要实现逆向必须将环境变量BUILD_ID设置为Jenkins作业的build id.这样,当ProcessTreeKiller查看正在运行的进程杀死时,它也会发现这一点


Following the comments by the author, based on the information about disabling ProcessTreeKiller, to achieve the inverse one must set the environment variable BUILD_ID to the build id of Jenkins job. This way, when ProcessTreeKiller looks through the running processes to kill, it will find this as well

导出BUILD_ID=$BUILD_ID

您也可以使用构建结果触发器插件,配置第二个作业来清理您的应用程序,并将其配置为监视第一个作业的 ABORTED 状态作为触发器.

You can also use the Build Result Trigger plugin, configure a second job to clean up your applications, and configure it to monitor the first job for ABORTED state as a trigger.

这篇关于詹金斯杀死所有子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆