CircleCI运行多行命令

时间:2018-08-03 11:55:02

标签: unix ssh circleci circleci-2.0

CircleCI配置文件的摘录:

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

如何将命令分成多行?尝试使用以下语法,但仅运行第一个命令:

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

2 个答案:

答案 0 :(得分:4)

这是一个古老的视图,但是它有很多视图,所以我发现的内容似乎值得分享。

在CircleCI文档(https://circleci.com/docs/2.0/configuration-reference/#shorthand-syntax)中,它们指示使用运行速记语法也可以进行多行操作。

如下所示

- run: |
    git add --all
    git commit -am "a commit message"
    git push

问题示例与命令示例之间的区别在于命令位于“运行”下,而不是“命令”下。

答案 1 :(得分:2)

您需要将其他命令作为args传递给外壳程序(例如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'
相关问题