Search code examples
jenkinssshpost-build

Jenkins post build script loads forever


I've made a web hook with bitbucket, and everything is working fine except the post build script, I'm trying to execute a shell command to push the build on the staging server, for some odd reason the shell hangs/loads forever after successfully logging in to the server using ssh key

here are my commands :

sudo ssh -tt -i ~/.ssh/id_rsa user@ip
cd default
git commit -am "inc Jenkins"
git pull origin master
composer install
npm install

The shell never finishes after executing the first line.

enter image description here

On the other side (The staging server), the auth log gave me this once the shell starts hanging : did not receive identification string from *****


Solution

  • The post build step works exactly as you set it: logins to interactive remote terminal. As no further input is given, the step hangs indefinitely.

    To make it work, you need to pass the desired commands using SSH syntax:

    ssh -i ~/.ssh/id_rsa user@ip "cd default;git commit -am \"inc Jenkins\";git pull origin master;composer install;npm install;exit"
    

    I omit the -tt as remote execution doesn't need it; you may want to keep it for some edge cases.