Fix Shell Script Run via SSH Hanging (Jenkins)

There is an important difference between running a script manually (ssh machine; machine$ ./ and running it via ssh (ssh machine < in the letter case the connection will not close when the script finishes but will stay open until stdout/stderr are closed or a timeout occurs. In Jenkins it will therefore seem as if the script hangs.

So if your shell scripts starts any background job, make sure to redirect all its output to somewhere:

nohup some-background-task &> /dev/null   # No space between & and > !

This has bitten me when trying to deploy an application from the Jenkins CI using SSH and a shell script.


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob