CircleCI 运行 多行命令

CircleCI run multi line command

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

您需要将这些其他命令作为参数传递给 shell(如 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'

这是一个旧的,但它有很多观点,所以我发现的东西似乎值得分享。

在 CircleCI 文档 (https://circleci.com/docs/2.0/configuration-reference/#shorthand-syntax) 中,他们指出在使用 运行 shorthand 语法时你也可以做多行。

看起来像下面这样

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

问题示例与命令之间的区别是 "run",而不是 "command"。