Branch filter is not working

Hello,

I have a really annoying issue with my config file, in my project config it’s set to only run on pull requests, and I would also like to restrict it so that it will only run on release branches.
In the end, CI should only run on pull requests with the base branch being release/*, no matter the target.

I have the following config and for some reason, the CI is running on every push of every branch that has a pull request attached/open.

defaults: &defaults
  working_directory: ~/project
  docker:
    - image: philipssoftware/node:15-java

version: 2
jobs:
  build:
    <<: *defaults
    filters:
      branches:
        only: /^release\/.*/
    steps:
      - checkout
      - restore_cache:
.....

Answering my own question, thanks to Nick Bialostosky from CircleCI support I was able to fix this. If anyone encounters the same issue here is his recommendation :

As for the current issue you are encountering, I actually think it may be from passing the filters key in. Since you are using version 2 and applying the branch filter at the job level it will need to be formatted like this:

https://circleci.com/docs/2.0/configuration-reference/#branches--deprecated

Alternatively, you can opt to move to 2.1 and use the filter at the workflow level:

https://circleci.com/docs/2.0/configuration-reference/#filters

Can you try this instead and see if it works for you:

defaults: &defaults
  working_directory: ~/project
  docker:
    - image: philipssoftware/node:15-java

version: 2
jobs:
  build:
    <<: *defaults
    branches:
      only:
        - /^release\/.*/
    steps:
      - checkout

I did a quick test myself and it seemed to work!

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