Ssh – jenkins cli build via ssh is disconecting after 10 minutes

Jenkinskeepalivessh

I have two jenkins instances. I want job at 1st instance to invoke job at 2nd instance, wait until it ends and perform some actions (using artifacts produced by job @ 2nd)

I've come up with this solution – using Jenkins CLI commands via SSH

ssh -p 2222 second-jenkins build second-job -s -v <further options>

But this session disconnects after 10minutes with message:

Received disconnect from 192.168.147.102: 2: User idle has timed out
after 600000ms.

I found ssh client option named ServerAliveInterval

ssh -o ServerAliveInterval=30 -p 2222 second-jenkins build second-job -s -v <...>

Documentation for this option says

ServerAliveInterval

Sets a timeout interval in seconds after which if no data has
been received from the server
, ssh(1) will send a message through
the encrypted channel to request a response from the server. The
default is 0, indicating that these messages will not be sent to
the server. This option applies to protocol version 2 only.

This works but only when server is quiet by at least 30 seconds within every 10 minutes. Of course I can use 1 second instead 30, but it wont work for jobs with continous console output (eg. maven builds).

Is there solution which keep connection alive even for hevy console output jobs?

Best Answer

Add this to Jenkins startup to disable the SSHD timeout:

-Dorg.jenkinsci.main.modules.sshd.SSHD.idle-timeout=0

See also https://blog.redaalaoui.me/blog/jenkins-cli-ssh-timeout/