我正在通过 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/