Start Building for Free
CircleCI.comAcademyBlogCommunitySupport

Selecting a workflow to run using pipeline parameters

11 months ago1 min read
Cloud
Server v4.x
Server v3.x
On This Page
  • config.yml
  • Supply parameter with API
  • Next steps

You might find that you want to manually trigger a specific workflow to run using the API but still run a workflow on every push to your project. To achieve this, use pipeline parameters to decide which workflow(s) to run.

config.yml

The following example defaults to running the build workflow, but allows control of which other workflow to run using the API:

version: 2.1

parameters:
  action:
    type: enum
    enum: [build, report]
    default: build

jobs:
  build:
    docker:
      - image: cimg/base:2023.11
    steps:
      - checkout
      - run: ./run-tests.sh

  report:
    docker:
      - image: cimg/base:2023.11
    steps:
      - checkout
      - run: ./create-report.sh

workflows:
  build:
    when:
      equal: [ build, << pipeline.parameters.action >> ]
    jobs:
      - build

  report:
    when:
      equal: [ report, << pipeline.parameters.action >> ]
    jobs:
      - report

Supply parameter with API

The action parameter will default to build on pushes to the project. Below is an example of supplying a different value to action using the API v2 Trigger a New Pipeline endpoint to select a different workflow to run.

In this example, the workflow named report would run. Remember to substitute project-slug with your values.

curl -X POST https://circleci.com/api/v2/project/{project-slug}/pipeline \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Circle-Token: API_KEY" \
  -d '{ "parameters": { "action": report } }'

Next steps

For more information on using API v2 endpoints, see the API Reference Documentation and the API Developers Guide end-to-end example.


Suggest an edit to this page

Make a contribution
Learn how to contribute