连接版本控制系统
Use Unity Build Automation with a version control system.
阅读时间7 分钟最后更新于 19 天前
要在项目中使用 Build Automation,首先必须将项目托管在一个源代码控制系统(也称为版本控制系统)中。Unity Build Automation 支持以下系统: 以下说明如何为 Build Automation 设置源代码控制。
将 Build Automation 连接到 Unity Version Control
Unity Build Automation 支持存储在 UVCS 代码仓库中的项目。- 从 Build settings(构建设置)中,选择 Source control(源代码控制) 选项卡。
- 从下拉选单中选择 UVCS。
- 在 source control provider URL(源代码控制提供者 URL) 字段中,添加 UVCS 云服务器的 URL,或者从可用组织列表中选择。
- 选择 Authenticate with Unity ID(使用 Unity ID 进行身份验证) 或 Authenticate with username or password(使用用户名或密码进行身份验证)。
- 如果选择 Authenticate with username or password(使用用户名或密码进行身份验证),请输入 UVCS 服务器的用户名和密码。
- 从下拉选单中选择一种身份验证类型。
- 如果代码仓库已加密,请选中 My repository is encrypted(我的代码仓库已加密)复选框。a.添加加密密钥。b.添加加密方法。
- 选择 Save(保存)。
将 Build Automation 连接到 Git
Unity Build Automation 支持存储在 Git 代码仓库中的项目。代码仓库可以托管在 GitHub、GitLab、Bitbucket 或私有服务器上。 您可以使用以下授权协议来配置对代码仓库的访问: 如果使用的是 Windows 操作系统,还可以选择构建将使用的 Git 可执行文件。个人访问令牌
要将 Build Automation 配置为使用个人访问令牌来访问代码仓库,请执行以下操作:- 从 Build settings(构建设置)中,选择 Source control(源代码控制) 选项卡。
- 从下拉选单中选择 GitHub、Bitbucket 或 GitLab。
- 从 Git 提供者生成个人访问令牌。
- 输入您的令牌并选择 Authorize(授权),以便 Unity 可以访问您的提供者帐户。
- 从下拉选单中选择您的首选代码仓库。
- 从 Build settings(构建设置)页面中,选择 Save(保存)。
GitHub
Build Automation 要求您对要构建的代码仓库具有读取权限。 如果使用的是个人访问令牌(经典),则所需的特定权限为:如果要构建的代码仓库是私有代码仓库,则需要repopublic_repowrite:repo_hookContentsRead-onlyWebhooks(如果使用自动构建)Read and write
GitLab
为了让 Build Automation 构建代码仓库,必须向个人访问令牌授予read_repositorywrite_repositoryBitbucket
代码仓库访问令牌授予对单个代码仓库的访问权限,因此您必须为要构建的每个代码仓库创建一个令牌。 为了让 Build Automation 构建代码仓库,必须向令牌授予RepositoriesReadWebhooksRead and writeSSH 密钥和私有代码仓库
Build Automation 在连接到托管站点时,会自动检测代码仓库是公开还是私有代码仓库。如果代码仓库是公开代码仓库,则 Build Automation 会自动连接到该代码仓库,并可跳至 Build Configuration(构建配置)。 如果代码仓库是私有代码仓库,则会生成 SSH 密钥并显示在代码仓库 URL 下方的设置屏幕中。将此 SSH 密钥添加到源代码控制提供者的设置中,以授予 Build Automation 访问权限。 要将 Build Automation 配置为使用 SSH 密钥来访问代码仓库,请执行以下操作:- 在 Source control(源代码控制) 选项卡中,从下拉选单中选择 Manual setup(手动设置),然后选择 Git。
- 在 Source control provider URL(源代码控制提供者 URL) 字段中,添加 Git 服务器的 URL。以下是 GitHub、Bitbucket 和 GitLab 的 URL 示例:
git@github.com:youraccount/yourrepo.gitgit@bitbucket.org:youraccount/yourrepo.gitgit@gitlab.com:youracccount/yourrepo.git
- 如果代码仓库是私有代码仓库,请将 SSH 密钥添加到源代码控制提供者设置中。
- 设置完成后,在 Source control(源代码控制)选项卡上,选择 Save(保存)。
将 Build Automation 连接到 Azure
Unity Build Automation 支持存储在 Azure 代码仓库中的项目。在 Dashboard 上配置 Azure
- 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
- 从下拉选单中选择 Azure。
- 添加您的 Azure 组织。
- 添加代码仓库所属的 Azure 项目。
- 创建并提供 Azure 个人访问令牌。
- 选择 Authorize(授权) 以允许 Unity 检索代码仓库。
- 选择 Save(保存)。
将 Build Automation 连接到 SVN
Unity Build Automation 支持托管在 Apache Subversion (SVN) 代码仓库中的项目。- 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
- 从下拉选单中选择 Manual setup(手动设置),然后选择 SVN。
- 在 SVN 服务器中,仅为 Unity Build Automation 创建一个只读用户帐户以及安全密码。
- 在 Build settings(构建设置)页面的相应字段中,输入新的用户名和密码。
- 选择 Save(保存)。
公有 SSH 密钥
Build Automation 不支持使用公有 SSH 密钥连接到 SVN 代码仓库。请改用用户名和密码。SSL 证书
不支持自签名的 SSL 证书。Build Automation 不支持与具有自签名证书的服务器进行 SSL 握手。证书中的主机名必须与 Build Automation 访问的主机名匹配。将 Build Automation 连接到 Perforce
Unity Build Automation 支持存储在 Perforce 代码仓库中的项目。在 Dashboard 上配置 Perforce
- 从 Build settings(构建设置)页面中,选择 Source control(源代码控制) 选项卡。
- 从下拉选单中选择 Manual setup(手动设置),然后选择 Perforce。
- 在 source control provider URL(源代码控制提供者 URL)字段中,输入 Perforce 服务器的 URL。您可以指定使用 或 SSL 协议的 URL。以下是有效的 URL 示例:
https://https://127.0.0.1:1667ssl:127.0.0.1:167
- 在 P4 中,创建一个对代码仓库具有只读访问权限的用户。
- 在 Build settings(构建设置)页面的相应字段中,输入用户名和密码。
- 选择 Save(保存)。