我想构建一个 CircleCI 工作流程,仅当我在 Github 中创建标记版本时才构建并推送到 ECR。
我有以下 CircleCI 工作流程:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies
- unit_tests:
requires:
- get_python_dependencies
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
filters:
tags:
only: /.*/
branches:
ignore: /.*/
据我了解,过滤器build-and-push-to-ecr
应该意味着:
- 为任何标签运行此作业
- 推送到任何分支时不要运行此作业
但是当我创建一个标记版本时,我得到:
为什么我的过滤器不起作用?
非常仔细地阅读下面的文档执行 git 标签的工作流程 https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag揭示了一个隐藏得很好的细节:
如果作业需要任何其他作业(直接或间接),则必须使用正则表达式为这些作业指定标签过滤器。
换句话说,工作流程中的每个作业都必须具有相同的过滤器才能发生构建和推送作业。
我们可以使用以下方法让东西保持干燥一点&
锚点:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies:
filters: &tagged
# We only want to trigger this workflow on tags, not pushes to branches.
branches:
ignore: /.*/
tags:
# Trigger on every tag
only: /.*/
- unit_tests:
requires:
- get_python_dependencies
<<: *tagged
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
<<: *tagged
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)