gpt4 book ai didi

linux - 通过 Jenkins 在 shell 中执行 "pkill"- 构建失败

转载 作者:太空狗 更新时间:2023-10-29 11:36:03 25 4
gpt4 key购买 nike

我正在通过 Jenkins 在 linux shell 上执行 pkill 命令。当进程不存在时,此命令总是会导致构建失败。

sudo docker exec mycontainer sh -c 'pkill -f processToKill || true '

为什么?我怎样才能让它成功,即使 pkill 失败?

最佳答案

你在自杀——|| true 部分永远不会到达:

$ sh -c 'pkill -f processToKill || true' ; echo $?
Terminated
143

原因是您提供给pkill-f 标志。来自手册页:

   -f, --full
The pattern is normally only matched against the process name.
When -f is set, the full command line is used.

您需要改进 pkill 语句的进程选择,这样它就不会捕获您传递给 sh 的命令行。

关于linux - 通过 Jenkins 在 shell 中执行 "pkill"- 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37930295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com