我如何获得 github 动作运行器令牌
How I can get a github actions runner token
我想在我的工作流程中创建一个 VM 并设置为自托管运行器。现在,阻碍我的是缺少 API 来给我 Runner Token。如果存在,我可以创建实例并将其注册为运行器,以便能够在下一个作业中使用它。
现在有人有解决办法来获得跑步者令牌吗?
晚更新
Looks like they have finally created the runner api. See the API specs 这里
他们现在还 example snippets on how to do this. See the other 在此处发布了完整示例。
上一个答案
现在您必须使用找到的指南手动创建实例 here。
根据 github staff,有一个计划最终添加一个 api 来生成跑步者令牌,但没有透露何时可能发生的时间表。
An API for this is on the roadmap. I don't have a timeline to share at
the moment. But we'll be posting to the Changelog when this is
available.
And to clear up some of the confusion around PATs/runner tokens. The
runner token provided via the UI is a temporary token that expires
after 60 minutes. It only has the ability to register runners.
PATs are not able to register runners.
用于创建注册令牌的 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,
};
我想在我的工作流程中创建一个 VM 并设置为自托管运行器。现在,阻碍我的是缺少 API 来给我 Runner Token。如果存在,我可以创建实例并将其注册为运行器,以便能够在下一个作业中使用它。
现在有人有解决办法来获得跑步者令牌吗?
晚更新
Looks like they have finally created the runner api. See the API specs 这里
他们现在还 example snippets on how to do this. See the other
上一个答案
现在您必须使用找到的指南手动创建实例 here。
根据 github staff,有一个计划最终添加一个 api 来生成跑步者令牌,但没有透露何时可能发生的时间表。
An API for this is on the roadmap. I don't have a timeline to share at the moment. But we'll be posting to the Changelog when this is available.
And to clear up some of the confusion around PATs/runner tokens. The runner token provided via the UI is a temporary token that expires after 60 minutes. It only has the ability to register runners.
PATs are not able to register runners.
用于创建注册令牌的 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,
};