circlecicircleci-workflows

Executing a CircleCI job only when tag matches a certain pattern


I have the following workflow definition for a CircleCI build

workflows:
  version: 2
  default:
    jobs:
      - verify
      - tests_3_1:
          requires:
            - verify
      - tests_5_0:
          requires:
            - verify
      - pack:
          requires:
            - tests_3_1
            - tests_5_0
      - push:
          requires:
            - pack
          context:
            - GitHub
          filters:
              tags:
                only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
              branches:
                ignore: /.*/

The idea is to:

For some reason no build is triggered when the commit is tagged. I am not sure if the problem is in the filter or in the regex not matching the build tags.

For now I tried v0.1.0-preview-0001 which matches on RegexPal.

build is not triggered

Could you suggest any improvement? I see there is this question that is pretty similar but I have issues implementing the suggested solution


Solution

  • I solved this by specifying a tag regex filter for every job before push as shown in the documentation.

    workflows:
      version: 2
      default:
        jobs:
          - verify:
              filters:
                tags:
                  only: /.*/
          - tests_3_1:
              requires:
                - verify
              filters:
                tags:
                  only: /.*/
          - tests_5_0:
              requires:
                - verify
              filters:
                tags:
                  only: /.*/
          - pack:
              requires:
                - tests_3_1
                - tests_5_0
              filters:
                tags:
                  only: /.*/
          - push:
              requires:
                - pack
              context:
                - GitHub
              filters:
                  tags:
                    only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
                  branches:
                    ignore: /.*/