Site admins can sync Git repositories hosted on Bitbucket Server (and the Bitbucket Data Center deployment option) with Sourcegraph so that users can search and navigate the repositories.
To connect Bitbucket Server to Sourcegraph:
- Go to Site admin > Manage repositories > Add repositories
- Select Bitbucket Server.
- Configure the connection to Bitbucket Server 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 and adds support for webhooks to Bitbucket Server.
There are four fields for configuring which repositories are mirrored:
repos
A list of repositories inprojectKey/repositorySlugformat.repositoryQuery
A list of strings with some pre-defined options (none,all), and/or a Bitbucket Server 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 instance to send webhooks to Sourcegraph.
Using webhooks is highly recommended when using Campaigns, since they speed up the syncing of pull request data between Bitbucket Server and Sourcegraph and make it more efficient.
To set up webhooks:
- Connect Bitbucket Server to Sourcegraph (see instructions above).
- Install the Sourcegraph Bitbucket Server plugin on your Bitbucket Server instance.
- In Sourcegraph, go to Site admin > Manage repositories and edit the Bitbucket Server configuration.
- Add the
"webhooks"property to"plugin"(you can generate a secret withopenssl rand -hex 32):
"plugin": {"webhooks": {"secret": "verylongrandomsecret"}} - Click Update repositories.
- Sourcegraph now automatically creates a webhook on your Bitbucket Server instance with the name
sourcegraph-, followed by the unique ID of your Sourcegraph instance. It is configured to deliverprandrepoevents. - On your Bitbucket Server instance, go to Administration > Add-ons > Sourcegraph and make sure that the new
sourcegraph-campaignswebhook is listed under All webhooks with a timestamp in the Last successful column.
Done! Sourcegraph will now receive webhook events from Bitbucket Server and use them to sync pull request events, used by Campaigns, fast and more efficiently.
By default, all Sourcegraph users can view all repositories. To configure Sourcegraph to use Bitbucket Server's repository permissions, see Repository permissions.
With the Sourcegraph Bitbucket Server plugin you can enable fast permission syncing:
- Connect Bitbucket Server to Sourcegraph (see instructions above).
- Follow the instructions to set up repository permissions with Bitbucket Server.
- Install the Sourcegraph Bitbucket Server plugin on your Bitbucket Server instance.
- In Sourcegraph, go to Site admin > Manage repositories and edit the Bitbucket Server configuration.
- Add the
"plugin.permissions"property:
{
// [...]
"plugin": {
"permissions": "enabled"
}
}Bitbucket Server versions older than v5.5 require specifying a less secure username and password combination, as those versions of Bitbucket Server do not support personal access tokens.
Sourcegraph by default clones repositories from your Bitbucket Server 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. You can exclude these repositories in search with archived:no search syntax.
Bitbucket Server connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage repositories" area.