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

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

问题描述

我有一个运行bash脚本的詹金斯工作.

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具有称为

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作业的构建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

export 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天全站免登陆