gitlab - How to obtain the GitLab runner ID from the authentication_token?
问题描述
When I register a runner, I can list my runner details with:
# gitlab-runner list
Runtime platform arch=amd64 os=linux pid=103997 revision=7a6612da version=13.12.0
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
runner-myproject Executor=docker Token=xxx URL=https://gitlab.example.com
So I have the authentication_token in that response (also available in my config.toml). From that runner token, how can I determine the runner ID?
I would like a cron that checks if the runner is busy and if not, it deregisters the runner from the autoscaling group:
- Checks if the runner has active jobs
- Pause the runner if there are 0 active jobs (would probably ensure that it has been idle for a while).
- Deregister the runner from GitLab.
- Deregister the runner instance from the AWS autoscaling group.
However, the API only works with the runner ID and all I know about the runner is the Token.
解决方案
您可以从 API 获取此信息。
首先,您可以获得实例或特定项目(取决于您的要求)的所有运行器,如下所示:
# For the instance:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/runners/all"
# For a specific project id
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:project_id:/runners"
结果将类似于:
[
{
"active": true,
"description": "test-2-20150125",
"id": 8,
"ip_address": "127.0.0.1",
"is_shared": false,
"runner_type": "project_type",
"name": null,
"online": false,
"status": "offline"
},
{
"active": true,
"description": "development_runner",
"id": 5,
"ip_address": "127.0.0.1",
"is_shared": true,
"runner_type": "instance_type",
"name": null,
"online": true,
"status": "paused"
}
]
然后,您可以遍历运行器,获取id
,并使用您已经找到的其他 API 调用为该运行器获取所有作业。
以下是有关此 API 的更多详细信息和选项的文档:
推荐阅读
- python - Python多处理:全局对象未正确复制给子对象
- design-patterns - 在聊天应用程序中使用 Docker
- assembly - 为什么这个汇编程序以无限循环结束?
- android - java.lang.RuntimeException 的错误:无法实例化活动 ComponentInfo KOTLIN/AndroidStudio
- file - '\n' 和 EOF 有什么区别?
- mongodb - 如何在 mongodb mongoose 中增加归档
- javascript - 如何使用 jquery 编辑和预览歌曲和弦
- json - OCaml:如何使用 Yojson 派生 JSON 记录,其中字段名称之一是 OCaml 关键字?
- javascript - 在一个类的 JavaScript 构造函数中,如果我的参数大部分或全部是默认的,我可以在它的创建中指定某个参数吗?
- python - 比较2个数组的数量