Missed Team ’24? Catch up on announcements here.

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

how to use multiple command in ssh run

nexus_hardik June 20, 2019

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

5 votes
Christopher Currie February 15, 2020

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.

lazyCoder September 5, 2020

Very neat and straight answer, thank you dude!

1 vote
Steven Vaccarella
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2019

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
nexus_hardik June 25, 2019

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?

Steven Vaccarella
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2019

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
AUG Leaders

Atlassian Community Events