【问题标题】:How to trigger github actions with dispatch using gh cli如何使用 gh cli 通过调度触发 github 操作
【发布时间】:2021-05-30 15:36:57
【问题描述】:

我有一个包含以下 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 并将输入属性传递给工作流的任何想法?

【问题讨论】:

    标签: github github-api github-actions


    【解决方案1】:

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

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

    结帐this documentation

    【讨论】:

    • 太棒了,谢谢你成功了 :)
    猜你喜欢
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2023-03-03
    • 2020-11-28
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多