Manually trigger path-filtered workflow

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

1 Like