Selecting a workflow to run using pipeline parameters
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:
machine: true
steps:
- checkout
- run: ./run-tests.sh
report:
machine: true
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 Worked Example.
Help make this document better
This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.
- Suggest an edit to this page (please read the contributing guide first).
- To report a problem in the documentation, or to submit feedback and comments, please open an issue on GitHub.
- CircleCI is always seeking ways to improve your experience with our platform. If you would like to share feedback, please join our research community.
Need support?
Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.
You can also visit our support site to find support articles, community forums, and training resources.
CircleCI Documentation by CircleCI is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.