Multiple remote SSH commands

Hi there,

I am trying to figure out how to write down multiple SSH commands on the remote server. For now I created environment variables to make it less painfull to do a ssh login per command, but I prefer to open one SSH connection and then execute all the commands (more efficient).

My only working solution now is to create separate lines with SSH login and commands:

 - ssh $DEPLOY_USER@$DEPLOY_SERVER tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder" 
- ssh $DEPLOY_USER@$DEPLOY_SERVER wget --cache=off --output-document $DEPLOY_PATH/
etc etc
I tried some varations (see below), but that leads to build failures as the SSH command is not working (interpreted as one string or command not remotely executed but on docker image)
Variation 1
- ssh $DEPLOY_USER@$DEPLOY_SERVER 'tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder"; wget --cache=off --output-document $DEPLOY_PATH/;'
Variation 2
              tar -xzf $DEPLOY_PATH/deploy.tar.gz --directory="$DEPLOY_PATH/folder";
              wget --cache=off --output-document $DEPLOY_PATH/;
As I use ENV variables for most commands, I was not able to find a way to include those variables in the remote bash script, otherwise I had to execute only one bashscript to do all the tasks. And besides, when you put multiple commands in 1 bash script, you don't have the advantage of the step by step logging in bitbucket pipelines, as it is interpreted as 1 command.
Hope anyone has a solution!

0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

714 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot