Branch ignore being ignored?

Our config looks like this:

version: 2.1
orbs:
  ruby: circleci/ruby@2.0.0
  heroku: circleci/heroku@0.0.8

jobs:
  build:
    docker:
      - image: cimg/ruby:2.7.6-node
        environment:
          RAILS_ENV: test
          RACK_ENV: test
          PG_USER: ubuntu
          PG_HOST: db
          DATABASE_URL: "postgres://ubuntu@db:5432/db_name"
          PAGER: cat
          ENABLE_SEGMENT: '1'
          ENABLE_SEND_EMAIL: '1'
          ENABLE_CREATE_TEST_ORDER: '12963,2162'
          ENABLE_DELAYED_JOB: '1'
      - image: postgres:12
        name: db
        environment:
          POSTGRES_USER: ubuntu
          POSTGRES_DB: db_name
          POSTGRES_HOST_AUTH_METHOD: trust
    executor: ruby/default
    steps:
      - run:
          name: Install dependencies
          command: sudo apt-get update && sudo apt-get install postgresql-client libmagickwand-dev
      - checkout
      - ruby/install-deps:
          # Share cache between branches
          # This speeds up runs in branches that don't touch Gemfile.lock,
          # because they don't need to reinstall the whole bundle.
          include-branch-in-cache-key: false
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://db:5432 -timeout 1m
      - run:
          name: Database creation
          command: bundle exec rake db:create db:test:load
      - ruby/rspec-test:
          include: spec/**/*_spec.rb
      - ruby/rubocop-check:
          format: progress
      - store_artifacts:
          path: ./log/test.log
      - store_artifacts:
          path: ./coverage
      - store_artifacts:
          path: reports

  staging_health_check:
    docker:
      - image: cimg/base:2021.04
    steps:
      - checkout
      - run:
          name: Staging Health Check
          command: ./scripts/health-check.sh

  deploy_staging:
    executor: heroku/default
    steps:
      - checkout
      - heroku/install
      - heroku/deploy-via-git:
          app-name: inspectify-dev

  deploy_prod:
    executor: heroku/default
    steps:
      - checkout
      - heroku/install
      - heroku/deploy-via-git:
          app-name: limitless-garden-75268

workflows:
  build:
    jobs:
      - build:
          filters:
            branches:
              ignore:
                # Sapling-SCM pushes branches to GitHub with the username: sapling-pr-archive-francois
                # This branch will never be merged, so we don't need to run specs against this branch anyway
                - /^sapling-pr-archive/
      - deploy_staging:
          filters:
            branches:
              only:
                - master
          requires:
            - build
      - staging_health_check:
          requires:
            - deploy_staging
      - deploy_prod:
          requires:
            - staging_health_check
            - deploy_staging

Using Sapling-SCM, it pushes branches whose names are sapling-pr-archive-$GH_USERNAME. I want to ignore those branches from consideration, always. I expected that the build step config above would do that, but sadly, that isn’t the case: CircleCI launches a pipeline to run against that branch.

Are we falling afoul of the warnings described in Branch-level job execution?

Workflows will ignore branches keys nested under jobs configuration, so if you use job-level branching and later add workflows, you must remove the branching at the job level and instead declare it in the workflows section […]

The examples below the section linked to above seem to imply we can do what we wrote above. What have we done wrong in our configuration?

Thanks a bunch!
François

Hello @francois,

CircleCI uses the Java variant of RegEx pattern matching (Using Workflows to Orchestrate Jobs - CircleCI).

So in your case, you need to specify the following RegEx pattern:

          filters:
            branches:
              ignore:
                - /^sapling-pr-archive.*/

Let me know if this helps.

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