This page explains how to connect a Bitbucket Cloud repository to Cloud Build.
Before you begin
-
Enable the Cloud Build API.
- Follow instructions in Connect to a Bitbucket Cloud host.
Connect to Bitbucket Cloud repositories
Console
Connect Cloud Build to your Bitbucket Cloud repository by doing the following steps:
Open the Repositories page in the Google Cloud console.
You will see the Repositories page.
In the project selector, select your Google Cloud project.
Select the 2nd gen tab.
Click Link repository to connect a new host to Cloud Build.
You will see the Link repositories side panel.
Connection: Select a host connection from the drop-down menu.
Repository: Select a repository from the drop-down menu.
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.
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
- Learn how to build repositories from a Bitbucket Cloud.
- Learn how to view build results.
- Learn how to perform blue/green deployments on Compute Engine.