[英]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.