Circleci run different jobs based on file

Hello,
I am trying to do the following workflow:
plan
check_if_certains_files_are_updated
if true:
Notify
Hold
Deploy
if false:
Notify
Deploy

I have tried path-filtering/filter to generate a new deploy pipeline if a change is detected but what happens is that the steps notify and hold still continue.

I have also tried to write my own script in check_if_certains_files_are_updated to check if the path was edited and update a temporary file which uses persist_to_workspace to pass it along a true or false to notify but I am unable to find a way to skip the hold job since that would require using when parameters that require the circleci api to trigger a new job.

Is there a way to accomplish this goal without creating an new pipeline or using the the cirleci api to generate these two different flows?

1 Like

Path filtering orb should do it, but it will have to use dynamic pipelines. I would make sure you have “setup workflows” etc. turned on, which is a big cause of it not working. Look at the docs here for more info.

So basically you’d have your top level parameters and your file filters in, your main .circleci/config.yml and then have a separate workflow (e.g., .circleci/workflows.yml) for continuation workflow.

So simplified example:

in config.yml

version: 2.1

setup: true

orbs:
  path-filtering: circleci/path-filtering@1.0.0

parameters:
  trigger-foo:
    type: boolean
    default: false

workflows:
  version: 2
  setup_workflow:
    jobs:
      - path-filtering/filter:
          base-revision: main
          config-path: .circleci/workflows.yml
          mapping: |
            some-directory/.* trigger-foo true

in workflows.yml you’d then make some of your steps conditional on whether trigger-foo (or whatever parameter(s) you use) are true or false. So in your case, you could have a when or unless type condition on the hold step.

Thank you for your quick reply, I have tested this configuration and when the mapping is false it won’t trigger the workflows.yml file.

Right - you might have to make a default mapping as well. For example,
trigger-all with a default of true. I don’t think you’d even need a glob pattern for it, though I could be wrong.