Skip to main content

Adding self-hosted runners

You can add a self-hosted runner to a repository, an organization, or an enterprise.

注意

GitHub Enterprise Server 目前不支持 GitHub 托管的运行器。 可以在 GitHub public roadmap 上查看有关未来支持计划的更多信息。

You can add a self-hosted runner to a repository, an organization, or an enterprise.

If you are an organization or enterprise administrator, you might want to add your self-hosted runners at the organization or enterprise level. This approach makes the runner available to multiple repositories in your organization or enterprise, and also lets you to manage your runners in one place.

警告

建议仅将自托管运行器用于私有仓库。 这是因为,通过创建在工作流中执行代码的拉取请求,公共存储库的分支可能会在自托管运行器计算机上运行危险代码。

For more information, see Security hardening for GitHub Actions.

You can set up automation to scale the number of self-hosted runners. For more information, see Autoscaling with self-hosted runners.

You can register ephemeral runners that perform a single job before the registration is cleaned up by using just-in-time runner registration. For more information, see Security hardening for GitHub Actions.

Prerequisites

  • 必须为 GitHub Enterprise Server 启用 GitHub Actions 。 站点管理员可以为实例启用和配置 GitHub Actions。 有关详细信息,请参阅“GitHub Actions for GitHub Enterprise Server 使用入门”。

  • 必须有权访问将在环境中用作自承载运行器的计算机。

  • 自托管运行器和 GitHub 通过 HTTP(端口 80)或 HTTPS(端口 443)建立连接。 若要确保通过 HTTPS 进行连接,请为 你的 GitHub Enterprise Server 实例 配置 TLS。 有关详细信息,请参阅“配置 TLS”。

Adding a self-hosted runner to a repository

You can add self-hosted runners to a single repository. To add a self-hosted runner to a user repository, you must be the repository owner. For an organization repository, you must be an organization owner, have admin access to the repository, or have the “Manage organization runners and runner groups” permission.

For more information about custom organization roles, see 关于自定义组织角色.

For information about how to add a self-hosted runner with the REST API, see 自托管运行器的 REST API 终结点.

注意

企业所有者和组织所有者可以选择允许哪些存储库创建存储库级别的自托管运行器。 拥有“管理组织运行器和运行器组”权限的用户只能选择允许哪些存储库为组织中的存储库创建存储库级自托管运行器。

有关自定义组织角色的详细信息,请参阅“关于自定义组织角色”。

有关详细信息,请参阅 在企业中为 GitHub Actions 实施策略禁用或限制组织的 GitHub Actions

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在存储库名称下,单击 “设置”。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。

    存储库标头的屏幕截图,其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。

  3. 在左侧边栏中,单击 “操作”,然后单击“运行器” 。

  4. Click New self-hosted runner.

  5. 选择自托管运行器计算机的操作系统映像和体系结构。

    操作系统和体系结构选择的屏幕截图。 这些选项以深橙色轮廓突出显示。

  6. 您将看到指示您如何下载运行器应用程序并安装到自托管运行器机器上的说明。

    在自托管运行器机器上打开 shell,并按显示的顺序运行每个 shell 命令。

    注意

    在 Windows 上,如果要将自托管运行器应用程序安装为服务,必须打开具有管理员权限的 shell。 我们还建议你使用 C:\actions-runner 作为自托管运行器应用程序的目录,以便 Windows 系统帐户可以访问运行器目录。

    这些说明将指导您完成以下任务:

    • 下载并提取自托管运行器应用程序。
    • 运行 config 脚本配置自托管运行器应用程序,并将其注册到 GitHub Actions。 config 脚本需要目标 URL 和自动生成的时间限制令牌对请求进行身份验证。 令牌将在一小时后过期。
    • 运行自托管运行器应用程序以将机器连接到 GitHub Actions。

检查您的自托管运行器是否已成功添加

在完成添加自托管运行器的步骤后,运行器及其状态列在“自托管运行器”下。

必须激活自托管运行器应用程序,运行器才能接受作业。 当运行器应用程序连接到 GitHub 并准备接收作业时,你将在机器的终端上看到以下消息。

√ Connected to GitHub

2019-10-24 05:45:56Z: Listening for Jobs

For more information, see Monitoring and troubleshooting self-hosted runners.

Adding a self-hosted runner to an organization

You can add self-hosted runners at the organization level, where they can be used to process jobs for multiple repositories in an organization. To add a self-hosted runner to an organization, you must be an organization owner or have the "Manage organization runners and runner groups" permission. For information about how to add a self-hosted runner with the REST API, see 自托管运行器的 REST API 终结点.

