# Can't trigger workflow on git tag push using when condition

**URL:** <https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252>\
**Category:** Build Environment\
**Tags:** circle-yml\
**Created:** [March 15, 2022, 4:27pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252 "2022-03-15T16:27:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vanals](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/vanals/32/28585_2.png) [@Vanals](https://discuss.circleci.com/u/Vanals)\
**Post date:** [March 15, 2022, 4:27pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/1 "2022-03-15T16:27:26Z")

</div>

Hi,

I am doing some **testing** and working on a release pipeline.  
At some point in my pipeline, I want to update my package.json, push it and then trigger a next workflow to actually deploy to prod.  
To do so I thought to update my package.json in a first workflow which we can call “A”. At the end, A, will push a tag doing something like:  
`git tag -a v0.2 -m "my version 0.2" && git push origin v0.2`

I would be then expecting it to trigger a next workflow which would take care of the release.  
I am aiming to le the workflow trigger on tag push with a syntax like that

```auto
on_tag:
    when: << pipeline.git.tag >>
    jobs:
      - build

```

Using the when conditional on it. But it does not trigger.

Just for testing, I also tried something like

```auto
    when: 
      and:
        - equal: [v0.3, << pipeline.git.tag >>]
    jobs:
      - build

```

using equal; but still.

Using a filter, like:

```auto
only_on_push_tag: &only_on_push_tag
  filters:
    tags:
      only: /^v0.5.*/
    branches:
      ignore: /.*/

```

does work.

But I want to stick to the when approach. I can see in the documentation there is some example using the pipeline.tag, even if different.

```auto
workflows:
  my-workflow:
    when:
      and:
        - not:
            matches:
              pattern: "^main$"
              value: << pipeline.git.branch >>
        - or:
            - equal: [canary, << pipeline.git.tag >>]
            - << pipeline.parameters.deploy-canary >>

```

So to conclude, any suggestion on how to trigger a workflow on tag push using the `when` condition? why is not working? Thanks  
For now we are not using any package for bumping the package.json, etc.

---

<div class="post-metadata">

**Author:** ![jackgoodacre-crypto](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jackgoodacre-crypto/32/29949_2.png) [@jackgoodacre-crypto](https://discuss.circleci.com/u/jackgoodacre-crypto)\
**Post date:** [April 20, 2022, 11:54am UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/2 "2022-04-20T11:54:44Z")

</div>

+1

In my case I’m restricted to using workflow conditionals due to the requirements for [path-filtering](https://github.com/CircleCI-Public/api-preview-docs/blob/path-filtering/docs/path-filtering.md#using-the-path-filtering-orb). Filters on jobs do not work in this case as path-filtering requires only a single workflow to be triggered.

Sadly I am also struggling to get the `matches` or `equal` logical operator working against the `pipeline.git.tag` despite following examples & testing:

```auto
# staging
  cicd-staging:
    when:
      matches: { pattern: '^v1.0.0-.+$', value: << pipeline.git.tag >> }
    jobs:
      - path-filtering/filter:
          name: 'serverless-cicd'
          base-revision: master
          mapping: |
            dir1/.* dir1-modified true
            dir2/.* dir2-modified true
          config-path: .circleci/serverless-cicd.yml

```

---

<div class="post-metadata">

**Author:** ![icco](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/icco/32/15877_2.png) [@icco](https://discuss.circleci.com/u/icco)\
**Post date:** [June 29, 2022, 8:39pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/3 "2022-06-29T20:39:57Z")

</div>

We are also seeing this and want to know the answer.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [June 29, 2022, 10:39pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/4 "2022-06-29T22:39:44Z")

</div>

I think the issue comes from the fact that \<\<pipeline.git.tag\>\> seems to only be populated with a tag value if a job filter exists that first passes all branches and contains a check against possible tag values.

So it seems that a workflow needs the following filter block in place (depending on your config needs)

```auto
    filters:
      tags:
         ignore: //
      branches:
         ignore: /.*/

```

It also seems to mean that a when: structure at the workflow level can not do a check against \<\<pipeline.git.tag\>\> as it seems to control the execution of the filter, which in turn is responsible for the population of \<\<pipeline.git.tag\>\>

---

<div class="post-metadata">

**Author:** ![sulami](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sulami/32/27472_2.png) [@sulami](https://discuss.circleci.com/u/sulami)\
**Post date:** [July 1, 2022, 12:18pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/5 "2022-07-01T12:18:04Z")

</div>

Hey all,

what’s happening here is that `when` for workflows is something that has been added fairly recently. CircleCI has always ignored tag pushes by default, unless opted in via `filters` as described by @rit1010 or described [here](https://circleci.com/docs/2.0/workflows#executing-workflows-for-a-git-tag).

In effect what’s happening is that without `filters` we don’t run a workflow and don’t actually make it to the stage where we evaluate `when`. The best workaround I can offer for now is something along the lines of

```yaml
filters:
  tags:
    only:
      - /.*/

```

combined with the `when` expression of your choice.

In the long run I’m hoping we can collapse these two filtering mechanisms into one, but with the need to preserve backwards compatibility for existing configs that’s easier said than done.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [July 1, 2022, 5:36pm UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/6 "2022-07-01T17:36:52Z")

</div>

Would not more use of the ‘version:’ feature resolve the backwards compatibility issue?

It does seem that there is quite a list of requested improvements to the scripting language that will break what is already developed unless ‘version:’ starts to be used.

---

<div class="post-metadata">

**Author:** ![sulami](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sulami/32/27472_2.png) [@sulami](https://discuss.circleci.com/u/sulami)\
**Post date:** [July 4, 2022, 7:17am UTC](https://discuss.circleci.com/t/cant-trigger-workflow-on-git-tag-push-using-when-condition/43252/7 "2022-07-04T07:17:59Z")

</div>

That’s a fair point, and we’re currently actively looking at the next version of config, which will likely be a smaller, iterative improvement rather than a big change, and is likely to include a fix for this.
