如何让Circle CI 只在测试成功后才在AWS ECS 上传部署镜像?

How to make Circle CI upload and deploy an image on AWS ECS only after tests are success?

我通过 Circle CI 将我的 Node.Js 应用程序部署到 AWS ECS。

我想先对 运行 进行测试,然后才将图像推送到存储库。但是,当前 运行 测试 运行 的任务与 AWS ECS 任务同时进行。下面是我的 ./circleci/config.yml 文件。

如何更改此行为,以便仅在测试成功时才推送图像?

version: 2.1
orbs:
  aws-ecr: circleci/aws-ecr@6.10.0
jobs:
  test:
    docker:
      - image: cypress/base:12.18.0
    steps:
      - checkout
      - run: npm ci
      - run: npm run cy:verify
      # save npm dependencies and Cypress binary for future runs
      - save_cache:
          key: cache-{{ checksum "package.json" }}
          paths:
            - ~/.npm
            - ~/.cache
      - run: npm run test:ci

workflows:
  version: 2.1
  test:
    jobs:
      - test
      - aws-ecr/build-and-push-image:
          create-repo: true
          no-output-timeout: 10m
          repo: 'stage-instance'

谢谢!

在工作流中添加一个需要的步骤以根据条件进行过滤。

version: 2.1
orbs:
  aws-ecr: circleci/aws-ecr@6.10.0
jobs:
  test:
    docker:
      - image: cypress/base:12.18.0
    steps:
      - checkout
      - run: npm ci
      - run: npm run cy:verify
      # save npm dependencies and Cypress binary for future runs
      - save_cache:
          key: cache-{{ checksum "package.json" }}
          paths:
            - ~/.npm
            - ~/.cache
      - run: npm run test:ci

workflows:
  version: 2.1
  test:
    jobs:
      - test
      - aws-ecr/build-and-push-image:
          create-repo: true
          no-output-timeout: 10m
          repo: 'stage-instance'
          requires:
            - test