Skip to main content

Using labels with self-hosted runners

You can use labels to organize your self-hosted runners based on their characteristics.

For information on how to use labels to route jobs to specific types of self-hosted runners, see "Using self-hosted runners in a workflow." You can also route jobs to runners in a specific group. For more information, see "Targeting runners in a group."

A self-hosted runner can be located in either your repository, organization, or enterprise account settings on GitHub. To manage a self-hosted runner, you must have the following permissions, depending on where the self-hosted runner was added:

  • User repository: You must be the repository owner.

  • Organization: You must be an organization owner.

  • Organization repository: You must be an organization owner, or have admin access to the repository.

  • Enterprise account: You must be an enterprise owner.

Creating a custom label

  1. 导航到自托管运行器注册的位置:

    • 在组织或存储库中:导航到主页并单击“ 设置” 。

    • 如果使用的是企业级运行器:

      1. 在 GitHub.com 的右上角,单击你的个人资料照片,然后单击“你的企业”。 GitHub Enterprise Cloud 上个人资料照片下拉菜单中的“你的企业”

      2. 在企业列表中,单击您想要查看的企业。 企业列表中的企业名称

  2. 导航到 GitHub Actions 设置:

    • 在组织或存储库中:

      1. In the left sidebar, click Actions, then click Runners.
    • 如果使用的是企业级运行器:

      1. 在企业边栏中,单击 “策略”。 企业帐户边栏中的“策略”选项卡 1. 在“ 策略”下,单击“操作”。 1. 单击“运行器”选项卡。
  3. 在运行器列表中,单击要配置的运行器。

  4. In the "Labels" section, click .

  5. In the "Find or create a label" field, type the name of your new label and click Create new label. The custom label is created and assigned to the self-hosted runner. Custom labels can be removed from self-hosted runners, but they currently can't be manually deleted. 未分配给运行器的任何未使用标签将在 24 小时内被自动删除。

Assigning a label to a self-hosted runner

  1. 导航到自托管运行器注册的位置:

    • 在组织或存储库中:导航到主页并单击“ 设置” 。

    • 如果使用的是企业级运行器:

      1. 在 GitHub.com 的右上角,单击你的个人资料照片,然后单击“你的企业”。 GitHub Enterprise Cloud 上个人资料照片下拉菜单中的“你的企业”

      2. 在企业列表中,单击您想要查看的企业。 企业列表中的企业名称

  2. 导航到 GitHub Actions 设置:

    • 在组织或存储库中:

      1. In the left sidebar, click Actions, then click Runners.
    • 如果使用的是企业级运行器:

      1. 在企业边栏中,单击 “策略”。 企业帐户边栏中的“策略”选项卡 1. 在“ 策略”下,单击“操作”。 1. 单击“运行器”选项卡。
  3. 在运行器列表中,单击要配置的运行器。

  4. 在“Labels(标签)”部分,单击

  5. To assign a label to your self-hosted runner, in the "Find or create a label" field, click the label.

Removing a custom label from a self-hosted runner

  1. 导航到自托管运行器注册的位置:

    • 在组织或存储库中:导航到主页并单击“ 设置” 。

    • 如果使用的是企业级运行器:

      1. 在 GitHub.com 的右上角,单击你的个人资料照片,然后单击“你的企业”。 GitHub Enterprise Cloud 上个人资料照片下拉菜单中的“你的企业”

      2. 在企业列表中,单击您想要查看的企业。 企业列表中的企业名称

  2. 导航到 GitHub Actions 设置:

    • 在组织或存储库中:

      1. In the left sidebar, click Actions, then click Runners.
    • 如果使用的是企业级运行器:

      1. 在企业边栏中,单击 “策略”。 企业帐户边栏中的“策略”选项卡 1. 在“ 策略”下,单击“操作”。 1. 单击“运行器”选项卡。
  3. 在运行器列表中,单击要配置的运行器。

  4. 在“Labels(标签)”部分,单击

  5. In the "Find or create a label" field, assigned labels are marked with the icon. Click on a marked label to unassign it from your self-hosted runner.

Programmatically assign labels

You can programmatically assign labels to a self-hosted runner after the runner is created, or during its initial configuration.

  • To programmatically assign labels to an existing self-hosted runner, you must use the REST API. For more information, see the "Self-hosted runners" REST API.

  • To programmatically assign labels to a self-hosted runner during the initial runner configuration, you can pass label names to the config script using the labels parameter.

    Note: You cannot use the config script to assign labels to an existing self-hosted runner.

    For example, this command assigns a label named gpu when configuring a new self-hosted runner:

    ./config.sh --url <REPOSITORY_URL> --token <REGISTRATION_TOKEN> --labels gpu
    

    The label is created if it does not already exist. You can also use this approach to assign the default labels to runners, such as x64 or linux. When default labels are assigned using the configuration script, GitHub Actions accepts them as given and does not validate that the runner is actually using that operating system or architecture.

    You can use comma separation to assign multiple labels. For example:

    ./config.sh --url <REPOSITORY_URL> --token <REGISTRATION_TOKEN> --labels gpu,x64,linux
    

    Note: If you replace an existing runner, then you must reassign any custom labels.