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

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:

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?

Sorry for any confusion here, but a workflow configuration 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.

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.

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.

  mobile:
    jobs:
      - run-android:
          filters:
            branches:
              only: build
      - run-ios:
          filters:
            branches:
              only: build
2 Likes

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.

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.

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