Skip to main content

Configure an agent with Bitbucket Cloud access

In order to view recipe results and commit changes from a recipe back to Bitbucket, you'll need to create an application link in Bitbucket and configure the Moderne agent with the appropriate variables.

To assist with that, this guide will:

Prerequisites

  • You will need access to create a Bitbucket OAuth Consumer

Bitbucket configuration

Step 1: Create a Bitbucket OAuth Consumer

Follow this Atlassian guide to create an OAuth Consumer.

Once that's done, configure the callback URL to point at your Moderne tenant:

Bitbucket Add OAuth consumer form with Name and Callback URL fields

The consumer should have these permissions:

Bitbucket OAuth consumer permissions with Account, Projects, Repositories, and Pull requests selected

  • Projects - Read
  • Repositories - Write
  • Pull requests - Write
  • Account - Read
  • Email - Read

Understanding the required permissions

The OAuth consumer requests the following permissions. Each permission is used for a specific set of operations:

PermissionRequiredPurpose
Projects - ReadYesUsed to verify the user has access to workspaces and list available repositories.
Repositories - WriteYesUsed to retrieve repository metadata, create forks, and push commits via Git-over-HTTP.
Pull requests - WriteYesUsed to create, update, close, merge, and approve pull requests, and to read pull request status and build results.
Account - ReadYesUsed to retrieve the authenticated user's identity (username and display name) so that Moderne can associate commits with the correct user.
Email - ReadYesUsed to read the user's email address for commit attribution.
Detailed list of Bitbucket Cloud API calls Moderne makes

User identity (Account and Email permissions):

API endpointMethodPurpose
/2.0/userGETRetrieve the authenticated user's profile
/2.0/user/emailsGETRetrieve the user's email addresses

Repository access checks (Projects - Read / Repositories):

API endpointMethodPurpose
/2.0/workspaces/{workspace}GETCheck whether a workspace exists
/2.0/repositories/{workspace}?page={page}&pagelen=100GETList repositories to verify access
/2.0/repositories/{workspace}/{repo}GETRetrieve repository details

Pull request operations (Pull requests - Write):

API endpointMethodPurpose
/2.0/repositories/{workspace}/{repo}/pullrequests?state=...&q=...GETFind existing pull request
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}GETGet pull request details
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}/statusesGETGet pull request build statuses
/2.0/repositories/{workspace}/{repo}/pullrequestsPOSTCreate pull request
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}PUTUpdate pull request
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}/approvePOSTApprove pull request
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}/declinePOSTClose pull request
/2.0/repositories/{workspace}/{repo}/pullrequests/{id}/mergePOSTMerge pull request
/2.0/repositories/{workspace}/{repo}/effective-default-reviewersGETGet default reviewers

Fork operations (Repositories - Write):

API endpointMethodPurpose
/2.0/repositories/{workspace}/{repo}/forksPOSTCreate fork
tip

The OAuth token is scoped to the individual user who authorizes it — Moderne can only perform actions that the user already has permission to do. The token does not grant Moderne any additional access beyond what the user themselves can do in Bitbucket.

Once your consumer has been created, you should see a key and a secret:

Bitbucket OAuth consumer details showing Key and Secret values

Please save those for use in Step 2.

Agent configuration

Step 2: Configure the Moderne agent

The following table contains all of the variables/arguments you need to add to your Moderne agent run command in order for it to work with your Bitbucket instance. Please note that these variables/arguments must be combined with ones found in other steps in the Configuring the Moderne agent guide.

Environment variables:

Variable NameRequiredDefaultDescription
MODERNE_AGENT_BITBUCKET_CLOUD_OAUTH_KEYtrueThe key specified in your Bitbucket OAuth consumer.
MODERNE_AGENT_BITBUCKET_CLOUD_OAUTH_SECRETtrueThe secret specified in your Bitbucket OAuth consumer.

Example:

docker run \
# ... Existing variables
-e MODERNE_AGENT_BITBUCKET_CLOUD_OAUTH_KEY=yourOAuthKey \
-e MODERNE_AGENT_BITBUCKET_CLOUD_OAUTH_SECRET=yourSecretKey \
# ... Additional variables