Jenkins Pipeline长时间运行出现client_loop: send disconnect: Broken pipe报错求助
解决Jenkins Pipeline中client_loop: send disconnect: Broken pipe错误
可能原因及修复方案
- SSH连接超时:Jenkins Agent与远程服务器的SSH连接因长时间无数据传输被断开
- 在Pipeline的SSH步骤中添加心跳参数,保持连接活跃:
sshCommand remote: remote, command: 'your_task_command', sshArgs: '-o ServerAliveInterval=60 -o ServerAliveCountMax=3' - 也可在Jenkins全局配置(Manage Jenkins > Configure System > SSH remote hosts)中,为目标主机添加上述心跳参数。
- 在Pipeline的SSH步骤中添加心跳参数,保持连接活跃:
- Agent资源不足:长时间运行的Pipeline占用过多内存,导致连接异常中断
- 调整Jenkins Agent的JVM内存参数,比如修改启动脚本中的
JAVA_OPTS="-Xmx2g"(根据实际情况调整内存值)。 - 优化Pipeline代码,清理不必要的临时资源、拆分长任务步骤。
- 调整Jenkins Agent的JVM内存参数,比如修改启动脚本中的
- 远程服务器TCP配置限制:服务器TCP栈设置了较短的空闲连接超时
- 在远程服务器修改
/etc/sysctl.conf,调整TCP保活参数:net.ipv4.tcp_keepalive_time=600 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=3 - 执行
sysctl -p使配置生效。
- 在远程服务器修改
- 步骤无持续输出:长耗时命令无输出被判定为空闲连接
- 给长运行命令添加输出操作,比如
your_long_command | tee -a runtime.log,确保有持续输出。 - 使用
timeout命令限制单步骤运行时长,避免无限阻塞。
- 给长运行命令添加输出操作,比如
内容的提问来源于stack exchange,提问作者B. Naga Lakshmi
相关产品推荐
相关产品推荐

