# Circleci run different jobs based on file

**URL:** <https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925>\
**Category:** Build Environment\
**Tags:** circle-yml\
**Created:** [August 11, 2023, 9:53pm UTC](https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925 "2023-08-11T21:53:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmalikunlearn](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/hmalikunlearn/32/33568_2.png) [@hmalikunlearn](https://discuss.circleci.com/u/hmalikunlearn)\
**Post date:** [August 11, 2023, 9:53pm UTC](https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925/1 "2023-08-11T21:53:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [August 11, 2023, 10:10pm UTC](https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925/2 "2023-08-11T22:10:53Z")

</div>

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](https://github.com/CircleCI-Public/api-preview-docs/blob/master/docs/setup-workflows.md#concepts) 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`

```yaml
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.

---

<div class="post-metadata">

**Author:** ![hmalikunlearn](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/hmalikunlearn/32/33568_2.png) [@hmalikunlearn](https://discuss.circleci.com/u/hmalikunlearn)\
**Post date:** [August 11, 2023, 10:51pm UTC](https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925/3 "2023-08-11T22:51:53Z")

</div>

> [@wyardley](#):
>
> `some-directory/.* trigger-foo true`

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.

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [August 14, 2023, 11:22pm UTC](https://discuss.circleci.com/t/circleci-run-different-jobs-based-on-file/48925/4 "2023-08-14T23:22:59Z")

</div>

> [@hmalikunlearn](#):
>
> 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.
