我正在尝试在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/[email protected]
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
确实存在,因此在这一点上很困难。
对于任何阅读我的人,我都知道为什么它不起作用。
基本上我在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
。