CircleCI配置仅Tag触发工作流失败,无工作流执行
问题描述
尝试配置CircleCI仅在匹配unstable-*格式的Tag(如unstable-2.7.31)触发工作流,但当前设置后无工作流运行;移除分支忽略规则后,所有分支和Tag都会触发工作流。
当前配置文件(.circleci/config.yml)
only-deploy-unstable: &only-deploy-unstable context: Unstable-context filters: tags: only: /^unstable-.*/ branches: ignore: /.*/ version: 2.1 jobs: build_unstable: docker: - image: docker:20.10.8 environment: DOCKER_IMAGE_BASE_URL: ********** steps: - checkout - setup_remote_docker - run: apk update - run: apk add git - run: docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - run: name: build and push unstable docker image no_output_timeout: 15m command: | export TAG_NAME=$(git describe --tags --abbrev=0) echo ${DOCKER_IMAGE_BASE_URL}:$TAG_NAME docker build --build-arg STAGING=test --rm -t $DOCKER_IMAGE_BASE_URL:$TAG_NAME -t $DOCKER_IMAGE_BASE_URL:latest . docker push $DOCKER_IMAGE_BASE_URL:$TAG_NAME docker push $DOCKER_IMAGE_BASE_URL:latest deploy_unstable: docker: - image: docker:20.10.8 steps: - checkout - setup_remote_docker - run: command -v ssh-agent >/dev/null || ( apk add --update openssh ) - run: eval $(ssh-agent -s) - run: ******************** workflows: # build unstable-version build_and_push_unstable: jobs: - build_unstable: *only-deploy-unstable - hold: <<: *only-deploy-unstable type: approval requires: - build_unstable - deploy_unstable: <<: *only-deploy-unstable requires: - hold
问题原因与解决方案
问题根源
你的配置仅在Job级别添加了过滤规则,但CircleCI的工作流(Workflow)默认不会对Tag事件触发执行,必须在工作流层面明确允许Tag触发,同时配合Job的过滤规则才能生效。
正确配置方式
调整配置,确保每个Job(包括审批节点)都配置匹配规则,保证工作流只响应符合要求的Tag事件。以下是修改后的完整配置:
version: 2.1 jobs: build_unstable: docker: - image: docker:20.10.8 environment: DOCKER_IMAGE_BASE_URL: ********** steps: - checkout - setup_remote_docker - run: apk update - run: apk add git - run: docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - run: name: build and push unstable docker image no_output_timeout: 15m command: | export TAG_NAME=$(git describe --tags --abbrev=0) echo ${DOCKER_IMAGE_BASE_URL}:$TAG_NAME docker build --build-arg STAGING=test --rm -t $DOCKER_IMAGE_BASE_URL:$TAG_NAME -t $DOCKER_IMAGE_BASE_URL:latest . docker push $DOCKER_IMAGE_BASE_URL:$TAG_NAME docker push $DOCKER_IMAGE_BASE_URL:latest deploy_unstable: docker: - image: docker:20.10.8 steps: - checkout - setup_remote_docker - run: command -v ssh-agent >/dev/null || ( apk add --update openssh ) - run: eval $(ssh-agent -s) - run: ******************** workflows: build_and_push_unstable: jobs: - build_unstable: context: Unstable-context filters: tags: only: /^unstable-.*/ branches: ignore: /.*/ - hold: type: approval requires: - build_unstable filters: tags: only: /^unstable-.*/ branches: ignore: /.*/ - deploy_unstable: requires: - hold filters: tags: only: /^unstable-.*/ branches: ignore: /.*/
关键说明
- 每个Job(包括
hold审批节点)都必须配置filters,确保仅在符合规则的Tag事件下执行。 branches: ignore: /.*/会忽略所有分支触发的事件,保证工作流只响应Tag推送。- 确认推送的Tag格式严格匹配正则
/^unstable-.*/(如unstable-2.7.31完全符合)。 - 可前往CircleCI项目设置页面,确认「Advanced Settings」中未禁用Tag触发的工作流。
内容的提问来源于stack exchange,提问作者L'amjed Bouhouch
相关产品推荐
相关产品推荐

