0

我正在尝试将保留作业添加到 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-service它上面的步骤有关,但build-and-test-service确实存在,所以在这一点上我很难过。

4

1 回答 1

0

对于任何阅读的人,我都知道为什么它不起作用。

本质上,我在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那里。

于 2020-05-07T15:59:47.977 回答