Bitbucket Cloud

Site admins can sync Git repositories hosted on Bitbucket Cloud with Sourcegraph so that users can search and navigate the repositories.

To connect Bitbucket Cloud to Sourcegraph:

  1. Go to Site admin > Manage code hosts > Add repositories.
  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 Cmd/Ctrl+Space for auto-completion. See the configuration documentation below.
  4. Press Add repositories.

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
    A list of teams (workspaces) that the configured user has access to whose repositories should be synced.
  • exclude
    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.
  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:

{
  "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:

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

HTTPS cloning

Sourcegraph clones repositories from your Bitbucket Cloud via HTTP(S), using the username and appPassword required fields you provide in the configuration.

Rate limits

Read about how Bitbucket Cloud applies rate limits here.

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

User authentication

To configure Bitbucket Cloud as an authentication provider (which will enable sign-in via Bitbucket Cloud), see the authentication documentation.

Repository permissions

Prerequisite: Add Bitbucket Cloud as an authentication provider.

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

{
  // 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": {}
}

Configuration

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

admin/external_service/bitbucket_cloud.schema.json

{
	// The workspace access token to use when authenticating with Bitbucket Cloud.
	"accessToken": 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.
	"apiURL": null,
	// Other example values:
	// - "https://api.bitbucket.org"

	// The app password to use when authenticating to the Bitbucket Cloud. Also set the corresponding "username" field.
	"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": 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}"}).
	"exclude": null,
	// Other example values:
	// - [
	//     {
	//       "name": "myorg/myrepo"
	//     },
	//     {
	//       "uuid": "{fceb73c7-cef6-4abe-956d-e471281126bc}"
	//     }
	//   ]
	// - [
	//     {
	//       "name": "myorg/myrepo"
	//     },
	//     {
	//       "name": "myorg/myotherrepo"
	//     },
	//     {
	//       "pattern": "^topsecretproject/.*"
	//     }
	//   ]

	// 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 [email protected]: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.
	"gitURLType": "http",
	// Other example values:
	// - "ssh"

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

	// 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.
	"teams": null,
	// Other example values:
	// - ["name"]
	// - [
	//     "kubernetes",
	//     "golang",
	//     "facebook"
	//   ]

	// 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.
	"url": null,
	// Other example values:
	// - "https://bitbucket.org"

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

	// A shared secret used to authenticate incoming webhooks (minimum 12 characters).
	"webhookSecret": null
}

Webhooks

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

Please consult this page in order to configure webhooks.