连接到 Bitbucket Cloud 代码库

本页介绍了如何将 Bitbucket Cloud 代码库关联到 Cloud Build。

准备工作

  • Enable the Cloud Build API.

    Enable the API

连接到 Bitbucket Cloud 代码库

控制台

请按以下步骤将 Cloud Build 连接到您的 Bitbucket Cloud 代码库:

  1. 打开 Google Cloud 控制台中的制品库页面。

    打开“代码库”页面

    您将看到代码库页面。

  2. 在项目选择器中,选择您的 Google Cloud 项目。

  3. 选择第 2 代标签页。

  4. 点击关联代码库以将新的主机连接到 Cloud Build。

    您将看到关联代码库侧边栏。

  5. 连接:从下拉菜单中选择主机连接。

  6. 代码库:从下拉菜单中选择一个代码库。

  7. 代码库资源名称:此步骤会为关联的代码库创建资源名称。

    • 生成:为 Cloud Build 选择此选项后,Cloud Build 会代表您自动为所选代码库生成代码库资源名称。
    • 手动:选择此选项可手动指定代码库资源名称。

    如果您选择手动,则可以在代码库名称部分修改所选代码库的名称。

  8. 点击关联

gcloud

连接到您的 Bitbucket Cloud 代码库:

gcloud builds repositories create REPO_NAME \
    --remote-uri=https://bitbucket.org/WORKSPACE/REPOSITORY.git \
    --connection=CONNECTION_NAME --region=REGION --project=PROJECT_ID

其中:

  • REPO_NAME 是代码库的名称。
  • WORKSPACE 是代码库的工作区 ID。
  • REPOSITORY 是代码库的名称。
  • REGION 是连接的区域
  • CONNECTION_NAME 是连接的名称。
  • PROJECT_ID 是您的 Google Cloud 项目 ID

Terraform

如需向关联添加 Bitbucket Cloud 代码库,请将以下代码段添加到 Terraform 配置中:

    resource "google_cloudbuildv2_repository" "my-repository" {
       project = "PROJECT_ID"
       name = "REPO_NAME"
       location = "REGION"
       parent_connection = google_cloudbuildv2_connection.RESOURCE_NAME.name
       remote_uri = "https://bitbucket.org/WORKSPACE_ID/REPO_NAME.git"
    }

其中:

  • PROJECT_ID 是您的 Google Cloud 项目 ID
  • WORKSPACE_ID 是代码库的工作区 ID。
  • REPO_NAME 是代码库的名称。
  • REGION 是连接的区域
  • RESOURCE_NAMEgoogle_cloudbuildv2_connection 资源的名称。例如,连接到 Bitbucket Cloud 主机中的 Terraform 示例中的 my-connection

后续步骤