Drone

DRONE_COMMIT_BEFORE is always empty on Bitbucket

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.

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
[2] https://github.com/drone/go-scm/issues/23

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

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.

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!

Bitbucket Cloud and Bitbucket Server share a similar name, but that is about all :slight_smile: 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.