连接到 Bitbucket Cloud 代码库

本页面介绍了如何连接到 Bitbucket Cloud 代码库 到 Cloud Build

准备工作

  • 启用 Cloud Build API。

    启用 API

连接到 Bitbucket Cloud 代码库

控制台

通过以下方式将 Cloud Build 连接到您的 Bitbucket Cloud 代码库: 执行以下操作:

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

    打开“代码库”页面

    您将看到代码库页面。

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

  3. 选择第 2 代标签页。

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

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

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

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

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

    • Generated(生成):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 资源。例如,my-connection 连接到 Bitbucket Cloud 主机中的 Terraform 示例。

后续步骤