Important
|
On March 5th, 2020, Atlassian releases Bitbucket Server 7 which removed some undocumented features with regards to pull requests.
|
CloudBees Bitbucket Branch Source plugin (Bitbucket plugin up now) allows use of Bitbucket Cloud and Server as a multi-branch project source in two different ways:
-
Single repository source: automatic creation of jobs for branches and pull requests in a specific repository.
-
Team/Project folders: automatic creation of multi-branch projects for each visible repository in a specific Bitbucket Team or Project.
IMPORTANT: This plugin is not compatible with versions of Bitbucket Server previous to 4.0.
BitBucket Server 7.x is supported but does no longer support lightweight checkout for pull requests when merge strategy is used for build.
Important
|
In order to have the pull request process working the "Call Changes api" option must be enabled in Manage Jenkins » Configure System |
This plugin adds an additional item in the "Branch Sources" list of multi-branch projects. Once configured, branches and pull requests are automatically created and built as branches in the multi-branch project.
Follow these steps to create a multi-branch project with Bitbucket as a source:
-
Create the multi-branch project. This step depends on which multi-branch plugin is installed. For example, "Multibranch Pipeline" should be available as project type if Pipeline Multibranch plugin is installed.
-
Select "Bitbucket" as Branch Source
-
Set credentials to access Bitbucket API and checkout sources (see "Credentials configuration" section below).
-
Set the repository owner and name that will be monitored for branches and pull requests.
-
If using Bitbucket Server the server base URL needs to be configured (expand the Advanced section to do it).
-
Finally, save the project. The initial indexing process will run and create projects for branches and pull requests.
Bitbucket Team/Project Folders project type can be used to automatically track branches and pull requests in all repositories in a Bitbucket Team or Project.
-
Create a project of type Bitbucket Team/Project. The project name will be proposed automatically as default Owner (or Team) name.
-
Configure the repository owner (if the proposed value does not match with the actual team or username). It could be:
-
A Bitbucket Cloud Team name: all repositories in the team are imported as Multibranch projects.
-
A Bitbucket Server Project ID: all repositories in the project are imported as Multibranch projects. Note that the project ID needs to be used instead of the project name.
-
A regular username: all repositories which the username is owner of are imported.
-
-
Save the configuration and an initial indexing process starts, once it finishes a Multibranch project is created for each repository.
The use of Bitbucket webhooks allows to trigger builds on branches and pull requests just when a new commit is done. Bitbucket plugin expose a special service to listen to this webhook requests and acts accordingly by triggering a new reindex and finally triggering builds on matching branches or pull requests.
For both Bitbucket Multibranch projects and Bitbucket Team projects there is an option in the configuration page to let Jenkins to automatically register the webhooks in all involved repositories.
Important
|
In order to have the auto-registering process working fine the Jenkins base URL must be properly configured in Manage Jenkins » Configure System |
The configuration of Bitbucket plugin (for both Bitbucket Multibranch projects and Bitbucket Team/Project) has two credentials to configure:
-
Scan Credentials: credentials used to access Bitbucket API in order to discover repositories, branches and pull requests. If not set then anonymous access is used, so only public repositories, branches and pull requests are discovered and managed. Note that the Webhooks auto-register feature requires scan credentials to be set. Only HTTP or OAuth credentials are accepted in this field.
-
Checkout Credentials: credentials used to checkout sources once the repository, branch or pull request is discovered. HTTP, SSH and OAuthcredentials are allowed. If not set then Scan Credentials are used.
Bitbucket plugin can make use of OAuth credentials instead of the standard username/password.
First create a new OAuth consumer as instructed in Bitbucket OAuth Documentation. Don’t forget to check This is a private consumer and at least allow read access to the repositories and Pull requests. If you want the Bitbucket to install the Webhooks also allow the read and write access of the Webhooks
Then create new Username with password credentials, enter the Bitbucket OAuth consumer key in Username field and the Bitbucket OAuth consumer secret in Password field
In case of slow network, you can increase socket timeout using the Script Console :
System.setProperty("http.socket.timeout", "300") // 5 minutes