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


#1

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

#2

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


#4

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.


#5

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