Selecting a workflow to run using pipeline parameters
On This Page
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.
If your project code is integrated with CircleCI via the GitHub App, GitLab or Bitbucket Data Center, you will need to use the new Trigger a new pipeline endpoint rather than the endpoint used in this example. |
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 } }'
To find your project slug, follow these steps:
|
Next steps
For more information on using API v2 endpoints, see the API Reference Documentation and the API Developers Guide end-to-end example.