如何获取 GitHub Actions Runner 令牌

7

我想创建一个虚拟机并在我的工作流中设置为自托管运行程序。目前,阻止我的是缺少提供运行程序令牌的API。如果有这个API,我就可以创建实例并注册它作为运行程序,以便在下一个作业中使用它。

有人知道获取运行程序令牌的解决方法吗?

2个回答

8

最新消息

看起来他们终于创建了Runner API。可以在这里查看API规范

[POST] /repos/{owner}/{repo}/actions/runners/registration-token

他们现在也有关于如何做这个的示例片段。查看此处发布的另一个答案以获取完整示例。

之前的回答

目前,您必须根据这里的指南手动创建实例。

根据GitHub员工的说法,计划最终添加一个API以生成运行程序令牌,但未透露何时可能发生这种情况。

此功能将在路线图上。目前我没有时间表可分享。但是当此功能可用时,我们将发布到更改日志

为了消除有关PAT /运行程序令牌的混淆。通过UI提供的运行程序令牌是一个临时令牌,在60分钟后过期。它只能注册运行程序。

PAT无法注册运行程序。


5
创建注册令牌的API已经可用:
  • 在这里,您可以了解如何为存储库级别创建一个注册令牌
  • 以及在这里 - 为组织级别
使用以下JavaScript代码,您可以在GitHub操作中创建GitHub注册令牌:
const core = require('@actions/core');
const github = require('@actions/github');

async function getRegistrationToken() {
  const githubToken = core.getInput('github_token'); // the GitHub Secret Token provided as an input of your GitHub Action using ${{ secrets.GITHUB_TOKEN }}
  const octokit = github.getOctokit(githubToken);

  const response = await octokit.request('POST /repos/{owner}/{repo}/actions/runners/registration-token', {
    owner: github.context.repo.owner, // the value is taken from the environment variable GITHUB_REPOSITORY which is provided by the GitHub Action during runtime
    repo: github.context.repo.repo, // the value is taken from the environment variable GITHUB_REPOSITORY which is provided by the GitHub Action during runtime
  });

  return response.data.token;
}

module.exports = {
  getRegistrationToken,
};


1
顺便说一下:如果你感兴趣的话,我正在开发一个 GitHub Action,用于创建按需 AWS EC2 实例并将其注册为自托管的 GitHub Actions runner。它仍在进行中,但很快就会准备好:https://github.com/machulav/aws-github-runner。所以请随意关注。 - Volodymyr Machula

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接