Build repositories from Bitbucket Cloud

Cloud Build enables you to create triggers to build from repositories hosted on Bitbucket Cloud, allowing you to execute builds in response to events such as commit pushes or merge requests associated with your Bitbucket Cloud repository.

This page explains how you can enable trigger functionality on a Bitbucket Cloud instance. Learn more about Cloud Build triggers and Cloud Build repositories.

Before you begin

  • Enable the Cloud Build and Secret Manager APIs.

    Enable the APIs

Create a Bitbucket Cloud trigger

Create a Bitbucket Cloud trigger using the following steps:

Console

  1. Open the Triggers page:

    Open the Triggers page

  2. Select your Google Cloud project and click Open.

  3. Click Create trigger.

  4. Enter the following trigger settings:

    • Name: A name for your trigger.

    • Region: Select the region for your trigger.

      • If the build config file associated with the trigger specifies a private pool, Cloud Build uses the private pool to run your build. In this case, the region you specify in your trigger must match the region where you created your private pool.
      • If the build config file associated with the trigger does not specify a private pool, Cloud Build uses the default pool to run your build in the same region as your trigger.
    • Description (Optional): A description for your trigger.

    • Event: Select the repository event to invoke your trigger.

      • Push to a branch: Set your trigger to start a build on commits to a particular branch.

      • Push new tag: Set your trigger to start a build on commits that contain a particular tag.

      • Pull request: Set your trigger to start a build on commits to a pull request.

    • Source: Select 2nd gen as your source.

      • Repository: From the list of available repositories, select the repository. To connect a new repository, see Connect to a Bitbucket Cloud repository.

      • Branch or Tag: Specify a regular expression with the branch or tag value to match. For information on acceptable regular expression syntax, see RE2 syntax.

      • Comment control: If you selected Pull request as your Event, choose one of the following options to control whether a build is automatically be executed by the trigger:

        • Required except for owners and collaborators: When a pull request is created or updated by a repository owner or collaborator, builds are automatically executed by the trigger. If an external contributor initiates the action, builds are executed only after an owner or collaborator comments /gcbrun on the pull request.

        • Required: When a pull request is created or updated by any contributor, builds are executed only after an owner or collaborator comments /gcbrun on the pull request. Builds are executed each time a change to a pull request is made.

        • Not required: When a pull request is created or updated by any contributor, builds are automatically be executed by triggers.

    • Configuration: Select the build config file located in your repository or configure your build inline on the trigger.

    • Type: Select the type of configuration to use for your build.

      • Cloud Build configuration file (yaml or json): Use a build config file for your configuration.
      • Dockerfile: Use a Dockerfile for your configuration.
    • Location: Specify the location for your configuration.

      • Repository: If your config file is located in your repository, provide the location of your build config file or the Dockerfile directory and a name for the resulting image. If your configuration is a Dockerfile, you can optionally provide a timeout for your build. When you've provided the Dockerfile and image name, you'll see a preview of the docker build command for your build.

      • Inline: If you selected Cloud Build configuration file (yaml or json) as your configuration option, you can specify your build config inline. Click Open Editor to write your build config file in the Google Cloud console using YAML or JSON syntax. Click Done to save your build config.

  5. Click Create to create your Bitbucket Cloud trigger.

gcloud

Create a repository push event trigger using the following command:

gcloud builds triggers create bitbucket-cloud \
    --name=TRIGGER_NAME \
    --repository=\
    projects/PROJECT_ID/locations/REGION/connections/CONNECTION_NAME/repositories/REPO_NAME \
    --branch-pattern=".*" --build-config="CONFIG_NAME" \
    --region=REGION

Where:

  • TRIGGER-NAME is the name you want to give to your build trigger.
  • PROJECT_ID is your Google Cloud project ID.
  • REGION is the region for your trigger.
  • CONNECTION_NAME is the name of your host connection.
  • REPO_NAME is the name of your connected repository in Bitbucket Cloud.
  • CONFIG_NAME is the name of your configuration schema file.

After the trigger is created, Cloud Build listens to all push events on all branches. When you push any commit to the repository, the trigger is invoked. You can view build results in the Build history page.

Data sharing

The data sent to Bitbucket Cloud from Cloud Build helps you identify triggers by name and see build results on your Bitbucket Cloud repositories.

The following data is shared between Cloud Build and your Bitbucket Cloud host:

  • Google Cloud project ID
  • Trigger name

What's next