Skip to content

Instantly share code, notes, and snippets.

@emmahsax
Last active June 15, 2023 11:41
Show Gist options
  • Save emmahsax/c622b843cc1425ec4e4986796e6261ce to your computer and use it in GitHub Desktop.
Save emmahsax/c622b843cc1425ec4e4986796e6261ce to your computer and use it in GitHub Desktop.
CircleCI configuration to completely ignore a specific branch

CircleCI Configuration to Ignore a Branch

This file live in the .circleci/ directory of your project, named config.yml:

version: 2.1
jobs:
  skip:
    working_directory: ~/PROJECT_DIRECTORY # If we leave this out, the build will break with missing required arguments
    docker: [ image: circleci/ruby:2.6.5 ] # This doesn't really matter, but just choose any docker image
    steps: [ checkout ] # A simple step otherwise the build with break with syntax errors
workflows:
  version: 2
  BRANCH_TO_IGNORE:
    jobs:
      - skip:
          filters:
            branches:
              ignore: [ BRANCH_TO_IGNORE ]

The reason I used this file with my CircleCI config was so that the CI would run on each branch except master branch (since that's what GitHub Pages reads from).

By default, unless you have the pull-requests-and-default-branch-only setting turned on, which I don't, CircleCI will still try to run a build on every branch, even if there's no .circleci/config.yml present in the whole directory. This results in an erring build. So, I've added this .circleci/config.yml file so there's no error, and then set it to specifically ignore that whole branch. With this set up, CircleCI doesn't even create a build for the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment