CircleCI 工作流能否在第一步中创建 Docker 图像,然后在第二步中测试该 Docker 图像?

Can a CircleCI workflow create a Docker image in a first step and then test that Docker image in a second step?

我是 CircleCI 工作流的新手,我想创建一个包含两个步骤的工作流。

  1. 第一步(构建作业)将构建 Docker 映像并将其推送到带有特定标签的 Docker 注册表。第一次成功终止后 步骤它将触发第二个工作流程步骤并移交标签 Docker 图片。
  2. 然后第二步将下载步骤 1 传递的图像(例如使用 ENV 变量)。像
version: 2
    jobs:
      build:
        docker:
          - image: docker.repo.ch/image:${TAG}

在 CircleCI 工作流程中,是否有某种机制可以将值作为参数从一个构建作业传递到另一个构建作业?

Since every run step is a new shell, environment variables are not shared across steps. If you need an environment variable to be accessible in more than one step, export the value using BASH_ENV.

https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-step

将变量导出到下一个作业:

workflows:
  version: 2
  pass_tag:
    jobs:
    - create_tag
    - use_tag:
        requires:
        - create_tag

executors:
  node:
    docker:
      - image: circleci/node:4.8.2

jobs:
  create_tag:
    executor: node
    steps:
    - run: echo "export MY_TAG=$CIRCLE_SHA1" >> $BASH_ENV
  use_tag:
    executor: node
    steps:
    - run: echo $MY_TAG

推送并使用 docker 图片:

使用 CircleCI orbs(像一个库)来构建和推送图像:

version: 2.1
orbs:
    aws-ecr: circleci/aws-ecr@6.7.0

workflows:
  version: 2
  example:
   jobs:
      - aws-ecr/build-and-push-image:
          account-url: DEV_AWS_ECR_ACCOUNT_URL
          aws-access-key-id: DEV_ACCESS_KEY_ID
          aws-secret-access-key: DEV_SECRET_ACCESS_KEY
          create-repo: true
          repo: '${CIRCLE_PROJECT_REPONAME}'
          region: AWS_DEFAULT_REGION
          tag: '${CIRCLE_SHA1}'
      -  pull_image:
          requires:
              - aws-ecr/build-and-push-image

jobs:
    pull_image:
        *** pull and use your image here ***