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 Cloud UI.
Note: This plugin aims at the Atlassian-hosted BitBucket Cloud solution, not BitBucket Server (formerly known as Stash).
- Notify to Bitbucket for the following build events:
- Build start
- Build finish
This plugin depends on other Jenkins plugins:
Please install them before if they are still not installed on your Jenkins server.
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.
Second, ensure that Jenkins URL is properly set:
- Open Jenkins Manage Jenkins page.
- Click Configure System page.
- Got to the section Jenkins Location.
- Set correct URL to Jenkins URL.
- Click Save button.
Third, you need to add the Bitbucket OAuth Consumer credentials. You have two ways to configure it globally or locally:
- 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.
- 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.
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.
Once you have configured the credential, you can notify BitBucket from your Pipeline script through the bitbucketStatusNotify
step.
The bitbucketStatusNotify
step notifies the status of a build identified by a build key and build name to BitBucket.
If buildKey
and buildName
parameters are not provided, a standard name will be assigned to the build (NameOfYourJob #numberOfBuild - eg. MyProject #32).
...
stage 'Build'
bitbucketStatusNotify(
buildState: 'INPROGRESS',
buildKey: 'build',
buildName: 'Build'
)
try {
myBuildFunction()
bitbucketStatusNotify(
buildState: 'SUCCESSFUL',
buildKey: 'build',
buildName: 'Build'
)
} catch(Exception e) {
bitbucketStatusNotify(
buildState: 'FAILED',
buildKey: 'build',
buildName: 'Build',
buildDescription: 'Something went wrong with build!'
)
}
stage 'Test'
bitbucketStatusNotify(
buildState: 'INPROGRESS',
buildKey: 'test',
buildName: 'Test'
)
try {
myTestFunction()
bitbucketStatusNotify(
buildState: 'SUCCESSFUL',
buildKey: 'test',
buildName: 'Test'
)
} catch(Exception e) {
bitbucketStatusNotify(
buildState: 'FAILED',
buildKey: 'test',
buildName: 'Test',
buildDescription: 'Something went wrong with tests!'
)
}
...
Parameter:
Name | Type | Optional | Description |
---|---|---|---|
buildState |
`"INPROGRESS" | "SUCCESSFUL" | "FAILED"` |
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 |
Contributions are welcome! For feature requests and bug reports please read the following Wiki page for guidelines on how to submit an issue.
The MIT License (MIT)
Copyright (c) 2015 Flagbit GmbH & Co. KG
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.