Bitbucket App connections
You can use Bitbucket to connect with CodeBuild. Bitbucket App connections are supported through Amazon CodeConnections.
Note
CodeConnections is available in fewer regions than CodeBuild. You can use cross-region connections in CodeBuild. Connections created in opt-in Regions cannot be used in other Regions. For more information, see Amazon CodeConnections endpoints and quotas.
Topics
Step 1: Create a connection to Bitbucket (console)
Use these steps to use the CodeBuild console to add a connection for your project in Bitbucket.
To create a connection to Bitbucket
-
Follow the instructions in the Developer Tools User Guide for Create a connection to Bitbucket.
Note
Instead of creating or using an existing connection in your account, you can use a connection shared from another Amazon account. For more information, see Share connections with Amazon accounts.
Step 2: Grant CodeBuild project IAM role access to use the connection
You can grant CodeBuild project IAM role access to use the Bitbucket tokens vended by your connection.
To grant CodeBuild project IAM role access
-
Create an IAM role for your CodeBuild project by following the instructions to Allow CodeBuild to interact with other Amazon services for your CodeBuild project.
-
While following the instructions, add the following IAM policy to your CodeBuild project role to grant access to the connection.
Step 3: Configure CodeBuild to use the new connection
You can configure a connection as an account level credential and use it in a project.
For more information about setting up multiple tokens in your CodeBuild project, see Configure multiple tokens as source level credentials.
Bitbucket OAuth rotating refresh tokens
Atlassian now enforces single-use rotating refresh tokens for Bitbucket OAuth.
Each time you use a refresh token, Bitbucket invalidates it and returns a new one.
For more information, see
Bitbucket OAuth single-use refresh tokens (CHANGE-3052)
Required action for Secrets Manager-stored credentials
If you store Bitbucket OAuth credentials in Secrets Manager, add the
secretsmanager:PutSecretValue permission to your CodeBuild service role.
With this permission, CodeBuild can write the updated refresh token back to your secret
after each token refresh. Without this permission, the next build after a token
refresh fails.
The following example IAM policy statement grants the required permission:
{ "Effect": "Allow", "Action": "secretsmanager:PutSecretValue", "Resource": "arn:aws:secretsmanager:*:*:secret:codebuild/*" }
If you use the CodeBuild-managed option, no changes are needed. CodeBuild handles token rotation automatically.
Migrate to Amazon CodeConnections (recommended)
We recommend migrating to Amazon CodeConnections for Bitbucket integration. Amazon CodeConnections uses a separate authorization mechanism that rotating refresh tokens do not affect. You don't need to manage tokens or add permissions.
To migrate to Amazon CodeConnections, complete the following steps:
-
Open the Developer Tools console. Choose Settings, Connections, then Create connection. Select Bitbucket as the provider.
-
Authorize the Amazon CodeConnections app in your Bitbucket workspace. This requires Administer workspace permission in Bitbucket.
-
Add the following permissions to your CodeBuild service role:
codeconnections:GetConnectionTokenandcodeconnections:GetConnection. -
Set the connection as your default credential:
aws codebuild import-source-credentials --auth-type CODECONNECTIONS --server-type BITBUCKET --token<connection-arn> -
All projects using the default credential switch automatically. Update projects that use custom, per-project credentials individually. Use the console or the
UpdateProjectAPI.