【问题标题】:how do I trigger a workflow dispatch event with gh api with inputs如何使用带有输入的 gh api 触发工作流调度事件
【发布时间】:2022-12-03 05:37:51
【问题描述】:

所以现在我有:

gh api --method POST -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/workflows/30721645/dispatches -F run_id=${{ github.run_id }}

我的 workflow_dispatch 事件将 run_id 作为输入,但问题是我得到了这个请求的 invalid_key,我如何正确地将 run_id 传递给 gh api?

【问题讨论】:

  • 您可以使用一个动作为您执行此操作,请从市场上查看this one

标签: github-actions


【解决方案1】:

这有点棘手,因为您必须将 JSON 传递给 gh api,并且还需要传递 ref

这应该工作:

jq -n '{"ref":"main","inputs":{"run_id":"${{github.run_id}}"}}' | gh api -H "Accept: application/vnd.github+json" --method POST /repos/${{ github.repository }}/actions/workflows/30721645/dispatches --input -

【讨论】:

    【解决方案2】:

    如果您没有任何 inputs 传入并且只是运行工作流,您可以使用:

    gh api /repos/joshjohanning-org/bash-testing/actions/workflows # get id
    gh api -X POST /repos/joshjohanning-org/bash-testing/actions/workflows/19595110/dispatches -f ref='main'
    

    否则,如果你想要输入,你可以使用(类似于上面的@Grzegorz Krukowski):

    gh api -X POST /repos/joshjohanning-org/bash-testing/actions/workflows/19595110/dispatches 
      --input - <<< '{"ref":"main","inputs":{"message":"all"}}'
    

    或者使用gh workflow run

    gh workflow run -R joshjohanning-org/bash-testing blank.yml 
    echo '{"name":"scully", "greeting":"hello"}' | gh workflow run -R joshjohanning-org/bash-testing blank.yml --json
    

    【讨论】:

      猜你喜欢
      • 2023-01-31
      • 2021-05-30
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 2021-08-25
      相关资源
      最近更新 更多