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?
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.old.target.hash . There is an open issue in our tracker .
Thank you, bradrydzewski.
I have added a pull request to solve the issue: https://github.com/drone/go-scm/pull/32
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?
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.