Site admins can sync Git repositories hosted on Bitbucket Server / Bitbucket Data Center (and the Bitbucket Data Center deployment option) with Sourcegraph so that users can search and navigate the repositories.
To connect Bitbucket Server / Bitbucket Data Center to Sourcegraph:
- Go to Site admin > Manage repositories > Add repositories
- Select Bitbucket Server / Bitbucket Data Center.
- Configure the connection to Bitbucket Server / Bitbucket Data Center using the action buttons above the text field, and additional fields can be added using Cmd/Ctrl+Space for auto-completion. See the configuration documentation below.
- Press Add repositories.
Also consider installing the Sourcegraph Bitbucket Server plugin which enables native code intelligence for every Bitbucket user when browsing code and reviewing pull requests, allows for faster permission syncing between Sourcegraph and Bitbucket Server / Bitbucket Data Center and adds support for webhooks to Bitbucket Server / Bitbucket Data Center.
Sourcegraph requires a Bitbucket Server / Bitbucket Data Center personal access token with read permissions to sync repositories.
When using batch changes the access token needs write permissions on the project and repository level. See "Code host interactions in batch changes" for details.
You can create a personal access token at https://[your-bitbucket-hostname]/plugins/servlet/access-tokens/add. Also set the corresponding username field.
For Bitbucket Server instances that don't support personal access tokens (Bitbucket Server version 5.4 and older), specify user-password credentials in the username and password fields.
There are four fields for configuring which repositories are mirrored:
repos
A list of repositories inprojectKey/repositorySlugformat. The order determines the order in which we sync repository metadata and is safe to change.repositoryQuery
A list of strings with some pre-defined options (none,all), and/or a Bitbucket Server / Bitbucket Data Center Repo Search Request Query Parameters.exclude
A list of repositories to exclude which takes precedence over therepos, andrepositoryQueryfields.excludePersonalRepositories
With this enabled, Sourcegraph will exclude any personal repositories from being imported, even if it has access to them.
The Sourcegraph Bitbucket Server plugin enables the Bitbucket Server / Bitbucket Data Center instance to send webhooks to Sourcegraph.
Using webhooks is highly recommended when using batch changes, since they speed up the syncing of pull request data between Bitbucket Server / Bitbucket Data Center and Sourcegraph and make it more efficient.
To set up webhooks:
- Connect Bitbucket Server / Bitbucket Data Center to Sourcegraph (see instructions above).
- Install the Sourcegraph Bitbucket Server plugin on your Bitbucket Server / Bitbucket Data Center instance.
- In Sourcegraph, go to Site admin > Manage repositories and edit the Bitbucket Server / Bitbucket Data Center configuration.
- Add the
"webhooks"property to"plugin"(you can generate a secret withopenssl rand -hex 32):
"plugin": {"webhooks": {"secret": "verylongrandomsecret"}} - Click Update repositories.
- Note the webhook URL displayed below the Update repositories button.
- On your Bitbucket Server / Bitbucket Data Center instance, go to Administration > Add-ons > Sourcegraph
- Fill in the Add a webhook form
- Name: A unique name representing your Sourcegraph instance
- Scope:
global - Endpoint: The URL from step 6
- Events:
pr, repo - Secret: The secret you configured in step 4
- Confirm that the new webhook is listed under All webhooks with a timestamp in the Last successful column.
Done! Sourcegraph will now receive webhook events from Bitbucket Server / Bitbucket Data Center and use them to sync pull request events, used by batch changes, faster and more efficiently.
By default, all Sourcegraph users can view all repositories. To configure Sourcegraph to use Bitbucket Server / Bitbucket Data Center's repository permissions, see Repository permissions.
With the Sourcegraph Bitbucket Server you can enable fast permission syncing:
- Connect Bitbucket Server / Bitbucket Data Center to Sourcegraph (see instructions above).
- Follow the instructions to set up repository permissions with Bitbucket Server / Bitbucket Data Center.
- Install the Sourcegraph Bitbucket Server plugin on your Bitbucket Server / Bitbucket Data Center instance.
- In Sourcegraph, go to Site admin > Manage repositories and edit the Bitbucket Server / Bitbucket Data Center configuration.
- Add the
"plugin.permissions"property:
{
// [...]
"plugin": {
"permissions": "enabled"
}
}Bitbucket Server / Bitbucket Data Center versions older than v5.5 require specifying a less secure username and password combination, as those versions of Bitbucket Server / Bitbucket Data Center do not support personal access tokens.
Sourcegraph by default clones repositories from your Bitbucket Server / Bitbucket Data Center via HTTP(S), using the access token or account credentials you provide in the configuration. The username field is always used when cloning, so it is required.
Sourcegraph will mark repositories as archived if they have the archived label on Bitbucket Server / Bitbucket Data Center. You can exclude these repositories in search with archived:no search syntax.
Internal rate limiting can be configured to limit the rate at which requests are made from Sourcegraph to Bitbucket Server / Bitbucket Data Center.
If enabled, the default rate is set at 28,800 per hour (8 per second) which can be configured via the requestsPerHour field (see below). If rate limiting is configured more than once for the same code host instance, the most restrictive limit will be used.
NOTE Internal rate limiting is only currently applied when synchronising changesets in batch changes, repository permissions and repository metadata from code hosts.
Bitbucket Server / Bitbucket Data Center connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage repositories" area.