# Branches filter doesn't work, job always run?

**URL:** <https://discuss.circleci.com/t/branches-filter-doesnt-work-job-always-run/30118>\
**Category:** Build Environment\
**Tags:** 2.0, workflow, circle-yml\
**Created:** [May 1, 2019, 9:29am UTC](https://discuss.circleci.com/t/branches-filter-doesnt-work-job-always-run/30118 "2019-05-01T09:29:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matanshukry](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@matanshukry](https://discuss.circleci.com/u/matanshukry)\
**Post date:** [May 1, 2019, 9:29am UTC](https://discuss.circleci.com/t/branches-filter-doesnt-work-job-always-run/30118/1 "2019-05-01T09:29:52Z")

</div>

We have the following config .yaml file, which includes a filter for master branch only.  
However, this seems to also run on every pull request, even one made to develop and doesn’t include master at all.

```
File:
version: 2.1
jobs:
  test:
    docker:
    - image: cirrusci/flutter
    steps:
      - checkout
      - run: ./ci/test.sh
      - run: flutter doctor
      - run: flutter test
  publish:
    docker:
      - image: cirrusci/flutter
    working_directory: ~/msh
    environment:
      GRADLE_OPTS: -Dorg.gradle.daemon=false
    steps:
      - checkout:
          post:
            cp android/local.properties.ci android/local.properties
      - run:
          name: Install fastlane
          command: cd android && bundle install
      - run:
          name: Store the google play key
          command: echo $ANDROID_SVC_ACC > ~/secret.json
      - run:
          name: Init fastlane supply
          command: cd android && bundle exec fastlane supply init
      - run:
          name: create key file
          command: ./ci/create_jks.sh
      - run:
          name: Create bundle
          command: flutter build appbundle --release
      - run:
          name: Publish to store
          command: cd android && bundle exec fastlane android deploy

workflows:
  version: 2

  test_and_publish:
    jobs:
      - test
      - publish:
        filters:
          branches:
            only:
            - master
```

---

<div class="post-metadata">

**Author:** ![carlosvin](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/carlosvin/32/22290_2.png) [@carlosvin](https://discuss.circleci.com/u/carlosvin)\
**Post date:** [May 10, 2019, 3:28pm UTC](https://discuss.circleci.com/t/branches-filter-doesnt-work-job-always-run/30118/2 "2019-05-10T15:28:57Z")

</div>

Same issue here. We’d like to build only master, but gh-pages branch if built after master succeed.  
[![CircleCI](https://global.discourse-cdn.com/circleci/original/3X/7/1/7157530e0110d2e00794e9199db8e5949c880b99.svg)](https://circleci.com/gh/carlosvin/budget-tracker/tree/gh-pages) gh-pages

Following the configuration file:

```
version: 2
jobs:
  build:
    docker:
      - image: circleci/node:lts
    branches:
      only:
        - master
    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run: yarn lint
      - run: yarn test
      - run: yarn clean
      - run: yarn build
      - run: git config --global user.email $GH_EMAIL
      - run: git config --global user.name "$GH_NAME"
      - run: yarn deploy-gh
```

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [May 11, 2019, 10:35am UTC](https://discuss.circleci.com/t/branches-filter-doesnt-work-job-always-run/30118/3 "2019-05-11T10:35:15Z")

</div>

@matanshukry: I wonder if it would be worth trying the [regex form of the filter](https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag)?

@carlosvin: your filter is on the job, and not in a workflow. I seem to recall there are some filtering problems with that. Try moving the filter to a workflow, and then maybe try what I’ve suggested above.
