本页介绍了如何将 GitLab 代码库连接到 Cloud Build。如需详细了解 Cloud Build 代码库,请参阅 Cloud Build 代码库。
准备工作
-
Enable the Cloud Build and Secret Manager APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.
- 请先按照说明连接 GitLab 主机,然后再连接代码库。
连接到 GitLab 代码库
控制台
在 Google Cloud 控制台中打开代码库页面。
您会看到代码库页面。
在页面顶部,选择第 2 代标签页。
在顶部栏的项目选择器中,选择您的 Google Cloud 项目。
点击关联代码库以关联连接中的代码库。
您会看到关联代码库面板。
在关联代码库面板中,输入以下信息:
- 连接:从下拉菜单中选择连接。
代码库:选择要与连接相关联的代码库。
代码库名称:输入代码库的名称。
- 生成:选择此选项可让 Cloud Build 自动为所选代码库生成代码库名称。
手动:选择此选项可手动为所选代码库指定名称。
如果您选择手动,则可以在代码库名称部分修改所选代码库的名称。
点击关联,将代码库与连接相关联。
gcloud
如需向连接添加 GitLab 代码库,请输入以下命令:
gcloud builds repositories create REPO_NAME \
--remote-uri=REPO_URI \
--connection=CONNECTION_NAME --region=REGION
其中:
- REPO_NAME 是代码库的名称。
- REPO_URI 是指向您的 GitLab 代码库的链接。
- CONNECTION_NAME 是在 Cloud Build 中通过连接到 GitLab 主机创建的 GitLab 连接的名称。
- REGION 是连接的区域。
您现在已将代码库关联到 GitLab 连接。
后续步骤
- 了解如何从 GitLab 构建代码库。
- 了解如何在 GitLab 流水线中使用 Google 管理的 CI/CD 组件,将工作负载构建并部署到 Google Cloud 。请参阅 Google Cloud上的 GitLab。