Webhook requests from Build do not contain branch name
Asked by Jonathan Duncan:

The webhook \[["Push" event payload](https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Push)\] contains the name of the branch that that the commit was pushed on.

The webhook "Build status created" (\`repo:commit_status_created\`) and "Build status updated" (\`repo:commit_status_updated\`) event payloads do not contain the name of the branch.

Is this a feature or an oversight? If it is like this on purpose, I am curious as to the reasoning. If this was an oversight, I would like to request that this feature be added.


Answers:
author: Theodora Boudale
body: Hi Jonathan,

When a commit is pushed, it is pushed to a specific branch. Builds, however, do not necessarily run on branches.

For example, with Bitbucket Pipelines it is possible to run builds on tags or pull requests. It is also possible to run a build on a certain commit if you open that commit on Bitbucket website and select the option *Run pipeline*. That build will not be associated with a certain branch. If we were to return the branches this commit is reachable from, then e.g. for the initial commit of the repo that would be all branches. For a repo with a large number of branches that would be a large number of references which would probably not be very useful.

Are you looking for the branch the commit belongs to? Or for the trigger of the build (branch name for builds triggered on branches, PR number for pull-requests triggered builds, tag for tags-triggered builds, and commit hash for commit-triggered builds)?

Kind regards,  
Theodora

comments: author: Jonathan Duncan
body: Thank you for your response. I can see how the current branch would not be useful.

As you mentioned, yes, I am actually looking for the branch that the commit belongs to or that triggered the build.

I need this information to help automate a process that depends on knowing which branch a build was started on.

I know I could take the commit information and use some of that to make an API call to get more information about the commit, but it would be convenient to have that in the webhook. It would save me some extra work. :)


author: Theodora Boudale
body: Hi Jonathan!

Thank you for your reply.

Our API for commits does not return the branches a commit is reachable from for the same reason I explained earlier (if a commit is reachable from a large number of branches, we would need to return a large number of refs which would probably not be very useful).

What you could do is check the **url** in the webhook payload, and if that returns a url to the build, you could use the API of the CI/CD tool you are using to retrieve info for the build and the branch that triggered the build (in case it was indeed a branch-triggered pipeline). For example, if you use Bitbucket Pipelines, our API returns this info:

* <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-pipeline-uuid-get>

If you use another CI/CD tool you may be able to get that info from that build system's APIs.

I went ahead and created a feature request in our issue tracker for returning the build trigger in the payload:

* <https://jira.atlassian.com/browse/BCLOUD-23042>

You can add your vote and feedback there to express your interest. Implementation of features is done as per our policy [here](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) and any updates will be posted in the feature request.

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora


author: Jonathan Duncan
body: Thank you for the extra information and also for submitting a feature request.


author: Theodora Boudale
body: You are very welcome. Please feel free to reach out if you ever need anything else!


Tags: bitbucket-cloud

cloud