unixsshcirclecicircleci-2.0

CircleCI run multi line command


Excerpt from a CircleCI config file:

deploy:
  machine:
    enabled: true
  steps:
    - run:
        name: AWS EC2 deploy
        command: |
          ssh -o "StrictHostKeyChecking no" ubuntu@xxx.xxx.xxx.xxx "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 ubuntu@xxx.xxx.xxx.xxx
          cd ~/circleci-aws
          git pull
          npm i
          npm run build
          pm2 restart build/server

Solution

  • You'll need to pass those other commands as args to a shell (like bash):

    ssh -o StrictHostKeyChecking=no ubuntu@xxx.xxx.xxx.xxx bash -c '
          cd ~/circleci-aws
          git pull
          npm i
          npm run build
          pm2 restart build/server'