# I have two workflows with opposite filters and both are run when I do a pull request; I would expect only one to run

**URL:** <https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320>\
**Category:** Build Environment\
**Created:** [April 7, 2018, 1:05pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320 "2018-04-07T13:05:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastianovide](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastianovide/32/13258_2.png) [@sebastianovide](https://discuss.circleci.com/u/sebastianovide)\
**Post date:** [April 7, 2018, 1:05pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/1 "2018-04-07T13:05:10Z")

</div>

I have two work flows with opposite filters and both are run when I do a pull request. I would expect only ONE to run…

any ideas ?

```
workflows:
  version: 2

  build_and_deploy_beta:
    jobs:
      - build:
          filters:
            tags:
              ignore: /^release-.*/

      - deploy_beta:
          requires:
            - build
          filters:
            branches:
              only: master
            tags:
              ignore: /^release-.*/

  build_and_release:
    jobs:
      - build:
          filters:
            tags:
              only: /^release-.*/

      - release:
          requires:
            - build
          filters:
            tags:
              only: /^release-.*/
```

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [April 7, 2018, 5:09pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/2 "2018-04-07T17:09:53Z")

</div>

I moved this to a new topic as this is a separate issue and the last topic was 24 days old.

I would recheck the defaults for branch and tag filters. By default, branches include everything and tags exclude everything. Both workflows are running because both `build` jobs in each workflow are suppose to run. Nothing is telling them not to. A PR is just a branch commit like any other commit. Without any ignore filter, the `build` jobs will run.

---

<div class="post-metadata">

**Author:** ![sebastianovide](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastianovide/32/13258_2.png) [@sebastianovide](https://discuss.circleci.com/u/sebastianovide)\
**Post date:** [April 7, 2018, 6:12pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/3 "2018-04-07T18:12:37Z")

</div>

Thanks for splitting the topic.

Thanks makes sense.

I’ve added `ignore: /.*/` telling to ignore any tag but it still builds. How can I tell CI to build **only** on tags matching `/^release-.*/` but **ignoring** anything else ?

```
  build_and_release:
    jobs:
      - build:
          filters:
            tags:
              only: /^release-.*/
              ignore: /.*/
```

---

<div class="post-metadata">

**Author:** ![chucksellick](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@chucksellick](https://discuss.circleci.com/u/chucksellick)\
**Post date:** [April 8, 2018, 10:33pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/4 "2018-04-08T22:33:54Z")

</div>

I also just tried numerous variations on configuration based on what is in the docs and also what has been written by various people in various threads.

It basically seems like regardless of what I do, ‘branches’ is the only filter that CircleCI actually bases any decisions on, when both filters are present.

What I want to do: deploy when I push a tagged release to master. That’s all. I don’t want to deploy based on a tag getting pushed to any other branch, but I don’t think it’s possible to configure this. You can either say “deploy from any branch when a tag gets pushed”, or “always deploy whatever gets pushed to master”.

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [April 9, 2018, 11:51pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/5 "2018-04-09T23:51:22Z")

</div>

You’d need to ignore all branches, not tags. Something like this:

```auto
workflows:
  version: 2
  build_and_deploy_beta:
    jobs:
      - build
      - deploy_beta:
          requires:
            - build
          filters:
            branches:
              only: master

  build_and_release:
    jobs:
      - build:
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^release-.*/
      - release:
          requires:
            - build
          filters:
            branches:
              ignore: /.*/
            tags:
              only: /^release-.*/

```

But you could probably combine that into one Workflow.

---

<div class="post-metadata">

**Author:** ![sebastianovide](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastianovide/32/13258_2.png) [@sebastianovide](https://discuss.circleci.com/u/sebastianovide)\
**Post date:** [April 10, 2018, 11:46am UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/6 "2018-04-10T11:46:49Z")

</div>

Thanks @FelicianoTech.

I’m reading the documentation and trying to understand it: Does it mean that filters branches are **OR** ed to filters tags ? [https://circleci.com/docs/2.0/configuration-reference/#filters-1](https://circleci.com/docs/2.0/configuration-reference/#filters-1) suggests that

> Any branches that match ignore will not run the job.

and it also suggests that adding a tags ignore: /.\*/ should ignore also pushes with empty tags.

> Any tags that match ignore will not run the job.

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [April 10, 2018, 4:45pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/7 "2018-04-10T16:45:05Z")

</div>

Git branches and tags are two different things. A tag commit doesn’t have a branch and a branch commit doesn’t have a tag. So the filters for both tags and branches in Workflows are completely separate from each other.

That being said, they have different defaults. By default, CircleCI will build **all** branch commits and by default CircleCI **won’t** build tag commits. You use filters when you need to change the default behavior.

---

<div class="post-metadata">

**Author:** ![sebastianovide](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastianovide/32/13258_2.png) [@sebastianovide](https://discuss.circleci.com/u/sebastianovide)\
**Post date:** [April 10, 2018, 8:26pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/8 "2018-04-10T20:26:37Z")

</div>

thanks.

Just for ref: I’ve just found another thread where it is discussed if it should be **OR** (as it is now) or **AND**. [Circle 2.0 Workflow Filters Should be logical AND not OR](https://discuss.circleci.com/t/circle-2-0-workflow-filters-should-be-logical-and-not-or/18231/8)

---

<div class="post-metadata">

**Author:** ![MikeBlair](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mikeblair/32/18167_2.png) [@MikeBlair](https://discuss.circleci.com/u/MikeBlair)\
**Post date:** [April 12, 2018, 10:32pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/9 "2018-04-12T22:32:28Z")

</div>

We’ve also run into this problem.

Pushing a tag and a commit at the same time is a very typical git workflow especially for anyone using NPM. When you run “npm version x.x.x” it will commit a change to package.json and create a git tag.

We’d like to setup our Circle config to build on every commit and do a build + npm deploy on every new tag. From my trials and these threads, it seems like there is no way to accomplish this without triggering a double build on the build + npm deploy step.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [July 11, 2018, 10:32pm UTC](https://discuss.circleci.com/t/i-have-two-workflows-with-opposite-filters-and-both-are-run-when-i-do-a-pull-request-i-would-expect-only-one-to-run/21320/10 "2018-07-11T22:32:35Z")

</div>

Closed on July 11, 2018, 10:32pm UTC

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