This page explains how to connect to a Bitbucket Data Center repository to Cloud Build.
Before you begin
- 
  
  
    
      Enable the Cloud Build and Secret Manager APIs. 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 the instructions to connect a Bitbucket Data Center host before connecting to a repository.
Connect to a Bitbucket Data Center repository
Console
- Open the Repositories page in the Google Cloud console. - You will see the Repositories page. 
- At the top of the page, select the 2nd gen tab. 
- In the project selector, select your Google Cloud project. 
- Click Link repository to link repositories from your connection. - You will see the Link repositories panel. 
- In the Link repositories panel, enter the following information: - Connection: Select a connection from the drop-down menu. 
- Repository: Select one or more repositories to link to your connection. 
- Repository Resource Name: Use these fields to create resource names for the repositories that are linked. - 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, you can modify the names for your selected repositories in the Repository names section. 
 
 
- Click Link to link your repository to your connection. 
gcloud
To add a Bitbucket Data Center repository to your connection, run the following command:
gcloud builds repositories create REPO_NAME \
    --remote-uri=REPO_URI \
    --connection=CONNECTION_NAME --region=REGION
Where:
- REPO_NAME is the name of your repository.
- REPO_URI is the link to your Bitbucket Data Center
repository. For example, https://bbdc-host.com/scm/myproject/myrepo.git.
- CONNECTION_NAME is the name given to the Bitbucket Data Center host connection created in Cloud Build from Connect to a Bitbucket Data Center host.
- REGION is the region for your connection.
Terraform
To add a Bitbucket Data Center 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 = "REPO_URI"
    }
Where:
- PROJECT_ID is your Google Cloud project ID.
- 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 Data Center host.
- REPO_URI is the link to your Bitbucket Data Center
repository. For example, https://bbdc-host.com/scm/myproject/myrepo.git.
What's next
- Learn how to build repositories from Bitbucket Data Center.
- Learn how to build repositories from Bitbucket Data Center in a private network.
- Learn how to perform blue/green deployments on Compute Engine.