Running a workflow after tagging commit

Hello everybody, I’m new on CircleCI and I’m trying to understand if it supports a simple CI/CD workflow I’ve designed.

Long story short, I’d like to run a workflow only on main branch when a tag is attached to a commit.

I tried

workflows:
  delivery:
    jobs:
      - build_and_deliver:
          filters:
            tags:
              ignore: /^$/
            branches:
              only: main

but as soon as I merge a PR, It runs.
I expect /^$/ to match an empty string, so It shouldn’t until I push the new tag.
I’ve also tried the complementary statement:
tags:
only: /.*/

I’m using BitBucket integration.
Any suggestion?

As I understand it, when using filters the branches expression is evaluated first and if it results in a true condition the job is run. The tag expression is only evaluated if the branches expression returns false.

This limits filters to the following structure

       filters:
          tags:
            only: /[regex match]/
          branches:
            ignore: /.*/

So any branch information gets ignored and then a check against the tag value takes place.

Thanks for explaining. I had actually read something about precedence but I couldn’t interpret it correctly. I was assuming the two conditions were OR or AND.

The best approximation I’ve got so far is

workflows:
  wf1:
    jobs:
      - ci:
          filters:
            tags:
              only: /^$/
  wf2:
    jobs:
      - cd:
          filters:
            tags:
              only: /.*/

but wf1 is still running on the main branch

The problem is the bit about “The tag expression is only evaluated if the branches expression returns false”. You have to do a branch check first to cause the tag check to take place.

It is not clear why this limitation was built into the scripting DSL, but it is unlikely CircleCI can make any changes to it unless they issue a new DSL version, something I’ve not seen any indication of happening, beyond a comment on the following message exchange

That message exchange also indicates a possible workaround, where you use a filter that always fires with a branch and tag check. This then causes both pipeline variables to be populated and so a job level ‘when’ condition should be possible.

I see. It looks a bit like a hack but If It works, It’s definitely an option. Thanks for sharing.

Oh, if it works it is a 100% bonafide hack.