Manually trigger path-filtered workflow

When using the path filtering orb to run workflows, I’m looking for a better method of manually triggering a workflow. As an example, let’s say I have this setup:

version: 2.1
setup: true
orbs:
  path-filtering: circleci/path-filtering@0.1.1
workflows:
  setup:
    jobs:
      - path-filtering/filter:
          base-revision: main
          config-path: .circleci/workflows.yml
          mapping: |
            dir_a/.* run-workflow-a true
            dir_b/.* run-workflow-b true

Let’s say the last 10 commits to the main branch have been for dir_a. How can I trigger a build for dir_b (workflow-b)? The two ways I know are to:

  • click “rebuild” on the most recent commit where there was a change in dir_b, 11 commits ago.
  • push a fake change (a blank file or whatever) under dir_b to the main branch to trigger workflow-b.

Thanks in advance.

Hi @dale.francum,

Thank you for sharing your question on our forum!

When wanting to manually trigger a setup workflow via the API or the “trigger pipeline” button on the dashboard, you will need to add additional pipeline parameters to pass in.

I was not able to get a good working example using just the path-filtering/filter job, but I was able to get it to work by using the underlying continuation/continue job from the continuation orb. Here are the two sample .yml files:

config.yml


version: 2.1
setup: true
orbs:
  path-filtering: circleci/path-filtering@0.1.1
  continuation: circleci/continuation@0.2.0
  
parameters:
  manual-workflow-a:
    type: boolean
    default: false 
  manual-workflow-b:
    type: boolean
    default: false
    
workflows:
  setup:
    unless:
      or: [<< pipeline.parameters.manual-workflow-a >>, << pipeline.parameters.manual-workflow-a >>]
    jobs:
      - path-filtering/filter:
          base-revision: << pipeline.git.branch >>
          config-path: .circleci/workflows.yml
          mapping: |
            dir_a/.* run-workflow-a true
            dir_b/.* run-workflow-b true
  setup-manual:
    when: 
      or: [<< pipeline.parameters.manual-workflow-a >>, << pipeline.parameters.manual-workflow-a >>]
    jobs:
      - continuation/continue:
          configuration_path: .circleci/workflows.yml
          parameters: /tmp/pipeline-parameters.json
          pre-steps:
            - run:
                command: |
                  echo '{ "run-workflow-a": << pipeline.parameters.manual-workflow-a >>, "run-workflow-b": << pipeline.parameters.manual-workflow-b >> }' >> /tmp/pipeline-parameters.json

workflows.yml (the continuation config)

version: 2.1

parameters:
  run-workflow-a:
    type: boolean
    default: false 
  run-workflow-b:
    type: boolean
    default: false
  manual-workflow-a:
    type: boolean
    default: false 
  manual-workflow-b:
    type: boolean
    default: false
    
jobs:
  buildjob:
    docker:
      - image: cimg/base:2022.01
    steps:
      - run: echo "test"

workflows:
  workflow-a:
    when: 
      or: [<< pipeline.parameters.run-workflow-a >>, << pipeline.parameters.manual-workflow-a >>]
    jobs:
      - buildjob
  workflow-b:
    when:
      or: [<< pipeline.parameters.run-workflow-b >>, << pipeline.parameters.manual-workflow-b >>]
    jobs:
      - buildjob

Essentially I added two pipeline parameters, one for each workflow you would like to manually execute.
When using the api or the trigger pipeline button, you can pass in true or false (default false) to fire one or multiple workflows.

The path filtering workflow will only run when neither manual-workflow-a nor manual-workflow-b is true.

If you would like further clarification on anything, please feel free to ask. I hope the above example can serve as a reference for your use case.

Best Regards

Thank you Aaron, this looks promising. I’ll give this a try with our workflows.

Dale

Confirming, this worked well. Thanks @aaronclark !

@dale.francum Glad to hear it worked!

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