簡體   English   中英

手動調用 GitHub Actions 工作流並傳遞參數

[英]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 調用觸發工作流。

文檔

手持示例

概括:

  • URL 端點:
https://api.github.com/repos/{owner}/{repo}/dispatches
  • 示例 cURL 調用:
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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM