This page explains how to connect a Bitbucket Cloud repository to Cloud Build.
Before you begin
-
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles .
- 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 Repositoriespage in the Google Cloud console.
You will see the Repositoriespage.
-
In the project selector, select your Google Cloud project.
-
Select the 2nd gentab.
-
Click Link repositoryto connect a new host to Cloud Build.
You will see the Link repositoriesside 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 namessection.
-
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 given to the Bitbucket Cloud host connection created in Cloud Build from Connect to a Bitbucket Cloud host .
- 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_connectionresource. For example,my-connectionfrom 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 .

