【问题标题】:GitHub Actions: Must have admin rights to trigger workflow_dispatch?GitHub Actions:必须具有管理员权限才能触发 workflow_dispatch?
【发布时间】:2022-08-18 17:34:25
【问题描述】:

使用 github API,我尝试使用以下方法手动启动工作流:

  curl \\
  -X POST \\
  -H \"Accept: application/vnd.github+json\" \\ 
  -H \"Authorization: MY_TOKEN\" \\
  https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches 

但我不断收到身份验证错误:

{
  \"message\": \"Must have admin rights to Repository.\",
  \"documentation_url\": \"https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event\"
}

这似乎是与this question 类似的问题。但是我的 PAT 令牌选择了所有 adminrepo 范围。我还将我的用户帐户设置为存储库的admin,并且我已将工作流调度添加到工作流 yaml 文件中。

  workflow_dispatch:
    inputs:
      tags:
        description:
          \"run from cmdline\"

我一直在关注https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event 的文档,并且使用 API 检索所有以前的工作流作业没有任何问题。我也尝试了runsjobs 端点,但得到了同样的错误。所以我现在不确定我还能做什么。还有其他地方我需要设置权限吗?

谢谢

    标签: github github-actions github-api


    【解决方案1】:

    这是一条糟糕的错误消息,告诉您您的请求格式不正确。如果要将 PAT 作为标头传递,则需要在其前面加上 token 前缀,如 docs 中所述:

    -H "Authorization: token MY_TOKEN"

    但是,一旦解决了这个问题,您也会收到一个错误,因为您没有传递所需的ref 有效负载。假设你的默认分支是main,这是一个正确的 curl 命令:

    > export MY_TOKEN=gha_abcdef
    > curl \
      -X POST \
      -H "Accept: application/vnd.github+json" \ 
      -H "Authorization: token $MY_TOKEN" \
      https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches -d '{"ref": "main"}'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2022-06-10
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多