[英]Invoke GitHub Actions workflow manually and pass parameters
我想传递一些动态参数并手动调用我的 GitHub 操作工作流(最好通过一些 API)。 这可能吗?
使用workflow_dispatch
事件触发器,您可以轻松地进行手动触发器。
流动:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
博文公告参考, https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
我认为对此的正确答案是使用repository_dispatch
而不是workflow_dispatch
。
只有存储库分派允许您从 API 调用触发工作流。
概括:
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"}}'
要通过 API 触发workflow_dispatch
,可在https://docs.github.com/dispatch-pro-create-a-lateflow/
POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
其中{workflow_id}
也可以是工作流的文件名(这使事情变得更容易)。
文档中的示例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.