本页面介绍了如何将 GitLab Enterprise Edition 代码库连接到 Cloud Build。如需详细了解 Cloud Build 代码库,请参阅 Cloud Build 代码库。
准备工作
-
启用 Cloud Build and Secret Manager API。
- 在连接代码库之前,请按照说明连接 GitLab Enterprise Edition 主机。
连接到 GitLab Enterprise Edition 代码库
控制台
打开 Google Cloud 控制台中的制品库页面。
您会看到代码库页面。
在页面顶部,选择第 2 代标签页。
在顶部栏的项目选择器中,选择您的 Google Cloud 项目。
点击关联代码库,以通过您的连接关联代码库。
您会看到关联代码库面板。
在关联代码库面板中,输入以下信息:
- 连接:从下拉菜单中选择一个连接。
代码库:选择要关联到连接的代码库。
代码库名称:输入代码库的名称。
- 已生成:为 Cloud Build 选择此选项,系统会代表您为所选代码库自动生成代码库名称。
手动:选择此选项可为所选代码库手动指定名称。
如果选择手动,您可以在代码库名称部分中修改所选代码库的名称。
点击关联,将您的代码库关联到连接。
现在,您已成功将 GitLab Enterprise Edition 代码库关联到您的连接。
gcloud
如需将 GitLab Enterprise Edition 代码库添加到您的连接,请输入以下命令:
gcloud builds repositories create REPO_NAME \
--remote-uri=REPO_URI \
--connection=CONNECTION_NAME --region=REGION
其中:
- REPO_NAME 是代码库的名称。
- REPO_URI 是指向您的 GitLab Enterprise Edition 代码库的链接。例如,https://
gitlab-enterprise.com/myuser/myrepo.git
。 - CONNECTION_NAME 是您的连接的名称。
- REGION 是您的连接所在的区域。
现在,您已将代码库关联到 GitLab Enterprise Edition 连接。
Terraform
如需将 GitLab Enterprise Edition 代码库添加到您的连接,请将以下代码段添加到您的 Terraform 配置:
resource "google_cloudbuildv2_repository" "my-repository" {
project = "PROJECT_ID"
name = "REPO_NAME"
location = :REGION"
parent_connection = google_cloudbuildv2_connection.my-connection.name
remote_uri = "REPO_URI'
}
其中:
- PROJECT_ID 是您的 Google Cloud 项目 ID。
- REPO_NAME 是 GitLab Enterprise Edition 代码库的名称。
- REGION 是您的连接所在的区域。
- REPO_URI 是代码库的远程 URI。例如
https://gitlab-enterprise.com/myuser/myrepo.git
。
现在,您已将代码库关联到 GitLab Enterprise Edition 连接。
后续步骤
- 了解如何从 GitLab Enterprise Edition 构建代码库。
- 了解如何在专用网络中通过 GitLab Enterprise Edition 构建代码库。
- 了解如何在 GitLab 流水线中使用 Google 管理的 CI/CD 组件构建工作负载并将其部署到 Google Cloud。请参阅 Google Cloud 上的 GitLab。