How to send Bamboo build status to GitHub via Webhook
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This article talks about how can we send Bamboo build status to GitHub for a particular commit via Webhook. This article only talks about
Environment
Bamboo DC 9.6 and GitHub.
Solution
From GitHub side
- Configure GitHub to call the following Bamboo REST API as per How to trigger Bamboo builds with GitHub webhook
https://<BAMBOO_URL>/rest/triggers/latest/remote/changeDetection?planKey=<PLAN-KEY>
The above steps should be enough to configure the Bamboo instance for remote triggers from GitHub. Make sure that the Content-type field is set to application/json.
2. As per GitHub documentation - REST API endpoints for commit statuses to receive a commit status it should have the below body parameters in the response body of the API call.
Body Parameters
state
The state of the status.
Can be one of: error, failure, pending, success
target_url
The target URL to associate with this status. This URL will be linked from the GitHub UI to allow users to easily see the source of the status.
description
A short description of the status.
context string
A string label to differentiate this status from the status of other systems. This field is case-insensitive.
Bamboo can send build status over to GITHUB, with the above body parameters,However the problem is that GITHUB expects Bamboo to send the status in lower case i.e “success”. Bamboo can send this as uppercase ex:- “SUCCESS” which GITHUB does not accept.
This has been fixed in Bamboo 9.6 in BAM-25700 - Getting issue details... STATUS
Note
There is an issue while sending Bamboo failed status to GITHUB. The problem is that GITHUB expects Bamboo to send the status of failed build as "failure" however Bamboo is sending the status as "FAILED" which GITHUB is not accepting.
We identify this as a bug and we have created the below bug report for the same BAM-25792 - Getting issue details... STATUS . This has been fixed from Bamboo 10.0 ,since from Bamboo 10.0, updating the GitHub build statuses will be supported out of the box!
From Bamboo side
1. The for the BAM-25700 - Getting issue details... STATUS includes FTL template engine parser, so it's possible to use payload which includes builtin string functions to change case of status string.
To enable this feature use system property "-Dbamboo.security.allow.freemarker.at.webhook.payload=true" at setenv.sh or setenv.bat as per this page.
2. Next step is to set up Webhook at Bamboo side with the below Payload and Header. (Overview→ Communication→Webhook Templates→Add Template)
Webhook Set up in Bamboo
Set up the Webhook as below
{"state":"${'${bamboo.buildState}'?lower_case}","target_url":"${bamboo.buildResultsUrl}","description":"${bamboo.buildState}","context":"continuous-integration/bamboo"}
Accept: application/vnd.github+json
Authorization: Bearer <use your github token>
3. Next step is to send Bamboo build status for a commit done in GITHUB, we can make use of Notifications i.e send Webhook as notifications for this purpose. To set up notifications go to (Plan->Actions→Configure Plan->Notifications→Add Notifications→Notification Type as "Webhook" →Select the template used above and the URL )
The URL as per REST API endpoints for commit statuses should be as below :
https://api.github.com/repos/ <GitHub username>/<repo name>/statuses/${bamboo.planRepository.revision}
4. Run the plan and check the webhook status
Finally Check for the commit in GITHUB it should show you the build status.
When you click on the details tab it takes you to the Bamboo build page , which has the build url and the build status for the commit done.