文档

​
​

Development

User Acquisition

Monetization

工业

Build Automation

DevOps

Build Automation REST API

Build Automation Editor Package

Open Unity Dashboard

Build Automation

​
​
Build Automation
  • Overview
  • Get started with Build Automation
  • Build Automation Glossary
  • Build configuration
  • Advanced build configuration
  • Run builds
  • Check build results
  • Optimize build speed
  • Manage consumption costs
  • Sign build artifacts
  • Build Automation integrations
  • Build Automation API
  • Build Automation Editor Package
  • Reference
  1. Unity Build Automation

连接版本控制系统

Use Unity Build Automation with a version control system.
阅读时间11 分钟
最后更新于 9 个月前

要在项目中使用 Build Automation,首先必须将项目托管在一个源代码控制系统(也称为版本控制系统)中。Unity Build Automation 支持以下系统:
  • Unity Version Control
  • Git
  • Azure
  • SVN
  • Perforce
以下说明如何为 Build Automation 设置源代码控制。

将 Build Automation 连接到 Unity Version Control

Unity Build Automation 支持存储在 UVCS 代码仓库中的项目。
注意
注意:此产品需要订阅 Unity DevOps。
  1. 从 Build settings(构建设置)中,选择 Source control(源代码控制) 选项卡。
  2. 从下拉选单中选择 UVCS。
  3. 在 source control provider URL(源代码控制提供者 URL) 字段中,添加 UVCS 云服务器的 URL,或者从可用组织列表中选择。
  4. 选择 Authenticate with Unity ID(使用 Unity ID 进行身份验证) 或 Authenticate with username or password(使用用户名或密码进行身份验证)。
  5. 如果选择 Authenticate with username or password(使用用户名或密码进行身份验证),请输入 UVCS 服务器的用户名和密码。
  6. 从下拉选单中选择一种身份验证类型。
  7. 如果代码仓库已加密,请选中 My repository is encrypted(我的代码仓库已加密)复选框。a.添加加密密钥。b.添加加密方法。
  8. 选择 Save(保存)。

将 Build Automation 连接到 Git

Unity Build Automation 支持存储在 Git 代码仓库中的项目。代码仓库可以托管在 GitHub、GitLab、Bitbucket 或私有服务器上。
您可以使用以下授权协议来配置对代码仓库的访问:
  • 个人访问令牌(默认)
  • SSH 密钥
如果使用的是 Windows 操作系统,还可以选择构建将使用的 Git 可执行文件。

个人访问令牌

要将 Build Automation 配置为使用个人访问令牌来访问代码仓库,请执行以下操作:
  1. 从 Build settings(构建设置)中,选择 Source control(源代码控制) 选项卡。
  2. 从下拉选单中选择 GitHub、Bitbucket 或 GitLab。
  3. 从 Git 提供者生成个人访问令牌。
  4. 输入您的令牌并选择 Authorize(授权),以便 Unity 可以访问您的提供者帐户。
  5. 从下拉选单中选择您的首选代码仓库。
  6. 从 Build settings(构建设置)页面中,选择 Save(保存)。
个人访问令牌因提供者而异。下面列出了每个提供者的相关详细信息,但有关如何生成和使用令牌的最新详细信息,请参阅提供者的文档。

GitHub

Build Automation 要求您对要构建的代码仓库具有读取权限。
如果使用的是个人访问令牌(经典),则所需的特定权限为:如果要构建的代码仓库是私有代码仓库,则需要
repo
权限;如果要构建的代码仓库是公开代码仓库并且您希望允许最低访问级别,则需要
public_repo
权限。
如果您计划在 Build Automation 中启用自动构建,则还需要
write:repo_hook
权限。
即使您在创建令牌时没有提供到期日期,GitHub 也会自动移除一年内未使用的经典个人访问令牌。
可以为用户或组织创建细粒度的个人访问令牌。可以授予对用户或组织拥有的所有代码仓库的访问权限,也可以仅授予对特定代码仓库的访问权限。如果选择使用细粒度令牌,并且配置的令牌不只是具有公开代码仓库访问权限,则必须为访问令牌添加特定权限。
以下是使用细粒度令牌的最低代码仓库权限要求:
  • Contents
    Read-only
  • Webhooks
    Read and write
    (如果使用自动构建)
Build Automation 不需要任何帐户权限。
请注意,细粒度个人访问令牌始终具有过期日期,一旦令牌过期,Build Automation 将无法再访问您的代码仓库。
注意
细粒度个人访问令牌目前处于测试阶段,所需权限(或令牌的其他方面)可能会发生变化,这可能要求您采取措施,以继续在 Build Automation 中使用这些令牌。

GitLab

为了让 Build Automation 构建代码仓库,必须向个人访问令牌授予
read_repository
范围的权限。如果打算在 Build Automation 中启用自动构建,则还需要
write_repository
范围的权限。
GitLab 令牌始终会在创建时设置过期日期,一旦令牌过期,Build Automation 将无法再访问您的代码仓库。

