# First-level jobs in a every workflow always run regardless of filters

**URL:** <https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865>\
**Category:** Build Environment\
**Tags:** workflow, workflows\
**Created:** [October 11, 2019, 6:09pm UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865 "2019-10-11T18:09:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![muhammed-sayadi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/muhammed-sayadi/32/25357_2.png) [@muhammed-sayadi](https://discuss.circleci.com/u/muhammed-sayadi)\
**Post date:** [October 11, 2019, 6:09pm UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/1 "2019-10-11T18:09:13Z")

</div>

I have a Unity project which could have one of three “workflows”:

`mobile`: Should build the app for both Android and iOS  
`content`: Should build the same app with a different “start scene” (Unity jargon) for testers for Android only  
`web`: Should build the app for, well, web.

My goal is to re-use the android jobs in the `mobile` workflow for the `content` workflow since the build process is pretty much the same (with some exceptions that can be easily changed based on environment variables that differ per-branch) and have the `web` workflow with its separate jobs.

The way I thought this would work (but isn’t) is to have every job in the `mobile` workflow only execute on the `build` branch. Similarly, every job in the `content` workflow execute only on the `build-content` branch. The same goes for the `web` workflow with the `build-web` branch.

What’s actually happening is that the first job in every workflow always runs. For example, when pushing to the `build-web` branch, the following jobs are running:

`run-web` -\> `test-web` -\> `upload-web` in the `web` workflow (as desired),  
`run-android` and `run-ios` only in the `mobile` workflow (unexpected), and  
`run-android` only in the `content` workflow (unexpected).

Here’s how the workflow section of my `config.yml` looks like:

```auto
version: 2.1

executors:
  # omitted for brevity

jobs:
  run-android:
    executor: docker-executor

    steps:
      - checkout
      # the rest of the steps are omitted for brevity in every job
  
  test-android:
    executor: docker-executor

    steps:
      - checkout

  upload-android:
    executor: docker-executor

    steps:
      - checkout

  run-ios:
    executor: macos-executor

    steps:
      - checkout

  test-ios:
    executor: docker-executor

    steps:
      - checkout

  upload-ios:
    executor: docker-executor

    steps:
      - checkout

  run-web:
    executor: docker-executor

    steps:
      - checkout

  test-web:
    executor: docker-executor

    steps:
      - checkout

  upload-web:
    executor: docker-executor

    steps:
      - checkout

workflows:
  version: 2

  mobile:
    jobs:
      - run-android:
        filters:
          branches:
            only: build
      - run-ios:
        filters:
          branches:
            only: build
      - test-android:
          filters:
            branches:
              only: build
          requires:
            - run-android
      - test-ios:
          filters:
            branches:
              only: build
          requires:
            - run-ios
      - upload-android:
          filters:
            branches:
              only: build
          requires:
            - test-android
            - test-ios
  # - upload-ios:
  # filters:
  # branches:
  # only: build
  # requires:
  # - test-android
  # - test-ios

  content:
    jobs:
      - run-android:
        filters:
          branches:
            only: build-content
      - test-android:
          filters:
            branches:
              only: build-content
          requires:
            - run-android
      - upload-android:
          filters:
            branches:
              only: build-content
          requires:
            - test-android

  web:
    jobs:
      - run-web:
          filters:
            branches:
              only: build-web
      - test-web:
          filters:
            branches:
              only: build-web
          requires:
            - run-web
      - upload-web:
          filters:
            branches:
              only: build-web
          requires:
            - test-web

```

Am I doing something wrong, or is this a bug?

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [October 13, 2019, 5:01pm UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/2 "2019-10-13T17:01:05Z")

</div>

> [@muhammed-sayadi](#):
>
> Here’s how the workflow section of my `config.yml` looks like:

Sorry for any confusion here, but a [workflow configuration](https://circleci.com/docs/2.0/workflows/#workflows-configuration-examples) should have a top level key called `workflows`, did you omit this in your snippet? If it does not exist, then it would explain the behavior that you are seeing.

---

<div class="post-metadata">

**Author:** ![muhammed-sayadi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/muhammed-sayadi/32/25357_2.png) [@muhammed-sayadi](https://discuss.circleci.com/u/muhammed-sayadi)\
**Post date:** [October 15, 2019, 9:05am UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/3 "2019-10-15T09:05:45Z")

</div>

Hi levlaz,

Thanks for your comment. The `workflows` keyword does exist both in the configuration and the snippet I posted. I do apologize, I’ve probably posted too much of the configuration.

> [@muhammed-sayadi](#):
>
> workflows: version: 2 mobile: jobs: - run-android:

---

<div class="post-metadata">

**Author:** ![gordon](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@gordon](https://discuss.circleci.com/u/gordon)\
**Post date:** [October 15, 2019, 2:29pm UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/4 "2019-10-15T14:29:19Z")

</div>

Hi there, the indentation of your workflows config is incorrect. `run-android` needs to be a key whose value is a map that can contain the `filters` key.

IOW, for those jobs the `filters` key needs to be indented one more level, e.g.

```auto
  mobile:
    jobs:
      - run-android:
          filters:
            branches:
              only: build
      - run-ios:
          filters:
            branches:
              only: build

```

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [October 17, 2019, 2:20am UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/5 "2019-10-17T02:20:41Z")

</div>

I am really sorry, I was not able to scroll to see your entire configuration for some reason. I am able to see it now.

---

<div class="post-metadata">

**Author:** ![muhammed-sayadi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/muhammed-sayadi/32/25357_2.png) [@muhammed-sayadi](https://discuss.circleci.com/u/muhammed-sayadi)\
**Post date:** [October 21, 2019, 8:45am UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/6 "2019-10-21T08:45:27Z")

</div>

You’re absolutely right!! Now that you mentioned it, I can’t unsee it. I can’t believe I missed this all the way to posting a question about it!

Thanks very much.

---

<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:** [October 31, 2019, 8:45am UTC](https://discuss.circleci.com/t/first-level-jobs-in-a-every-workflow-always-run-regardless-of-filters/32865/7 "2019-10-31T08:45:32Z")

</div>

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