CircleCI 保持步骤

CircleCI Hold step

我正在尝试将保留作业添加到 CircleCI 的 config.yml 文件中的工作流程中,但我无法让它工作,我很确定这对我来说是一个非常简单的错误(我只是可以'没看到!)。

在本地使用 CircleCI CLI 验证它时 运行 以下命令

circleci config validate:

我收到以下错误

Error: Job 'hold' requires 'build-and-test-service', which is the name of 0 other jobs in workflow 'build-deploy'

这是 config.yml(请注意,它适用于无服务器框架应用程序 - 不会有任何区别)

version: 2.1
jobs:
  build-and-test-service:
    docker:
      - image: timbru31/java-node
    parameters:
      service_path:
        type: string
    steps:
      - checkout
      - serverless/setup:
          app-name: serverless-framework-orb
          org-name: circleci
      - restore_cache:
          keys:
            - dependencies-cache-{{ checksum "v2/shared/package-lock.json" }}-{{ checksum "package-lock.json" }}-{{ checksum "<< parameters.service_path >>/package-lock.json" }}
            - dependencies-cache
      - run:
          name: Install dependencies
          command: |
            npm install
            cd v2/shared
            npm install
            cd ../../<< parameters.service_path >>
            npm install
      - run:
          name: Test service
          command: |
            cd << parameters.service_path >>
            npm run test:ci
      - store_artifacts:
          path: << parameters.service_path >>/test-results/jest
          prefix: tests
      - store_artifacts:
          path: << parameters.service_path >>/coverage
          prefix: coverage
      - store_test_results:
          path: << parameters.service_path >>/test-results
  deploy:
    docker:
      - image: circleci/node:lts
    parameters:
      service_path:
        type: string
      stage_name:
        type: string
      region:
        type: string
    steps:
      - run:
          name: Deploy application
          command: |
            cd << parameters.service_path >>
            serverless deploy --verbose --stage << parameters.stage_name >> --region << parameters.region >>
      - save_cache:
          paths:
            - node_modules
            - << parameters.service_path >>/node_modules
          key: dependencies-cache-{{ checksum "package-lock.json" }}-{{ checksum "<< parameters.service_path >>/package-lock.json" }}
orbs:
  serverless: circleci/serverless-framework@1.0.1
workflows:
  version: 2
  build-deploy:
    jobs:
      # non-master branches deploys to stage named by the branch
      - build-and-test-service:
          name: Build and test campaign
          service_path: v2/campaign
          filters:
            branches:
              only: develop
      - hold:
          name: hold
          type: approval
          requires:
            - build-and-test-service
      - deploy:
          service_path: v2/campaign
          stage_name: dev
          region: eu-west-2
          requires:
            - hold

很明显错误与 hold 步骤(靠近配置底部)有关,无法找到其上方的 build-and-test-servicebuild-and-test-service 确实存在,所以我难倒在这一点上。

对于所有阅读我的人,我弄清楚了为什么它不起作用。

基本上我在 requires 键下使用了不正确的 属性 引用:

workflows:
  version: 2
  build-deploy:
    jobs:
      # non-master branches deploys to stage named by the branch
      - build-and-test-service:
          name: Build and test campaign
          service_path: v2/campaign
          filters:
            branches:
              only: develop
      - hold:
          name: hold
          type: approval
          requires:
            - build-and-test-service

在这种情况下,正确的 属性 引用应该是上一步的 name,即 Build and test campaign,所以我只是将该名称更改为 build-and-test-service

我发现 CircleCI 文档对此不是很清楚,但也许是因为他们围绕手动批准的示例指出 requires 属性 应该指向作业的根键,例如build-and-test-service.

我想我也应该更加警惕我的错误阅读,它确实在那里也提到了 name