使用 jobs.<job_id>.runs-on 定义要运行作业的计算机类型。
-
可基于分配给运行器的标签或其组成员身份或两者的组合,面向这些运行器。
-
可以提供以下形式的 runs-on:
- 单个字符串
- 包含字符串的单个变量
- 字符串数组、包含字符串的变量或两者的组合
- 使用
group 或 labels 键的 key: value 对
-
如果指定字符串数组,工作流将在与所有指定 runs-on 值匹配的运行器上执行。 例如,此处的作业将仅在具有标签 linux、x64 和 gpu 的自托管运行器上运行:
runs-on: [self-hosted, linux, x64, gpu]
有关详细信息,请参阅“选择自托管运行程序”。
-
可以在数组中混合使用字符串和变量。 例如:
on:
workflow_dispatch:
inputs:
chosen-os:
required: true
type: choice
options:
- Ubuntu
- macOS
jobs:
test:
runs-on: [self-hosted, "${{ inputs.chosen-os }}"]
steps:
- run: echo Hello world!
-
如果要在多台计算机上运行工作流,请使用 jobs.<job_id>.strategy。
注意
像 self-hosted 这样的简单字符串前后不需要引号,但 "${{ inputs.chosen-os }}"
等表达式前后需要引号。
如果使用 GitHub 托管的运行器,每个作业将在 runs-on 指定的运行器映像的新实例中运行。
使用 GitHub 托管的运行器时,运行时的值是运行器标签或运行器组名称。 标准 GitHub 托管的运行器的标签如下表所示。
有关详细信息,请参阅“GitHub 托管的运行程序”。
对于公共存储库,使用下表中显示的工作流标签的作业将与关联的规范一起运行。 除单 CPU 运行器外,每个 GitHub 托管的运行器都是由 GitHub 托管的新虚拟机(VM)。 单 CPU 运行器托管在共享 VM 上的容器中;请参阅GitHub 托管的运行器参考。 公共存储库上标准 GitHub 托管运行器的使用是免费且无限制的。
|
虚拟机/容器 |
处理器 (CPU) |
内存 (RAM) |
存储 (SSD) |
体系结构 |
工作流标签 |
| Linux |
1 |
5 GB |
14 GB |
x64 |
ubuntu-slim
|
| Linux |
4 |
16 GB |
14 GB |
X64 |
<code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md">ubuntu-latest</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md">ubuntu-24.04</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md">ubuntu-22.04</a></code></td>
</tr>
<tr>
<td>Windows</td>
<td>4</td>
<td>16 GB</td>
<td>14 GB</td>
<td> X64 </td>
<td>
<code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md">windows-latest</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md">windows-2025</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md">windows-2022</a></code></td>
</tr>
<tr>
<td>Linux</td>
<td>4</td>
<td>16 GB</td>
<td>14 GB</td>
<td> arm64 </td>
<td>
<code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-ubuntu-24-image.md">ubuntu-24.04-arm</a></code>, <code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-ubuntu-22-image.md">ubuntu-22.04-arm</a></code></td>
</tr>
<tr>
<td>Windows</td>
<td>4</td>
<td>16 GB</td>
<td>14 GB</td>
<td>arm64</td>
<td>
<code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-windows-11-image.md">windows-11-arm</a></code>
</td>
</tr>
<tr>
<td>macOS</td>
<td>4</td>
<td>14 GB</td>
<td>14 GB</td>
<td> Intel </td>
<td>
<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md">macos-13</a></code>, <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md">macos-15-intel</a></code></td>
</tr>
<tr>
<td>macOS</td>
<td>3 (M1)</td>
<td>7 GB</td>
<td>14 GB</td>
<td> arm64 </td>
<td> <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md">macos-latest</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md">macos-14</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md">macos-15</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md">macos-26</a></code> (公共预览版) </td>
</tr>
|
对于内部和专用存储库,使用下表中所示工作流标签的作业将在具有相关规格的虚拟机上运行。 这些运行程序使用 GitHub 帐户分配的免费分钟数,然后按每分钟费率收费。 请参阅“Actions 运行程序定价”。
| 虚拟机 |
处理器 (CPU) |
内存 (RAM) |
存储 (SSD) |
体系结构 |
工作流标签 |
| Linux |
1 |
5 GB |
14 GB |
x64 |
ubuntu-slim
|
| Linux |
2 |
8 GB |
14 GB |
X64 |
<code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md">ubuntu-latest</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md">ubuntu-24.04</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md">ubuntu-22.04</a></code></td>
</tr>
<tr>
<td>Windows</td>
<td>2</td>
<td>8 GB</td>
<td>14 GB</td>
<td> X64 </td>
<td>
<code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md">windows-latest</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md">windows-2025</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md">windows-2022</a></code></td>
</tr>
<tr>
<td>Linux</td>
<td>2</td>
<td>8 GB</td>
<td>14 GB</td>
<td> arm64 </td>
<td>
<code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-ubuntu-24-image.md">ubuntu-24.04-arm</a></code>, <code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-ubuntu-22-image.md">ubuntu-22.04-arm</a></code></td>
</tr>
<tr>
<td>Windows</td>
<td>2</td>
<td>8 GB</td>
<td>14 GB</td>
<td> arm64 </td>
<td>
<code><a href="https://github.com/actions/partner-runner-images/blob/main/images/arm-windows-11-image.md">windows-11-arm</a></code>
</td>
</tr>
<tr>
<td>macOS</td>
<td>4</td>
<td>14 GB</td>
<td>14 GB</td>
<td> Intel </td>
<td>
<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md">macos-13</a></code>, <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md">macos-15-intel</a></code></td>
</tr>
<tr>
<td>macOS</td>
<td>3 (M1)</td>
<td>7 GB</td>
<td>14 GB</td>
<td> arm64 </td>
<td> <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md">macos-latest</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md">macos-14</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md">macos-15</a></code>、<code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md">macos-26</a></code> (公共预览版) </td>
</tr>
|
注意
macOS 运行程序在 GHE.com 的子域(例如 octocorp.ghe.com)上不可用。
除了标准 GitHub 托管的运行器之外,GitHub 还在 GitHub Team 和 GitHub Enterprise Cloud 计划中为客户提供一系列具有更多高级功能的托管虚拟机,如更多核心和磁盘空间、GPU 支持的计算机以及 ARM 支持的计算机。 有关详细信息,请参阅“大型运行器”。
注意
-latest 运行器映像是 GitHub 提供的最新稳定映像,但可能不是操作系统供应商提供的最新版本的操作系统。
警告
Beta 版映像和已弃用的映像“按原样”、“含全部错误”和“按可用性”提供,不包含在服务级别协议和保证之内。 客户支持可能不会涵盖 Beta 版映像。
runs-on: ubuntu-latest
有关详细信息,请参阅“GitHub 托管的运行程序”。
要为作业指定自托管运行器,请在工作流文件中使用自托管运行器标签配置 runs-on。
自托管运行器可能具有 self-hosted 标签。 设置自托管运行器时,默认情况下,我们将包含标签 self-hosted。 可以传递 --no-default-labels 标志以防止应用自托管标签。 标签可用于为运行器创建目标选项(例如,操作系统或体系结构),建议提供以 self-hosted 开头的标签数组(必须首先列出),然后根据需要包含其他标签。 指定标签数组时,作业将在具有你指定的所有标签的运行器上排队。
请注意,Actions Runner Controller 不支持多个标签,并且不支持 self-hosted 标签。
runs-on: [self-hosted, linux]
有关详细信息,请参阅 自托管运行程序 和 在工作流中使用自托管运行程序。
可以使用 runs-on 定位运行器组,以便作业将在属于该组的任何运行器上执行。 若要进行更精细的控制,还可以将运行器组与标签组合在一起。
运行器组只能将 大型运行器 或自托管运行器作为成员。
在此示例中,Ubuntu 运行器已添加到名为 ubuntu-runners 的组中。 runs-on 键将作业发送到 ubuntu-runners 组中的任何可用运行器:
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on:
group: ubuntu-runners
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
组合组和标签时,运行器必须满足这两项要求才能运行作业。
在此示例中,名为 ubuntu-runners 的运行器组使用 Ubuntu 运行器(分配了标签 ubuntu-20.04-16core)进行填充。 runs-on 键将 group 和 labels 组合在一起,以便将作业路由到具有匹配标签的组内的任何可用运行器:
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on:
group: ubuntu-runners
labels: ubuntu-20.04-16core
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
例如,如果组织中有一个名为 my-group 的运行器组,企业中有另一个名为 my-group 的运行器组,则可以更新工作流文件以使用 org/my-group 或 ent/my-group 来区分这两者。
使用 org/:
runs-on:
group: org/my-group
labels: [ self-hosted, label-1 ]
使用 ent/:
runs-on:
group: ent/my-group
labels: [ self-hosted, label-1 ]