Bitbucket

代码仓库访问令牌授予对单个代码仓库的访问权限,因此您必须为要构建的每个代码仓库创建一个令牌。
为了让 Build Automation 构建代码仓库,必须向令牌授予
Repositories
范围的
Read
权限。如果打算在 Build Automation 中启用自动构建,还需要授予
Webhooks
范围的
Read and write
权限。
对于所有提供者,如果您撤销访问令牌、令牌过期,或者与令牌关联的用户对代码仓库的访问权限被降低或撤销,则 Build Automation 将无法再访问代码仓库。
有关下一步操作,请参阅“设置目标构建平台”。

SSH 密钥和私有代码仓库

Build Automation 在连接到托管站点时,会自动检测代码仓库是公开还是私有代码仓库。如果代码仓库是公开代码仓库,则 Build Automation 会自动连接到该代码仓库,并可跳至 Build Configuration(构建配置)。
如果代码仓库是私有代码仓库,则会生成 SSH 密钥并显示在代码仓库 URL 下方的设置屏幕中。将此 SSH 密钥添加到源代码控制提供者的设置中,以授予 Build Automation 访问权限。
要将 Build Automation 配置为使用 SSH 密钥来访问代码仓库,请执行以下操作:
  1. 在 Source control(源代码控制) 选项卡中,从下拉选单中选择 Manual setup(手动设置),然后选择 Git。
  2. 在 Source control provider URL(源代码控制提供者 URL) 字段中,添加 Git 服务器的 URL。以下是 GitHub、Bitbucket 和 GitLab 的 URL 示例:
    • git@github.com:youraccount/yourrepo.git
    • git@bitbucket.org:youraccount/yourrepo.git
    • git@gitlab.com:youracccount/yourrepo.git
  3. 如果代码仓库是私有代码仓库,请将 SSH 密钥添加到源代码控制提供者设置中。
  4. 设置完成后,在 Source control(源代码控制)选项卡上,选择 Save(保存)。

将 Build Automation 连接到 Azure

Unity Build Automation 支持存储在 Azure 代码仓库中的项目。

在 Dashboard 上配置 Azure

  1. 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
  2. 从下拉选单中选择 Azure。
  3. 添加您的 Azure 组织。
  4. 添加代码仓库所属的 Azure 项目。
  5. 创建并提供 Azure 个人访问令牌。
  6. 选择 Authorize(授权) 以允许 Unity 检索代码仓库。
  7. 选择 Save(保存)。

将 Build Automation 连接到 SVN

Unity Build Automation 支持托管在 Apache Subversion (SVN) 代码仓库中的项目。
  1. 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
  2. 从下拉选单中选择 Manual setup(手动设置),然后选择 SVN。
  3. 在 SVN 服务器中,仅为 Unity Build Automation 创建一个只读用户帐户以及安全密码。
  4. 在 Build settings(构建设置)页面的相应字段中,输入新的用户名和密码。
  5. 选择 Save(保存)。

公有 SSH 密钥

Build Automation 不支持使用公有 SSH 密钥连接到 SVN 代码仓库。请改用用户名和密码。

SSL 证书

不支持自签名的 SSL 证书。Build Automation 不支持与具有自签名证书的服务器进行 SSL 握手。证书中的主机名必须与 Build Automation 访问的主机名匹配。

将 Build Automation 连接到 Perforce

Unity Build Automation 支持存储在 Perforce 代码仓库中的项目。

在 Dashboard 上配置 Perforce

  1. 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
  2. 从下拉选单中选择 Manual setup(手动设置),然后选择 Perforce。
  3. 在 source control provider URL(源代码控制提供者 URL)字段中,输入 Perforce 服务器的 URL。您可以指定使用
    https://
    或 SSL 协议的 URL。以下是有效的 URL 示例:
    • https://127.0.0.1:1667
    • ssl:127.0.0.1:167
  4. 在 P4 中,创建一个对代码仓库具有只读访问权限的用户。
  5. 在 Build settings(构建设置)页面的相应字段中,输入用户名和密码。
  6. 选择 Save(保存)。

后续步骤

  • 创建第一个构建配置。
  • 运行第一个构建。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 将 Build Automation 连接到 Unity Version Control

    • 将 Build Automation 连接到 Git

      • 个人访问令牌

        • GitHub

        • GitLab

        • Bitbucket

      • SSH 密钥和私有代码仓库

    • 将 Build Automation 连接到 Azure

      • 在 Dashboard 上配置 Azure

    • 将 Build Automation 连接到 SVN

      • 公有 SSH 密钥

      • SSL 证书

    • 将 Build Automation 连接到 Perforce

      • 在 Dashboard 上配置 Perforce

    • 后续步骤


报告此页面的问题