我试图在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
确实存在,因此被绊倒在这一点。
答案 0 :(得分: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
。