Excerpt from a CircleCI config file:
deploy:
machine:
enabled: true
steps:
- run:
name: AWS EC2 deploy
command: |
ssh -o "StrictHostKeyChecking no" [email protected] "cd ~/circleci-aws; git pull; npm i; npm run build; pm2 restart build/server
How can I break the command into multiple lines? Tried below syntax, but it only runs the first command:
deploy:
machine:
enabled: true
steps:
- run:
name: Deploy
command: |
ssh -o StrictHostKeyChecking=no [email protected]
cd ~/circleci-aws
git pull
npm i
npm run build
pm2 restart build/server
This is an old one, but it's had a lot of views so what I've found seems worth sharing.
In the CircleCI docs (https://circleci.com/docs/2.0/configuration-reference/#shorthand-syntax) they indicate that in using the run shorthand syntax you can also do multi-line.
That would look like the following
- run: |
git add --all
git commit -am "a commit message"
git push
The difference between the question's example and this is the commands are under "run", not "command".
You'll need to pass those other commands as args to a shell (like bash
):
ssh -o StrictHostKeyChecking=no [email protected] bash -c '
cd ~/circleci-aws
git pull
npm i
npm run build
pm2 restart build/server'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With