Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to use multiple command in ssh run

Hello Guys

 

Below is my pipe code and want to use multiple command so how can i do that.

 

Thank you.

 

pipe: atlassian/ssh-run:0.1.3
variables:
SSH_USER: $USER
SERVER: $SERVER
#SSH_KEY: $MYKEY
PORT: 22
COMMAND: 'sudo chmod -R 755 filename/*'

 

2 answers

The command variable only accepts a single command. If the shell on the remote server happens to be Bourne shell-like (such as bash), you can use a YAML multiline block with command chaining to get this effect.

- pipe: atlassian/ssh-run:0.1.3
variables:
# ... other vars ...
COMMAND: >
sudo chmod -R 755 filename/* &&

sudo other command/*

This style will not run the second command if the first one fails. If you want the second command run no matter what, you can use `;` instead of `&&` as a separator.

As the docs suggest, it's probably better to use a script file, as you can control the shell being used and can more easily write tests around the command.

Very neat and straight answer, thank you dude!

Hi Hardik,

I haven't used this pipe myself, but from reading the docs I think what you want is the "script" mode, as per this example (taken straight from the docs):

script:
  - pipe: atlassian/ssh-run:0.2.0
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      SSH_KEY: $MY_SSH_KEY
      MODE: 'script'
      COMMAND: 'myscript.sh' # path to a script in your repository

If you don't want to add the script to your repository, then you could always create it in your build script just before launching the pipe, eg:

script:
- 'echo ''command 1'' > myscript.sh'
- 'echo ''command 2'' >> myscript.sh'
- 'echo ''command 3'' >> myscript.sh'
- pipe: atlassian/ssh-run:0.2.0
... etc

Hello Steven,

 

Thankx for your response. But I am looking like something as below

 

pipe: atlassian/ssh-run:0.1.3

variables:

SSH_USER: $USER

SERVER: $SERVER

#SSH_KEY: $MYKEY

PORT: 22

COMMAND: 'sudo chmod -R 755 filename/*'

COMMAND: 'sudo other command/*'

 

Is this possible?

Try this:

script:
- 'echo ''sudo chmod -R 755 filename/*'' > my-ssh-script.sh'
- 'echo ''sudo other command/*'' >> my-ssh-script.sh'
- pipe: atlassian/ssh-run:0.2.0
variables:
SSH_USER: $USER
SERVER: $SERVER
PORT: 22
MODE: 'script'
COMMAND: 'my-ssh-script.sh'
Like mkarthauser likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,762 views 10 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you