如何使用 gh cli 通过调度触发 github 操作

时间:2021-03-01 04:19:44

标签: github github-api github-actions

我有一个包含以下 yaml 的操作:

on:
  workflow_dispatch:
    inputs:
      BuildTarget:
        description: "Targets to rebuild. Set to all to rebuild everything."
        required: false
        default: ""

我可以用什么触发:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch"

但我似乎无法弄清楚如何将输入从 cli 传递到操作中。

我试过了:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch" -F BuildTarget=all

告诉"BuildTarget" is not a permitted key. (HTTP 422)

并尝试这个:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch" -F inputs='{ "BuildTarget": "all" }'

给我For 'properties/inputs', "{ \"BuildTarget\": \"all\" }" is not an object. (HTTP 422)

知道如何从 cli 调用此 api 并将输入属性传递给工作流吗?

1 个答案:

答案 0 :(得分:1)

您可以使用 --input - 直接发送原始正文以从标准输入中读取:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches \
   --input - <<< '{"ref":"master","inputs":{"BuildTarget":"all"}}'

结帐this documentation