系统软件环境

系统软件 版本
Jenkins 2.150.2
Slave Windows 10

问题描述

部分 Windows slave job 执行时间较长,日志分析发现不是Job脚本更新导致,而是因为Jenkins退出卡住。
日志分析:案例
具体任务在13:41就已经执行完成,但是Jenkins在13:51才退出返回结果。
也就是说整整卡住了10分钟,必须要解决。

原因分析

Jenkins 在 2.14 版本引入了 killSoftly 特性,出发点是想更加优雅的结束进程。
但是导致了 Windows slave上的 batch 脚本 执行完成 返回结果卡住(时间不确定)的情况。
Linux slave上的 shell 脚本执行退出没有发现此问题。

1
2
3
// Firstly try to kill the root process gracefully, then do a forcekill if it does not help (algorithm is described in JENKINS-17116)

killSoftly();

解决方法

可以通过 在Windows slave连接master机器的时候 增加 这个参数 -DSoftKillWaitSeconds=0 来解决。

1
2
3
# Run from agent command line:

java -Xrs -DSoftKillWaitSeconds=0 -jar agent.jar -jnlpUrl ...

使用上述命令重新连接 Master - Slave 后,可以在Slave系统信息界面看到参数生效了。
Slave信息

参考链接

https://issues.jenkins-ci.org/browse/JENKINS-55106
https://stackoverflow.com/questions/54039226/jenkins-hangs-between-build-and-post-build