Skip to content

Instantly share code, notes, and snippets.

@ryanpedersen42
Last active April 29, 2024 17:18
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ryanpedersen42/c867acd9b0837789a92836e8f5bd8b55 to your computer and use it in GitHub Desktop.
Save ryanpedersen42/c867acd9b0837789a92836e8f5bd8b55 to your computer and use it in GitHub Desktop.
Path filtering example
version: 2.1
setup: true
orbs:
path-filtering: circleci/path-filtering@0.0.2
workflows:
setup-workflow:
jobs:
- path-filtering/filter:
base-revision: main
config-path: .circleci/continue-config.yml
mapping: |
project1/.* project-one true
project2/.* project-two true
project3/.* project-three true
shared-things/.* run-them-all true
version: 2.1
executors:
base:
docker:
- image: cimg/base:stable
parameters:
project-one:
type: boolean
default: false
project-two:
type: boolean
default: false
project-three:
type: boolean
default: false
run-them-all:
type: boolean
default: false
jobs:
project_one:
executor: base
steps:
- run:
command: |
echo "project one"
project_two:
executor: base
steps:
- run:
command: |
echo "project two"
project_three:
executor: base
steps:
- run:
command: |
echo "project three"
all_projects:
executor: base
steps:
- run:
command: |
echo "all"
workflows:
build-1:
when:
or:
- << pipeline.parameters.project-one >>
- << pipeline.parameters.run-them-all >>
jobs:
- project_one
build-2:
when:
or:
- << pipeline.parameters.project-two >>
- << pipeline.parameters.run-them-all >>
jobs:
- project_two
build-3:
when:
or:
- << pipeline.parameters.project-three >>
- << pipeline.parameters.run-them-all >>
jobs:
- project_three
build-shared-other:
when: << pipeline.parameters.run-them-all >>
jobs:
- all_projects
@ipv1337
Copy link

ipv1337 commented Sep 19, 2022

Thanks for this super simple example!

@atishn
Copy link

atishn commented Sep 19, 2022

Thank god. So easy to read.

@mathaeus
Copy link

Life saver! :)

CircleCI should have such an example, I commented that over there

@xbeta
Copy link

xbeta commented Mar 4, 2023

Thanks!

Quick question, anyone knows how to use different branches with base-revision on this?

@ryanpedersen42

@Antman261
Copy link

what happens if i have two paths for one variable? will it set the variable if either path is modified? e.g.

            project1/.* project-one true 
            shared-things/.* project-one true

@jghiloni
Copy link

what happens if i have two paths for one variable? will it set the variable if either path is modified? e.g.

            project1/.* project-one true 
            shared-things/.* project-one true

Yes!

@snooky23
Copy link

Thanks!

Quick question, anyone knows how to use different branches with base-revision on this?

@ryanpedersen42

use base-revision for different actions based on branch.
you can only specify only one branch per job

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