# DRONE\_COMMIT\_BEFORE is always empty on Bitbucket

**URL:** <https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950>\
**Category:** Drone Support\
**Created:** [July 1, 2019, 10:43am UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950 "2019-07-01T10:43:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkdev81](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jkdev81](https://drone.discourse.group/u/jkdev81)\
**Post date:** [July 1, 2019, 10:43am UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/1 "2019-07-01T10:43:55Z")

</div>

Hi!  
With drone 1.2.1 connecting to BitBucket the env variable DRONE\_COMMIT\_BEFORE is always empty.  
Previously we had drone 0.8.1 and the env variable DRONE\_PREV\_COMMIT\_SHA was working as expected.  
How can I get the previous commit for a build? Is it a problem with BitBucket?  
Thanks.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [July 1, 2019, 3:10pm UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/2 "2019-07-01T15:10:04Z")

</div>

These are different fields. The drone\_prev\_commit\_sha was the previous build executed by Drone for the repository (and was deprecated). The drone\_commit\_before is a field that is sent in the webhook that provides the commit sha before the commit was pushed, and the drone\_commit\_after is the commit sha after it was pushed.

It is possible the bitbucket webhook has this field so that we can populate, however, I have not done enough research to say for sure. It may be the value of `push.changes[0].old.target.hash` [1]. There is an open issue in our tracker [2].

[1] [https://github.com/drone/go-scm/blob/master/scm/driver/bitbucket/testdata/webhooks/push.json](https://github.com/drone/go-scm/blob/master/scm/driver/bitbucket/testdata/webhooks/push.json)  
[2] [https://github.com/drone/go-scm/issues/23](https://github.com/drone/go-scm/issues/23)

---

<div class="post-metadata">

**Author:** ![jkdev81](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jkdev81](https://drone.discourse.group/u/jkdev81)\
**Post date:** [July 2, 2019, 7:26am UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/3 "2019-07-02T07:26:20Z")

</div>

Thank you, bradrydzewski.  
I have added a pull request to solve the issue: [https://github.com/drone/go-scm/pull/32](https://github.com/drone/go-scm/pull/32)

---

<div class="post-metadata">

**Author:** ![marcos-monteiro](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/marcos-monteiro/32/2686_2.png) [@marcos-monteiro](https://drone.discourse.group/u/marcos-monteiro)\
**Post date:** [May 21, 2020, 9:10pm UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/4 "2020-05-21T21:10:14Z")

</div>

Hi!

Should DRONE\_COMMIT\_BEFORE works now in Bitbucket? I can see that the “pull/32” was merged, but the variable is still empty to me. I’m using Drone 1.7.

If this variable is still not working with Bitbucket, do you guys recommend another way to track the “chain of updates” of a branch? After we get a branch merged, we should run another pipeline that it needs something that refer the branch that originated that merge.

Now, in the env vars of the (merge triggered) pipeline containers, I don’t have any reference of what branch I’m merging.

I could see in the Drone UI a pattern in the description, like:  
job 84 - marcos.monteiro pushed [3f502a3a] to [master]  
job 83 - marcos.monteiro pushed [3f502a3a] to [feature/…]  
job 82 - marcos.monteiro pushed [3f502a3a] to [feature/…]

Is there a way to get the hash above complete and inside of the steps containers as env vars?

Sorry if my question can sound a bit confused, I’m trying to make this work for a few days already.

Let me know If you guys need any additional info. Thanks.

---

<div class="post-metadata">

**Author:** ![marcos-monteiro](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/marcos-monteiro/32/2686_2.png) [@marcos-monteiro](https://drone.discourse.group/u/marcos-monteiro)\
**Post date:** [May 22, 2020, 4:17pm UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/5 "2020-05-22T16:17:30Z")

</div>

I tested with Bitbucket Cloud and the DRONE\_COMMIT\_BEFORE var was populated in all jobs. I use Bitbucket server 5.16 though. Do you know if this variable works in Bitbucket server? and if so, since what version?

Thank you!

---

<div class="post-metadata">

**Author:** ![ashwilliams1](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ashwilliams1/32/5549_2.png) [@ashwilliams1](https://drone.discourse.group/u/ashwilliams1)\
**Post date:** [May 22, 2020, 8:04pm UTC](https://drone.discourse.group/t/drone-commit-before-is-always-empty-on-bitbucket/10950/6 "2020-05-22T20:04:48Z")

</div>

Bitbucket Cloud and Bitbucket Server share a similar name, but that is about all 🙂 They are completely distinct systems with different API endpoints and webhook payloads. The pull request mentioned in this thread seems to add support for Bitbucket Cloud, however, support for Bitbucket Server (aka Stash) has not been added yet. I believe this would require a patch to [this file](https://github.com/drone/go-scm/blob/master/scm/driver/stash/webhook.go#L148:L166).
