如何使用自托管 GitHub Runner 运行 GitHub Actions 工作流?
有时候github action 提供的runner不能满足我们的一些需求,此时我们可以使用自托管runner来运行github action jobs, 设置步骤如下.
✅ 步骤一:在服务器部署自托管 runner
- 进入你的 GitHub 仓库(或组织)页面。
- 点击右上角 “Settings” → “Actions” → “Runners”。
- 选择 “New self-hosted runner”,根据你的操作系统下载对应的 runner。
- 按照 GitHub 提示进行配置和运行:
1 |
|
你也可以用 svc.sh install 注册为系统服务。
✅ 步骤二:在 Workflow 中使用自托管 runner
在 .github/workflows/xxx.yml
中,将 job 的 runs-on
设置为 self-hosted
并加上自定义标签:
1 |
|
✅ 可选:多个中国节点时做区域调度
如果你有多个节点,可以给每个 runner 加上不同的标签(如 tag-a
、tag-b
),并通过 GitHub Actions 的 matrix
或 if
做条件调度。
如何使用自托管 GitHub Runner 运行 GitHub Actions 工作流?