For more information about custom organization roles, see 关于自定义组织角色.

  1. 在 GitHub 上,导航到组织的主页面。

  2. 在组织名称下,单击 “设置”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”********。

    组织配置文件中选项卡的屏幕截图。 “设置”选项卡以深橙色标出。

  3. 在左侧边栏中,单击 “操作”,然后单击“运行器” 。

  4. Click New runner.

  5. 选择自托管运行器计算机的操作系统映像和体系结构。

    操作系统和体系结构选择的屏幕截图。 这些选项以深橙色轮廓突出显示。

  6. 您将看到指示您如何下载运行器应用程序并安装到自托管运行器机器上的说明。

    在自托管运行器机器上打开 shell,并按显示的顺序运行每个 shell 命令。

    注意

    在 Windows 上,如果要将自托管运行器应用程序安装为服务,必须打开具有管理员权限的 shell。 我们还建议你使用 C:\actions-runner 作为自托管运行器应用程序的目录,以便 Windows 系统帐户可以访问运行器目录。

    这些说明将指导您完成以下任务:

    • 下载并提取自托管运行器应用程序。
    • 运行 config 脚本配置自托管运行器应用程序,并将其注册到 GitHub Actions。 config 脚本需要目标 URL 和自动生成的时间限制令牌对请求进行身份验证。 令牌将在一小时后过期。
    • 运行自托管运行器应用程序以将机器连接到 GitHub Actions。

检查您的自托管运行器是否已成功添加

在完成添加自托管运行器的步骤后,运行器及其状态列在“自托管运行器”下。

必须激活自托管运行器应用程序,运行器才能接受作业。 当运行器应用程序连接到 GitHub 并准备接收作业时,你将在机器的终端上看到以下消息。

√ Connected to GitHub

2019-10-24 05:45:56Z: Listening for Jobs

For more information, see Monitoring and troubleshooting self-hosted runners.

注意

出于安全原因,公共存储库默认不能在运行器组中使用运行器,但你可以在运行器组的设置中覆盖此项。 有关详细信息,请参阅“Managing access to self-hosted runners using groups”。

Adding a self-hosted runner to an enterprise

You can add self-hosted runners to an enterprise, where they can be assigned to multiple organizations. The organization owner can control which repositories can use it.

New runners are assigned to the default group. You can modify the runner's group after you've registered the runner. For more information, see Managing access to self-hosted runners using groups.

To add a self-hosted runner to an enterprise, you must be an enterprise owner. For information about how to add a self-hosted runner with the REST API, see the enterprise endpoints in the GitHub Actions REST API.

  1. 在 的右上角,单击你的个人资料照片,然后单击“企业设置”****。

    单击 GitHub Enterprise Server 上的个人资料照片时显示的下拉菜单的屏幕截图。 框出了“企业设置”选项。

  2. 在页面顶部,单击“ Policies”****。

  3. 在“ 策略”下,单击“操作”。****

  4. 单击“运行器”选项卡。

  5. 单击“新运行器”。 1. 选择自托管运行器计算机的操作系统映像和体系结构。

    操作系统和体系结构选择的屏幕截图。 这些选项以深橙色轮廓突出显示。

  6. 您将看到指示您如何下载运行器应用程序并安装到自托管运行器机器上的说明。

    在自托管运行器机器上打开 shell,并按显示的顺序运行每个 shell 命令。

    注意

    在 Windows 上,如果要将自托管运行器应用程序安装为服务,必须打开具有管理员权限的 shell。 我们还建议你使用 C:\actions-runner 作为自托管运行器应用程序的目录,以便 Windows 系统帐户可以访问运行器目录。

    这些说明将指导您完成以下任务:

    • 下载并提取自托管运行器应用程序。
    • 运行 config 脚本配置自托管运行器应用程序,并将其注册到 GitHub Actions。 config 脚本需要目标 URL 和自动生成的时间限制令牌对请求进行身份验证。 令牌将在一小时后过期。
    • 运行自托管运行器应用程序以将机器连接到 GitHub Actions。

检查您的自托管运行器是否已成功添加

在完成添加自托管运行器的步骤后,运行器及其状态列在“自托管运行器”下。

必须激活自托管运行器应用程序,运行器才能接受作业。 当运行器应用程序连接到 GitHub 并准备接收作业时,你将在机器的终端上看到以下消息。

√ Connected to GitHub

2019-10-24 05:45:56Z: Listening for Jobs

For more information, see Monitoring and troubleshooting self-hosted runners.

注意

出于安全原因,公共存储库默认不能在运行器组中使用运行器,但你可以在运行器组的设置中覆盖此项。 有关详细信息,请参阅“Managing access to self-hosted runners using groups”。

Making enterprise runners available to repositories

By default, runners in an enterprise's "Default" self-hosted runner group are available to all organizations in the enterprise, but are not available to all repositories in each organization.

To make an enterprise-level self-hosted runner group available to an organization repository, you might need to change the organization's inherited settings for the runner group to make the runner available to repositories in the organization.

For more information on changing runner group access settings, see Managing access to self-hosted runners using groups.

Further reading