# Bitbucket Cloud

<TierCallout>
	Supported on [Enterprise](/pricing/plans/enterprise) plans.
	<user>Available via the Web app.</user>
</TierCallout>

Site admins can sync Git repositories hosted on [Bitbucket Cloud](https://bitbucket.org) with Sourcegraph so that users can search and navigate the repositories.

To connect Bitbucket Cloud to Sourcegraph:

1. Go to **Site admin > Code host connections > Add connection**.
2. Select **Bitbucket.org**.
3. Configure the connection to Bitbucket Cloud using the action buttons above the text field. Additional fields can be added using <kbd>Cmd/Ctrl+Space</kbd> for auto-completion. See the [configuration documentation below](#configuration).
4. Press **Add connection**.

## Repository syncing

Currently, all repositories belonging to the user configured will be synced.

In addition, there is one more field for configuring which repositories are mirrored:

-   [`teams`](/admin/code-hosts/bitbucket-cloud#configuration)
    A list of teams (workspaces) that the configured user has access to whose repositories should be synced.
-   [`exclude`](/admin/code-hosts/bitbucket-cloud#configuration)
    A list of repositories to exclude, which takes precedence over the `teams` field.

## Configuration options

Bitbucket Cloud code host connections can be configured with either a username and app password combination, or with workspace access tokens.

### Username and app password

1. Visit your [Bitbucket account settings page](https://bitbucket.org/account/settings).
2. Navigate to **App passwords**.
3. Select **Create app password**.
4. Give your app password a label.
5. Select the `Projects: Read` permission. `Repositories: Read` should automatically be selected.
6. Press **Create**.

Use the newly created app password and your username to configure the Bitbucket Cloud connection:

```json
{
	"url": "https://bitbucket.org",
	"username": "USERNAME",
	"appPassword": "<PASSWORD>"
	// ... other settings
}
```

### Workspace access token

1. Visit the Bitbucket Cloud workspace settings page of the workspace you want to create an access token for.
2. Navigate to **Security > Access tokens**.
3. Press **Create workspace access token**.
4. Give your access token a name.
5. Select the `Projects: Read` permission. `Repositories: Read` should automatically be selected.
6. Press **Create**.

Use the newly created access token to configure the Bitbucket Cloud connection:

```json
{
	"url": "https://bitbucket.org",
	"accessToken": "ACCESS_TOKEN"
	// ... other settings
}
```

### HTTPS cloning

Sourcegraph clones repositories from your Bitbucket Cloud via HTTP(S), using the [`username`](/admin/code-hosts/bitbucket-cloud#configuration) and [`appPassword`](/admin/code-hosts/bitbucket-cloud#configuration) required fields you provide in the configuration.

## Rate limits

Read about how Bitbucket Cloud applies rate limits [here](https://support.atlassian.com/bitbucket-cloud/docs/api-request-limits/).

When Sourcegraph encounters rate limits on Bitbucket Cloud, it will retry the request with exponential back-off, until 5 minutes have passed. If the connection is still being rate limited after 5 minutes, the request will be dropped.

### Internal rate limits

See [Internal rate limits](/admin/code-hosts/rate-limits#internal-rate-limits)

## User authentication

To configure Bitbucket Cloud as an authentication provider (which will enable sign-in via Bitbucket Cloud), see the
[authentication documentation](/admin/auth/#bitbucket-cloud).

## Repository permissions

Prerequisite: [Add Bitbucket Cloud as an authentication provider](#user-authentication).

Then, add or edit a Bitbucket Cloud connection as described above and include the `authorization` field:

```json
{
	// The URL used to set up the Bitbucket Cloud authentication provider must match this URL.
	"url": "https://bitbucket.com",
	"username": "horsten",
	"appPassword": "$APP_PASSWORD",
	// ...
	"authorization": {}
}
```

> NOTE: It can take some time to complete full cycle of repository permissions sync if you have a large number of users or repositories. [See sync duration time](/admin/permissions/syncing#sync-duration) for more information.

## Configuration

Bitbucket Cloud connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.

{/* <div markdown-func=jsonschemadoc jsonschemadoc:path="admin/code_hosts/bitbucket_cloud.schema.json">[View page on our docs](/admin/code-hosts/bitbucket-cloud) to see rendered content.</div> */}

### admin/code_hosts/bitbucket_cloud.schema.json

{/* SCHEMA_SYNC_START: admin/code_hosts/bitbucket_cloud.schema.json */}
{/* WARNING: This section is auto-generated during releases. Do not edit manually. */}
{/* Last updated: 2026-04-02T18:35:11Z */}
```json
{
	// The workspace access token to use when authenticating with Bitbucket Cloud.
	"accessToken": null,

	// The API token to use when authenticating with Bitbucket Cloud.
	"apiToken": null,

	// The API URL of Bitbucket Cloud, such as https://api.bitbucket.org. Generally, admin should not modify the value of this option because Bitbucket Cloud is a public hosting platform.
	// Other example values:
	// - "https://api.bitbucket.org"
	"apiURL": null,

	// The app password to use when authenticating to the Bitbucket Cloud. Also set the corresponding "username" field.
	// 🚨 NOTE 🚨: Please use the "apiToken" field instead of this field, since Bitbucket Cloud is deprecating app passwords as of June 9, 2026. See https://www.atlassian.com/blog/bitbucket/bitbucket-cloud-transitions-to-api-tokens-enhancing-security-with-app-password-deprecation for more details.
	"appPassword": null,

	// If non-null, enforces Bitbucket Cloud repository permissions. This requires that there is an item in the [site configuration json](https://sourcegraph.com/docs/admin/config/site_config#auth-providers) `auth.providers` field, of type "bitbucketcloud" with the same `url` field as specified in this `BitbucketCloudConnection`.
	"authorization": {
		"identityProvider": null
	},

	// A list of repositories to never mirror from Bitbucket Cloud. Takes precedence over "teams" configuration.
	// Supports excluding by name ({"name": "myorg/myrepo"}) or by UUID ({"uuid": "{fceb73c7-cef6-4abe-956d-e471281126bd}"}).
	// Other example values:
	// - [
	//     {
	//       "name": "myorg/myrepo"
	//     },
	//     {
	//       "uuid": "{fceb73c7-cef6-4abe-956d-e471281126bc}"
	//     }
	//   ]
	// - [
	//     {
	//       "name": "myorg/myrepo"
	//     },
	//     {
	//       "name": "myorg/myotherrepo"
	//     },
	//     {
	//       "pattern": "^topsecretproject/.*"
	//     }
	//   ]
	"exclude": null,

	// SSH cipher to use when cloning via SSH. Must be a valid choice from `ssh -Q cipher`.
	"gitSSHCipher": null,

	// SSH keys to use when cloning Git repo.
	"gitSSHCredential": null,

	// The type of Git URLs to use for cloning and fetching Git repositories on this Bitbucket Cloud.
	// If "http", Sourcegraph will access Bitbucket Cloud repositories using Git URLs of the form https://bitbucket.org/myteam/myproject.git.
	// If "ssh", Sourcegraph will access Bitbucket Cloud repositories using Git URLs of the form git@bitbucket.org:myteam/myproject.git. See the documentation for how to provide SSH private keys and known_hosts: https://sourcegraph.com/docs/admin/repo/auth#repositories-that-need-http-s-or-ssh-authentication.
	// Valid options: "http", "ssh"
	// Other example values:
	// - "ssh"
	"gitURLType": "http",

	// The maximum number of repos that will be deleted per sync. A value of 0 or less indicates no maximum.
	"maxDeletions": 0,

	// Rate limit applied when making background API requests to Bitbucket Cloud.
	"rateLimit": {
		"enabled": true,
		"requestsPerHour": 7200
	},

	// An array of repository "projectKey/repositorySlug" strings specifying repositories to mirror on Sourcegraph.
	// Other example values:
	// - [
	//     "myproject/myrepo",
	//     "myproject/myotherrepo"
	//   ]
	"repos": null,

	// The pattern used to generate the corresponding Sourcegraph repository name for a Bitbucket Cloud repository.
	// - "{host}" is replaced with the Bitbucket Cloud URL's host (such as bitbucket.org),  and "{nameWithOwner}" is replaced with the Bitbucket Cloud repository's "owner/path" (such as "myorg/myrepo").
	// For example, if your Bitbucket Cloud is https://bitbucket.org and your Sourcegraph is https://src.example.com, then a repositoryPathPattern of "{host}/{nameWithOwner}" would mean that a Bitbucket Cloud repository at https://bitbucket.org/alice/my-repo is available on Sourcegraph at https://src.example.com/bitbucket.org/alice/my-repo.
	// It is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined.
	"repositoryPathPattern": "{host}/{nameWithOwner}",

	// An array of team names identifying Bitbucket Cloud teams whose repositories should be mirrored on Sourcegraph.
	// Other example values:
	// - [
	//     "name"
	//   ]
	// - [
	//     "kubernetes",
	//     "golang",
	//     "facebook"
	//   ]
	"teams": null,

	// REQUIRED:
	// URL of Bitbucket Cloud, such as https://bitbucket.org. Generally, admin should not modify the value of this option because Bitbucket Cloud is a public hosting platform.
	// Other example values:
	// - "https://bitbucket.org"
	"url": null,

	// The username to use when authenticating to the Bitbucket Cloud. Also set the corresponding "appPassword" field.
	"username": null,

	// ⚠️  DEPRECATED: DEPRECATED: See https://sourcegraph.com/docs/admin/config/webhooks/incoming#deprecation-notice
	// DEPRECATED: See https://sourcegraph.com/docs/admin/config/webhooks/incoming#deprecation-notice
	"webhookSecret": null
}
```
{/* SCHEMA_SYNC_END: admin/code_hosts/bitbucket_cloud.schema.json */}

## Webhooks

Using the `webhooks` property on the external service has been deprecated.

Please consult [this page](/admin/webhooks/incoming) in order to configure webhooks.
