Workflow 2.0 - Filter for branch is not applied when running build

Hello,

I have done integration of circleci with Github
My config file looks as shown below. I wanted to restrict the circleci to build only if there are checkin to specific branch. But its not working as stated in workflow 2.0 docs.
Please guide what is wrong in my config file.


version: 2
jobs:
  build:

    docker:
     - image: circleci/node:7.10

    steps:

      - run:
          command:
            export CF_USERNAME=$CF_USERNAME
            export CF_PASSWORD=$CF_PASSWORD
            export CF_API=$CF_API

      - checkout

      - restore_cache:
          key: dependency-cache-v2-{{ checksum "package.json" }}
      
      - run: npm install

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

      - run: npm run build

      - setup_remote_docker:
          docker_layer_caching: true

workflows:
  version: 2
  run-for-cicd:
     jobs:
       - build:
            filters:
              branches:
                only: dev-circleci

content of workflow from config file is not showing well formatted, but its all good in config file

Hello @kkmiral,

How is this currently working your you? I ran a test of your config simplified.

version: 2
jobs:
  build:
    docker:
     - image: circleci/node:7.10
    steps:
      - run: echo "test commit to master with build job."

workflows:
  version: 2
  run-for-cicd:
     jobs:
       - build:
            filters:
              branches:
                only: dev-circleci

This will only execute a commit if the branch matches what you have listed.

1 Like

Hello @KyleTryon,

Currently, if i check in to other branch, say “master” then also it triggers the build job in circleci

I want that build trigger to happen only if it matches the branch name

Hello. I would like to know if it is actually a bug and if so do you have an estimated date for the fix? In the company Im working we started migrating all our pipelines from Jenkins to CircleCi. But it feature is really necessary for us. We have the workflow branches filters in our config files but it is not working. Thanks.

Probably not - branch filtering has worked fine for me for the last couple of years. Do you have an example YAML file that is not working? If so, please post it here, using the formatting tools provided.

(If something is “not working” for you, the best kind of fault report is one that shows the problem - “me too” reports don’t help track problems down).

The issue we were facing was exaclty the same that was posted before. Didn’t make sense to say the same. We fixed it. It was some character that was causing the yaml file breaks. We recreate the yaml file and it worked. Thanks!

1 Like