Working with Bitbucket Cloud
QuickBuild integrates with Bitbucket cloud via the Bitbucket Cloud repository. This repository has all features of a normal Git repository, but add the ability to build against open pull requests, and update pull request status based on build result.
Build against pull requests
To build against pull requests, define a Bitbucket Cloud repository like below:
In repository definition, tick the build open pull requests option like below:
Upon triggering of configuration using such repository, QuickBuild will first find all open pull requests at Bitbucket side and then fire separate build request(s) for each open pull request to check changes against that pull request, and build that pull request if necessary. So if there are many open pull requests, many build requests will be fired. So it is best practice to enable concurrent build to speed up verification of multiple pull requests.
As demonstrated below, each finished build will display associated pull request as branch information and changes of the build will be calculated against previous build with the same pull request branch.
Upon manual triggering of such configuration, all matched pull requests will be built even if they've not being updated, just like what QuickBuild behaves when trigger configurations using normal repositories. However if you schedule the configuration and set build condition to If changes found in referenced repositories (or something similar), QuickBuild will only build against new/updated pull requests.
Update pull request status at Bitbucket side based on build status
QuickBuild will update pull request status automatically to reflect build status when build is started/finished, as demonstrated below:
BitBucket Cloud Webhook Integration
To use BitBucket Cloud webhook, first, you need ensure you have anonymous group added with REST API access permission.
Config Webhook on bitbucket.org
Go to your repository settings page on bitbucket.org, then config webhook settings:
Here, the URL for QuickBuild is in below format:
http://your-qb-server:8810/rest/webhook/bitbucket.org/{configurationId}?secret={my_webhook_secret}
Config Webhook on QuickBuild
Add anonymous group
As the webhook is triggered without authentication, anonymous group should be added and it should have the permission to use RESTful API.
Add webhook settings
To add integration at QuickBuild side, please go to configuration settings page and then choose Webhook -> bitbucket.org from right side menu:
Then, you can add the settings:
- Trigger User the user to trigger the build
- Webhook Secret the secret should be the same as what you defined in BitBucket webhook URL in secret query param.
- Trigger Condition the trigger condition in Groovy scripts, when the result is true, build will be triggered, otherwise, the build will not be triggered.
- Trigger Events the events which are allowed to trigger the build.
Event Payload
For detailed event payload please refer to below page:
https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/
You can use the payload data in the script. For example, in "Trigger Condition", you can use payload data via delivery object:
if ("repo:push".equals(event)) {
return delivery.actor.account_id == "5555555:77771777-2222-4ta6-bbbb-da3f0b740476";
} else {
return false;
}
You can define Trigger Build Variables in the webhook settings, and then use those variables in configuration settings just like other variables. When define the variables, script is also supported, so the payload data can also be used via delivery object, for example:
if (event.startsWith("pr:")) {
return delivery.pullRequest.fromRef.id;
} else {
return "main";
}