There is an important difference between running a script manually (
ssh machine; machine$ ./script.sh) and running it via ssh (
ssh machine < script.sh): 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.