使用 jobs.<job_id>.runs-on 定义要运行作业的计算机类型。
-
目标计算机可以是GitHub托管运行器、大型运行器,或自托管运行器。
-
你可以根据分配给运行器的标签、其所属组,或两者的组合来指定目标运行器。
-
您可以按以下方式提供 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 托管的运行器时,runs-on 的值可以是工作流标签或运行器组的名称。 下列表格显示了标准 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>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2604-Readme.md">ubuntu-26.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/Windows2025-VS2026-Readme.md">windows-2025-vs2026</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/runner-images/blob/main/images/ubuntu/Ubuntu2404-Arm64-Readme.md">ubuntu-24.04-arm</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Arm64-Readme.md">ubuntu-22.04-arm</a></code><code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2604-Arm64-Readme.md">ubuntu-26.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/runner-images/blob/main/images/windows/Windows11-Arm64-Readme.md">windows-11-arm</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows11-VS2026-Arm64-Readme.md">windows-11-vs2026-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-15-Readme.md">macos-15-intel</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-26-Readme.md">macos-26-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>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2604-Readme.md">ubuntu-26.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/runner-images/blob/main/images/ubuntu/Ubuntu2404-Arm64-Readme.md">ubuntu-24.04-arm</a></code>、、 <code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Arm64-Readme.md">ubuntu-22.04-arm</a></code><code><a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2604-Arm64-Readme.md">ubuntu-26.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/runner-images/blob/main/images/windows/Windows11-Arm64-Readme.md">windows-11-arm</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/windows/Windows11-Arm64-VS2026-Readme.md">windows-11-vs2026-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-15-Readme.md">macos-15-intel</a></code>、 <code><a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-26-Readme.md">macos-26-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 托管运行器外,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 定位运行器组,以便作业将在属于该组的任何运行器上执行。 若要进行更精细的控制,还可以将运行器组与标签组合在一起。
运行器组只能将 大型运行器 或自托管运行器作为成员。
在此示例中,运行器已添加到名为 build-runners 的组。
runs-on 键将作业发送到 build-runners 组中的任何可用运行器:
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on:
group: build-runners
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
组合组和标签时,运行器必须满足这两项要求才能运行作业。
在此示例中,runs-on 键结合了 group 和 labels,从而将该作业路由到组内任何具有匹配标签的可用运行器:
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on:
group: ubuntu-runners
labels: ubuntu-24.04-16core
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v