AWS CodeBuild
User Guide (API Version 2016-10-06)

The procedures in this guide support the new console design. If you choose to use the older version of the console, you will find many of the concepts and basic procedures in this guide still apply. To access help in the new console, choose the information icon.

Bitbucket Pull Request Sample for AWS CodeBuild

This sample shows you how to create a pull request using a Bitbucket repository. It also shows you how to use a Bitbucket webhook to trigger AWS CodeBuild to create a build of a project.

Bitbucket Pull Request Prerequisites

To run this sample you must connect your AWS CodeBuild project with your Bitbucket account.

Note

AWS CodeBuild has updated its permissions with Bitbucket. If you previously connected your project to Bitbucket and now receive a Bitbucket connection error, you must reconnect to grant AWS CodeBuild permission to manage your webhooks.

Create a Build Project with Bitbucket as the Source Repository and Enable Webhooks

The following steps describe how to create an AWS CodeBuild project with Bitbucket as a source repository and enable webhooks.

  1. Open the AWS CodeBuild console at https://console.aws.amazon.com/codesuite/codebuild/home.

  2. If an AWS CodeBuild information page is displayed, choose Create project. Otherwise, on the navigation pane, expand Build, and then choose Build projects.

  3. On the Create build project page, in Project configuration, for Project name, enter a name for this build project. Build project names must be unique across each AWS account. You can also include an optional description of the build project to help other users understand what this project is used for.

  4. In Source, for Source provider, choose Bitbucket. Follow the instructions to connect or reconnect, and then choose Grant access.

  5. Choose Use a repository in my account. You cannot use a webhook if you use a public Bitbucket repository.

  6. For Webhook, select Rebuild every time a code change is pushed to this repository

    Note

    If a build is triggered by a Bitbucket webhook, the Report build status setting is ignored. The build status is always sent to Bitbucket.

  7. Choose other settings for your project. For more information about source provider options and settings, see Choose source provider.

  8. Choose Create build project. On the Review page, choose Start build to run the build.

Trigger a Build with a Bitbucket Webhook

For a project that uses Bitbucket webhooks, AWS CodeBuild creates a build when the Bitbucket repository detects a change in your source code.

  1. Open the AWS CodeBuild console at https://console.aws.amazon.com/codesuite/codebuild/home.

  2. On the navigation pane, choose Build projects, and then choose a project associated with a Bitbucket repository with webhooks. For information about creating a Bitbucket webhook project, see Create a Build Project with Bitbucket as the Source Repository and Enable Webhooks.

  3. Make some changes in the code in your project's Bitbucket repository.

  4. Create a pull request on your Bitbucket repository. For more information, see Making a Pull Request.

  5. In the Bitbucket webhooks page, choose View request to see a list of recent events.

  6. In the Bitbucket webhooks page, choose View details to see details about the response returned by AWS CodeBuild. It might look something like this:

    "response":"Webhook received and buld started: https://us-east-1.console.aws.amazon.com/codebuild/home..." "statusCode":200
  7. Navigate to the Bitbucket pull request page to see the status of the build.