Connect to a Bitbucket Cloud repository

This page explains how to connect a Bitbucket Cloud repository to Cloud Build.

Before you begin

  • Enable the Cloud Build API.

    Enable the API

Connect to Bitbucket Cloud repositories

Console

Connect Cloud Build to your Bitbucket Cloud repository by doing the following steps:

  1. Open the Repositories page in the Google Cloud console.

    Open the Repositories page

    You will see the Repositories page.

  2. In the project selector, select your Google Cloud project.

  3. Select the 2nd gen tab.

  4. Click Link repository to connect a new host to Cloud Build.

    You will see the Link repositories side panel.

  5. Connection: Select a host connection from the drop-down menu.

  6. Repository: Select a repository from the drop-down menu.

  7. Repository Resource Name: This step creates resource names for the linked repositories.

    • Generated: Select this option for Cloud Build to automatically generate repository resource names on your behalf for selected repositories.
    • Manual: Select this option to manually specify repository resource names.

    If you select Manual, then you can modify the names for your selected repositories in the Repository names section.

  8. Click Link.

gcloud

Connect to your Bitbucket Cloud repository:

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

Where:

  • REPO_NAME is the name of your repository.
  • WORKSPACE is the workspace ID for your repository.
  • REPOSITORY is the name of the repository.
  • REGION is the region for your connection.
  • CONNECTION_NAME is the name of your connection.
  • PROJECT_ID is your Google Cloud project ID.

Terraform

To add a Bitbucket Cloud repository to your connection, add the following code snippet to your Terraform configuration:

    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"
    }

Where:

  • PROJECT_ID is your Google Cloud project ID.
  • WORKSPACE_ID is the workspace ID for your repository.
  • REPO_NAME is the name of your repository.
  • REGION is the region for your connection.
  • RESOURCE_NAME is the name of the google_cloudbuildv2_connection resource. For example, my-connection from the Terraform example in Connect to a Bitbucket Cloud host.

What's next