9

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
4

2 回答 2

14

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

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

如下所示

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

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

于 2020-05-06T14:40:24.797 回答
3

您需要将这些其他命令作为 args 传递给 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'
于 2018-08-04T19:45:42.293 回答