[英]Invoke GitHub Actions workflow manually and pass parameters
I want to pass some dynamic parameters and invoke my GitHub Actions workflow manually (ideally via some API).我想传递一些动态参数并手动调用我的 GitHub 操作工作流(最好通过一些 API)。 Is this possible?
这可能吗?
With the workflow_dispatch
event trigger , you can do the manual triggers easily.使用
workflow_dispatch
事件触发器,您可以轻松地进行手动触发器。
Flow:流动:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
Manual trigger screenshot:手动触发截图:
Blog post announcement reference, https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/博文公告参考, 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
.我认为对此的正确答案是使用
repository_dispatch
而不是workflow_dispatch
。
Only repository dispatch allows you to trigger a workflow from an API call.只有存储库分派允许您从 API 调用触发工作流。
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要通过 API 触发
workflow_dispatch
,可在https://docs.github.com/dispatch-pro-create-a-lateflow/
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).其中
{workflow_id}
也可以是工作流的文件名(这使事情变得更容易)。
An example curl
from the documentation:文档中的示例
curl
:
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"}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.