{"meta":{"title":"选择作业的运行器","intro":"定义将在工作流程中处理作业的计算机类型。","product":"GitHub Actions","breadcrumbs":[{"href":"/zh/actions","title":"GitHub Actions"},{"href":"/zh/actions/how-tos","title":"操作方法"},{"href":"/zh/actions/how-tos/write-workflows","title":"编写工作流"},{"href":"/zh/actions/how-tos/write-workflows/choose-where-workflows-run","title":"选择工作流运行位置"},{"href":"/zh/actions/how-tos/write-workflows/choose-where-workflows-run/choose-the-runner-for-a-job","title":"选择作业的运行器"}],"documentType":"article"},"body":"# 选择作业的运行器\n\n定义将在工作流程中处理作业的计算机类型。\n\n## 概述\n\n使用 `jobs.<job_id>.runs-on` 定义要运行作业的计算机类型。\n\n* 目标计算机可以是一个[GitHub托管运行器](#choosing-github-hosted-runners)、[大型运行器](#choosing-runners-in-a-group)，或是一个[自托管运行器](#choosing-self-hosted-runners)。\n\n* 你可以根据分配给运行器的标签、其组成员身份，或两者的组合来指定目标运行器。\n\n* 您可以按以下方式提供 `runs-on`：\n  * 单个字符串\n  * 包含字符串的单个变量\n  * 字符串数组、包含字符串的变量或两者的组合\n  * 使用 `key: value` 或 `group` 键的 `labels` 对\n\n* 如果指定字符串或变量数组，工作流将在任何与所有指定的 `runs-on` 值匹配的运行器上执行。 例如，此处的作业将仅在具有标签 `linux`、`x64` 和 `gpu` 的自托管运行器上运行：\n\n  ```yaml\n  runs-on: [self-hosted, linux, x64, gpu]\n  ```\n\n  有关详细信息，请参阅[选择自托管运行器](#choosing-self-hosted-runners)。\n\n* 可以在数组中混合使用字符串和变量。 例如：\n\n  ```yaml\n  on:\n    workflow_dispatch:\n      inputs:\n        chosen-os:\n          required: true\n          type: choice\n          options:\n          - Ubuntu\n          - macOS\n\n  jobs:\n    test:\n      runs-on: [self-hosted, \"${{ inputs.chosen-os }}\"]\n      steps:\n      - run: echo Hello world!\n  ```\n\n* 如果要在多台计算机上运行工作流，请使用 [`jobs.<job_id>.strategy`](/zh/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstrategy)。\n\n> \\[!NOTE]\n> 在简单字符串（如） `self-hosted`周围不需要引号，但表达式 `\"${{ inputs.chosen-os }}\"`需要引号。\n\n## 选择 GitHub 托管的运行器\n\n如果使用 GitHub托管运行程序，则每个作业在由 `runs-on`指定的运行程序映像的新实例中运行。\n\n当你使用 GitHub 托管运行器时，runs-on 的值可以是工作流标签或运行器组的名称。 下列表格显示了标准 GitHub 托管运行器的标签。\n\n有关详细信息，请参阅“[GitHub 托管的运行程序](/zh/actions/concepts/runners/github-hosted-runners)”。\n\n### 公共存储库的标准 GitHub 托管运行器\n\n对于公共存储库，使用下表中显示的工作流标签的作业将与关联的规范一起运行。\n除单 CPU 运行器外，每个 GitHub 托管的运行器都是由 GitHub 托管的新虚拟机（VM）。 单 CPU 运行器托管在共享 VM 上的容器中；请参阅[GitHub 托管的运行器参考](/zh/actions/reference/runners/github-hosted-runners#single-cpu-runners)。 使用标准 GitHub托管运行器在公共存储库上免费且不受限制。\n\n<table style=\"width:100%\">\n  <thead>\n    <tr>\n      <th scope=\"col\">\n<b>虚拟机/容器</b></th>\n      <th scope=\"col\">\n<b>处理器 (CPU)</b></th>\n      <th scope=\"col\">\n<b>内存 (RAM)</b></th>\n      <th scope=\"col\">\n<b>存储 (SSD)</b></th>\n      <th scope=\"col\">\n<b>建筑</b></th>\n      <th scope=\"col\">\n<b>工作流标签</b></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n          <td>Linux</td>\n          <td>1</td>\n          <td>5 GB</td>\n          <td>14 GB</td>\n          <td> x64 </td>\n          <td>\n            <code><a href=\"https://github.com/actions/runner-images/blob/main/images/ubuntu-slim/ubuntu-slim-Readme.md\">ubuntu-slim</a></code>\n          </td>\n        </tr>\n    <tr>\n      <td>Linux</td>\n      <td>4</td>\n      <td>16 GB</td>\n      <td>14 GB</td>\n      <td> X64 </td>\n      <td>\n\n```\n    <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>\n</tr>\n<tr>\n  <td>Windows</td>\n  <td>4</td>\n  <td>16 GB</td>\n  <td>14 GB</td>\n  <td> X64 </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>Linux</td>\n  <td>4</td>\n  <td>16 GB</td>\n  <td>14 GB</td>\n  <td> arm64 </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>Windows</td>\n  <td>4</td>\n  <td>16 GB</td>\n  <td>14 GB</td>\n  <td>arm64</td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>macOS</td>\n  <td>4</td>\n  <td>14 GB</td>\n  <td>14 GB</td>\n  <td> Intel </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>macOS</td>\n  <td>3 （M1）</td>\n  <td>7 GB</td>\n  <td>14 GB</td>\n  <td> arm64 </td>\n  <td>\n          \n    <code><a href=\"https://github.com/actions/runner-images/blob/main/images/macos/macos-26-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>、 <code><a href=\"https://github.com/actions/runner-images/blob/main/images/macos/xcode-27-arm64-Readme.md\">xcode-27</a></code> （公共预览） </td>\n</tr>\n```\n\n  </tbody>\n\n</table>\n\n### 标准 GitHub 托管运行器适用于专用存储库\n\n对于  专用存储库，使用下表中显示的工作流标签的作业将在具有关联规范的虚拟机上运行。 这些运行器会使用你的 GitHub 帐户中的免费分钟数，之后按每分钟费率收费。 请参阅“[Actions 运行程序定价](/zh/billing/reference/actions-runner-pricing)”。\n\n<table style=\"width:100%\">\n  <thead>\n    <tr>\n      <th scope=\"col\">\n<b>虚拟机</b></th>\n      <th scope=\"col\">\n<b>处理器 (CPU)</b></th>\n      <th scope=\"col\">\n<b>内存 (RAM)</b></th>\n      <th scope=\"col\">\n<b>存储 (SSD)</b></th>\n      <th scope=\"col\">\n<b>建筑</b></th>\n      <th scope=\"col\">\n<b>工作流标签</b></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n          <td>Linux</td>\n          <td>1</td>\n          <td>5 GB</td>\n          <td>14 GB</td>\n          <td> x64 </td>\n          <td>\n            <code><a href=\"https://github.com/actions/runner-images/blob/main/images/ubuntu-slim/ubuntu-slim-Readme.md\">ubuntu-slim</a></code>\n          </td>\n        </tr>\n    <tr>\n      <td>Linux</td>\n      <td>2</td>\n      <td>8 GB</td>\n      <td>14 GB</td>\n      <td> X64 </td>\n      <td>\n\n```\n    <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>\n</tr>\n<tr>\n  <td>Windows</td>\n  <td>2</td>\n  <td>8 GB</td>\n  <td>14 GB</td>\n  <td> X64 </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>Linux</td>\n  <td>2</td>\n  <td>8 GB</td>\n  <td>14 GB</td>\n  <td> arm64 </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>Windows</td>\n  <td>2</td>\n  <td>8 GB</td>\n  <td>14 GB</td>\n  <td> arm64 </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>macOS</td>\n  <td>4</td>\n  <td>14 GB</td>\n  <td>14 GB</td>\n  <td> Intel </td>\n  <td>\n          \n    <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>\n</tr>\n<tr>\n  <td>macOS</td>\n  <td>3 （M1）</td>\n  <td>7 GB</td>\n  <td>14 GB</td>\n  <td> arm64 </td>\n  <td>\n          \n    <code><a href=\"https://github.com/actions/runner-images/blob/main/images/macos/macos-26-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>、 <code><a href=\"https://github.com/actions/runner-images/blob/main/images/macos/xcode-27-arm64-Readme.md\">xcode-27</a></code> （公共预览） </td>\n</tr>\n```\n\n  </tbody>\n</table>\n\n除了标准的 GitHub 托管运行器外，GitHub 还为使用 GitHub Team 和 GitHub Enterprise Cloud 方案的客户提供一系列具有高级特性的托管虚拟机，例如更多内核和更大磁盘空间、配备 GPU 的机器以及基于 ARM 的机器。 有关详细信息，请参阅“[大型运行程序](/zh/actions/concepts/runners/larger-runners)”。\n\n> \\[!NOTE]\n> `-latest`运行器映像是GitHub提供的最新稳定映像，但可能并非操作系统供应商提供的该操作系统的最新版本。\n\n> \\[!WARNING]\n> Beta 版映像和弃用映像均“按原样”、“包含所有缺陷”且“按现有可用状态”提供，不在服务级别协议和保修范围内。 客户支持可能不会涵盖 Beta 版映像。\n\n#### 示例：指定操作系统\n\n```yaml\nruns-on: ubuntu-latest\n```\n\n有关详细信息，请参阅“[GitHub 托管的运行程序](/zh/actions/concepts/runners/github-hosted-runners)”。\n\n## 选择自托管运行器\n\n要为作业指定自托管运行器，请在工作流文件中使用自托管运行器标签配置 `runs-on`。\n\n自托管运行器可能具有 `self-hosted` 标签。 设置自托管运行器时，默认情况下，我们将包含标签 `self-hosted`。 可以传递 `--no-default-labels` 标志来阻止自托管标签的应用。 标签可用于为运行器创建目标选项（例如，操作系统或体系结构），建议提供以 `self-hosted` 开头的标签数组（必须首先列出），然后根据需要包含其他标签。 在指定标签集之后，作业将在拥有你所指定所有标签的运行器上排队。\n\n> \\[!NOTE] Actions Runner Controller 不支持 `self-hosted` 标签。\n\n#### 示例：使用标签进行运行器选择\n\n```yaml\nruns-on: [self-hosted, linux]\n```\n\n有关详细信息，请参阅 [自托管运行程序](/zh/actions/concepts/runners/self-hosted-runners) 和 [在工作流中使用自托管运行程序](/zh/actions/how-tos/manage-runners/self-hosted-runners/use-in-a-workflow)。\n\n## 在组中选择运行器\n\n可以使用 `runs-on` 定位运行器组，以便作业将在属于该组的任何运行器上执行。 若要进行更精细的控制，还可以将运行器组与标签组合在一起。\n\n运行器组的成员只能是[大型运行器](/zh/actions/concepts/runners/larger-runners)或[自托管运行器](/zh/actions/how-tos/manage-runners/self-hosted-runners)。\n\n#### 示例：使用群组来控制作业的运行位置\n\n在此示例中，运行器已添加到名为 `build-runners` 的组。\n`runs-on` 键将作业发送到 `build-runners` 组中的任何可用运行器：\n\n```yaml\nname: learn-github-actions\non: [push]\njobs:\n  check-bats-version:\n    runs-on: \n      group: build-runners\n    steps:\n      - uses: actions/checkout@v6\n      - uses: actions/setup-node@v7\n        with:\n          node-version: '14'\n      - run: npm install -g bats\n      - run: bats -v\n```\n\n#### 示例：将组和标签组合\n\n组合组和标签时，运行器必须满足这两项要求才能运行作业。\n\n在此示例中，`runs-on` 键结合了 `group` 和 `labels`，从而将该作业路由到组内任何具有匹配标签的可用运行器：\n\n```yaml\nname: learn-github-actions\non: [push]\njobs:\n  check-bats-version:\n    runs-on:\n      group: ubuntu-runners\n      labels: ubuntu-24.04-16core\n    steps:\n      - uses: actions/checkout@v6\n      - uses: actions/setup-node@v7\n        with:\n          node-version: '14'\n      - run: npm install -g bats\n      - run: bats -v\n```"}