Bitbucket Cloud

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

To set this up, add Bitbucket Cloud as an external service to Sourcegraph:

  1. Go to User menu > Site admin.
  2. Open the External services page.
  3. Press + Add external service.
  4. In the list, select Bitbucket.org repositories.
  5. Enter a Display name (using "Bitbucket Cloud" is OK).
  6. Configure the connection to Bitbucket Cloud in the JSON editor. Use Cmd/Ctrl+Space for completion, and see configuration documentation below.
  7. Press Add external service.

Repository syncing

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

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

  • teams
    A list of teams 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.

HTTPS cloning

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

Configuration

Bitbucket Cloud external service connections support the following configuration options, which are specified in the JSON editor in the site admin external services area.

admin/external_service/bitbucket_cloud.schema.json

{
	// The app password to use when authenticating to the Bitbucket Cloud. Also set the corresponding "username" field.
	"appPassword": 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://docs.sourcegraph.com/admin/repo/auth#repositories-that-need-http-s-or-ssh-authentication.
	"gitURLType": "http",
	// Other example values:
	// - "ssh"

	// 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.
	"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
}