-
Bug
-
Resolution: Fixed
-
Low
-
9.6.2
-
None
-
2
-
Severity 2 - Major
-
2
-
Issue Summary
When we try to use a webhook as a notification to try to send failed build status from Bamboo to GITHUB for particular commit id, its failing with the status code 422
{"message":"Validation Failed","errors":[{"resource":"Status","code":"custom","field":"state","message":"state is not included in the list"}],"documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status"}
This is reproducible on Data Center: (yes) / (no) yes
Steps to Reproduce
1. Intergrate Bamboo with GITHUB
2. Configure Bamboo to trigger build after a commit in GITHUB - https://confluence.atlassian.com/bamkb/how-to-trigger-bamboo-builds-with-github-webhook-1097179080.html
3. Try to send the Bamboo build results to GITHUB
For that we need to set up a webhook to transfer Bamboo build status to GITHUB commit via notifications in build plan.
4. Use the below payload and header
Payload :-
{"state":"${'${bamboo.buildState}'?lower_case}","target_url":"${bamboo.buildResultsUrl}","description":"${bamboo.buildState}","context":"continuous-integration/bamboo"}
Header :-
Accept: application/vnd.github+json Authorization: Bearer <use your github token>
Use the below notification url
https://api.github.com/repos/ <GitHub username>/<repo name>/statuses/${bamboo.planRepository.revision}
Expected Results
The build status , target url , description and context arer passed to GITHUB for the commit ID
Actual Results
The webhook execution fails with status code 422
{"message":"Validation Failed","errors":[{"resource":"Status","code":"custom","field":"state","message":"state is not included in the list"}],"documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status"}
However 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
state string Required The state of the status. Can be one of: error, failure, pending, success
This is a follow up to https://jira.atlassian.com/browse/BAM-25700 where we fixed the success part. where GITHUB expects Bamboo to send the status in lower case i.e "success". Bamboo was sending this as uppercase "SUCCESS". Now the issue is with failed builds.
Workaround
Workaround 1
There is a way to allow freemarker templating in the webhook payload to customize the JSON based on certain criteria. It is gated behind a security property as it will allows access to powerful freemarker templating APIs which can be used to customize the webhook payload. However, these templates are only editable by Bamboo administrators.
-Dbamboo.security.allow.freemarker.at.webhook.payload=true
Use the following template with Freemarker customizations to map Bamboo build states to the GitHub expectations:
- FAILED -> failure
- SUCCESS -> success
{ "state": "<#if '${bamboo.buildState}' == 'FAILED'>failure<#else>${'${bamboo.buildState}'?lower_case}</#if>", "target_url": "${bamboo.buildResultsUrl}", "description": "${bamboo.buildState}", "context": "continuous-integration/bamboo" }
Workaround 2
Try to use this external third party open-source plugin instead : https://github.com/HackAttack/bamboo-github-status however it is heavily outdated and will likely need customizations to work with modern versions of Bamboo