SSHEXEC 任务有一个脚本在 Ant 中调用命令,从 Jenkins 调用,2 小时后超时

SSHEXEC task has a script calling in command in Ant, called from Jenkins, times out after 2 hours

在 Jenkins 中,基于 ANT XML 中存在的目标,我将调用该目标。该目标有 SSHEXEC 任务。

在那个SSHEXEC任务中,command调用了脚本。

基本上脚本代码如下:

waitForAggregationJobCompletion()
{
while [ 1 ]
do
# Checks for the condition

if [ #Condition] ;then
break;
fi

if [ #Different condition ]; then
break;
fi

done
waitForAggregationJobCompletion

基本上一旦这个函数“waitForAggregationJobCompletion”被调用,它就会进入 while[1] 循环并继续检查条件。一旦 if 满足 "IF" 条件中存在的条件,它就应该中断。

如果脚本 运行s 持续 1.5 小时,这 运行s 很好。但是如果脚本 运行ning 的时间更长,在 Jenkins 中它会说它仍在执行但是在 Linux 服务器上,它不会 运行ning.

是否因为sshexec ANT 中的任务只能将脚本进程保持一定时间?或者我是否需要在 sshd_config 文件中添加任何参数,然后再触发 while[1] 基于条件的脚本到 运行 更长时间。

我已将日志记录重定向放在脚本中,并用一个 echo 语句重定向到 /dev/null,但没有成功。

当我继续记录重定向时,它打印了那个带有日期的日志,持续时间接近 2.10 小时,然后该文件中就没有记录了。

你能帮帮我吗?

您可以查看 Bjørn Johansen 的“SSH timeout prevention – keep SSH sessions alive”中提到的技巧之一

在客户端,例如:

you can edit your local SSH config file in ~/.ssh/config and add the following line:

ServerAliveInterval 120

This will send a “null packet” every 120 seconds on your SSH connections to keep them alive.

在 Jenkins 上下文中,这将是 ~/.ssh/config 在 Jenkins 从服务器上执行作业的用户。


但是如果你有 access/control 到服务器端:

add the following to your SSH daemon config in /etc/ssh/sshd_config on your servers to prevent the clients to time out – so they don’t have to modify their local SSH config:

ClientAliveInterval 120
ClientAliveCountMax 720

This will make the server send the clients a “null packet” every 120 seconds and not disconnect them until the client have been inactive for 720 intervals (120 seconds * 720 = 86400 seconds = 24 hours).