I want to pass some dynamic parameters and invoke my GitHub Actions workflow manually (ideally via some API). Is this possible?
3 Answers
With the workflow_dispatch
event trigger, you can do the manual triggers easily.
Flow:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
Blog post announcement reference, https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
-
1
-
-
2I have some example in here, github.com/chenrui333/github-action-test/blob/master/.github/…– chenruiCommented Jul 9, 2020 at 14:01
-
5Access / use manual parameters like:
${{ github.event.inputs.logLevel }}
- since links sometimes get stale copied from first link in answer. Commented Nov 24, 2020 at 23:44 -
1Full documentation: docs.github.com/en/actions/using-workflows/… Workflows can be triggered with
gh
CLI:gh workflow run run-tests.yml -f logLevel=warning -f tags=false
– jakub.gCommented May 5, 2023 at 9:15
I think the correct answer to this is using a repository_dispatch
NOT a workflow_dispatch
.
Only repository dispatch allows you to trigger a workflow from an API call.
Summary:
- URL Endpoint:
https://api.github.com/repos/{owner}/{repo}/dispatches
- Example cURL call:
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer <token>" https://api.github.com/repos/{owner}/{repo}/dispatches -d '{"event_type": "type1","client_payload": {"key1": "Hello from CRUD"}}'
-
3Wish I could upvote more than once. This is the only answer which specified that I can send "inputs" by sending "client_payload". Even the docs don't say that. Docs I'm referring to: docs.github.com/en/rest/reference/… Thank you Commented Mar 3, 2021 at 22:20
-
Doesn't the answer below show how
workflow_dispatch
can be triggered from the API? Commented Mar 24, 2023 at 15:40
To trigger a workflow_dispatch
via API, the documentation can be found at https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event
POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
where {workflow_id}
can also be the filename of the workflow (which makes things a lot easier).
An example curl
from the documentation:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/actions/workflows/42/dispatches \
-d '{"ref":"ref"}'
-
1Also possible via
gh
CLI:gh workflow run workflow-name.yml -f param1=value1 -f param2=value2
– jakub.gCommented May 5, 2023 at 9:17 -
2Is there a way to create a clickable hyperlink that will dispatch a workflow? Meaning is there a way to do it from a GET without a body? Commented Jun 19, 2023 at 18:49