Every time you trigger a build, you don't have to log in to your build server to see if it passed or failed. Now you will be able to know when your build is passing right within the Bitbucket UI.
Features
Notify to Bitbucket Cloud for the following build events:
-
Build start
-
Build finish
This plugin aims at the Atlassian-hosted BitBucket Cloud solution, not BitBucket Server (formerly known as Stash).
Configuration
Create a OAuth Consumer
First you need to get a OAuth consumer key/secret from Bitbucket.
- Login into your Bitbucket account.
- Click your account name and then in Settings from the menu bar.
- Click OAuth from the menu bar.
- Press the Add consumer button.
- The system requests the following information:
- Give a representative name to the consumer e.g. Jenkins build status notifier.
- Although is not used, a Callback URL must be set e.g. ci.your-domain.com.
- Leave blank the URL field.
- Add Read and Write permissions to Repositories.
- Click Save button and a Key and Secret will be automatically generated.
Ensure Jenkins URL is set
Second, ensure that Jenkins URL is properly set:
- Open Jenkins Manage Jenkins page.
- Click Configure System page.
- Go to the section Jenkins Location.
- Set the correct URL to Jenkins URL.
- Click Save button.
Add OAuth Credentials to Jenkins
Third, you need to add the Bitbucket OAuth Consumer credentials. You have two ways to configure it globally or locally:
Global
- Open Jenkins Manage Jenkins page.
- Click Configure System.
- Go to the section Bitbucket Build Status Notifier plugin.
- If you still don't have stored the credentials click Add,
otherwise you can skip this step.
- Select Username with password.
- Set the the OAuth consumer key in Username.
- Set the the OAuth consumer secret in Password.
- Click Add button.
- Select the desired credentials.
- Click Save button.
Local
- Go to the Job you want notifies the builds to Bitbucket.
- Click Configure.
- Click Add post-build action.
- Select Bitbucket notify build status.
- Click Advanced button.
- If you still don't have stored the credentials click Add,
otherwise you can skip this step.
- Select Username with password.
- Set the the OAuth consumer key in Username.
- Set the the OAuth consumer secret in Password.
- Click Add button.
- Select the desired credentials.
Pipeline Projects
Once you have configured the credential, you can notify BitBucket from your Pipeline script through the bitbucketStatusNotify step.
Usage
The bitbucketStatusNotify step notifies the status of a build identified by a build key and build name to BitBucket (see all options under API). If buildKey and buildName parameters are not provided, a standard name will be assigned to the build (NameOfYourJob #numberOfBuild - eg. MyProject #32).
...
bitbucketStatusNotify(buildState: 'INPROGRESS')
try {
// do your job logic
} catch (Exception e) {
bitbucketStatusNotify(buildState: 'FAILED')
}
bitbucketStatusNotify(buildState: 'SUCCESSFUL')
...
API
The bitbucketStatusNotifiy step allows the following parameters:
Name | Type | Optional | Description |
---|---|---|---|
buildState | "INPROGRESS"|"SUCCESSFUL"|"FAILED" | no | The status of the current build phase |
buildKey | String | yes | The unique key identifying the current build phase |
buildName | String | yes | The build phase's name shown on BitBucket |
buildDescription | String | yes | The build phase's description shown on BitBucket |
Freestyle Projects
Once you have configured the credentials, configure jenkins to notify Bitbucket.
- Go to the Job you want notifies the builds to Bitbucket.
- Click Configure.
- Select Bitbucket notify build status.
- Choose whether you want to notify the build status on Jenkins to Bitbucket.
- Choose whether given a same scm revision you want to notify a new build status for every job build or to override the latest one.
Change Log
Version 1.4.0 (May 29, 2018)
- Add optional parameters for the bitbucket repo slug and the commit id. (PR #37)
Version 1.3.3 (Feb 15, 2017)
- Fix bug on pipeline avoid exception whenever failure is notified.
Version 1.3.1 (Dec 20, 2016)
- Add documentation for overriding latest build status
- Folders/Multibranch support. Refactored all project.getFullDisplayName() calls to project.getFullName() calls in order to support job inside folders.
- Fix for username same as repository name
- Use MercurialTagAction.class to retrive Mercurial revision
Version 1.3.0 (Juli 13, 2016)
- Add support for pipeline plugin. (JENKINS-33841)
- Add configuration for show only latest build status on Bitbucket. (JENKINS-35083)
Version 1.2.2 (Juni 16, 2016)
- Improve documentation.
- Fix some issues related to plugin deployment.
Version 1.2.1 (Juni 1, 2016)
- Add Junit test results to Bitbucket build status description. (JENKINS-34619)
- Fix minor issues. (JENKINS-33901)
- Increase logging verbosity. (JENKINS-34788)
Version 1.2.0 (April 22, 2016)
- Add support for parameterized repository URLs. (JENKINS-33276)
- Add support for multi SCM.
Version 1.1.0 (March 13, 2016)
- Add support for updating the Bitbucket build status for a previous aborted build. (JENKINS-32940)
- Fix bug build abortion not notified. (JENKINS-32940)
- Add support for single and global API credentials. (JENKINS-32574)
- Fix bug max Bitbucker key lenght. (JENKINS-32781)
- Add support for mercurial repositories. (JENKINS-32548)
Version 1.0.3 (Jan 29, 2016)
- Fix bug parsing repository URI. (JENKINS-32498)
- Mark UNSTABLE builds as FAILED on Bitbucket.
Version 1.0.1 (Jan 22, 2016)
- Fix problem finding current revision. (JENKINS-32519)
- Improve logging for exceptions in order to easy debugging.