I want to pass some dynamic parameters and invoke my GitHub Actions workflow manually (ideally via some API). Is this possible?
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/
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:
https://api.github.com/repos/{owner}/{repo}/dispatches
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"}}'
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"}'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.