Workflow Job with Tag Filter being run for every commit

I have three workflows defined and associated with my Circle repo.

One of the three looks like this:

...  
deploy-production:
    jobs:
      - docker_production_build:
          filters:
            branches:
              only: master
            tags:
              only: /^v[0-9]+(\.[0-9]+)*$/
...

It is a workflow with one job and no dependencies. My expectation is for this workflow to run only when I push to the master branch with a version tag (see tag pattern). However, this seems to run every time that I push to master. Can help me understand why?

https://discuss.circleci.com/t/circle-2-0-workflow-filters-should-be-logical-and-not-or/18231

Thanks, Jon.

I must add that even on removing the branch filter, that job is run for every commit to master and not only for the version tag push which is my expectation. Am I missing something?

Phew, finally got it to work. The solution leverages on the fact that multiple filters are ORed by CircleCI:

...
deploy-production:
  jobs:
    - docker_production_build:
        filters:
          # ignore any commit on any branch by default
          branches:
            ignore: /.*/
          # only act on version tags
          tags:
            only: /^v[0-9]+(\.[0-9]+)*$/
...

I guess it is mostly my fault as it is mentioned in the documentation that branches are included and tags are excluded by default. However, my intuition for mixing the two filters did not match what CircleCI expected.

5 Likes

Hello, can you share what git commands did you run to trigger builds on tags ?
I have tried tens of different combinations without being able to trigger a single build from a git tag …

Hey @tsauvajon,

This should work AFAIK:

# vX.X.X... is the tag pattern that we expect in the 
# CircleCI config to trigger a build
➤ git tag v0.1.0 && git push --tags origin
1 Like

Indeed the jobs ran, I just didn’t look at the right place (the workflows were just not located at the same place as the branches workflows).

They do not directly appear on the left panel behind the project name, as branch workflows do.
To access them I clicked the project name to go to the project’s workflows at https://circleci.com/:provider/:org/workflows/:project.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.