# Buildkite pull request build failed for existing commits

**URL:** <https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416>\
**Category:** Pipelines\
**Created:** [December 13, 2023, 11:59pm UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416 "2023-12-13T23:59:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sindhuja](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sindhuja](https://forum.buildkite.community/u/sindhuja)\
**Post date:** [December 13, 2023, 11:59pm UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/1 "2023-12-13T23:59:54Z")

</div>

Hi Team,

I have disabled “Skip pull request builds for existing commits” in the pipeline settings

Buildkite build triggered by commit push webhook is successful

But the Buildkite build triggered by a pull request for the same commit failed during the “Preparing working directory” step with an error

```auto
git fetch -v --prune -- origin 456b02e2af84	
fatal: couldn't find remote ref 456b02e2af84
🚨 Error: fetching commit "456b02e2af84": exit status 128

```

### Note:

Bitbucket webhook payload for push has commit with full hash

`"commitId":"456b02e2af84bda60b91391d3548a53e964cea04"`

Bitbucket webhook payload for pull request payload has a different commit hash for the same commit

`"commitId": "456b02e2af84"`

I had to create another dummy commit to trigger the Buildkite build to fix the pipeline.

do we have a workaround for this? Any help/suggestions would be appreciated.

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [December 14, 2023, 12:20am UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/2 "2023-12-14T00:20:51Z")

</div>

Hello @sindhuja!

Hope you’re well and thanks for the question - welcome to the Buildkite Support Community!

The good news is that this has been something we have seen before with received Bitbucket webhooks containing a short SHA which Buildkite resolves to `BUILDKITE_COMMIT` and hence those seen checkout errors occur. In that in [agent version](https://github.com/buildkite/agent/releases/tag/v3.58.0) `v3.58.0` and newer - we included a fix for events like this (where `BUILDKITE_COMMIT` is set to a short SHA from a resultant webhook and errors are seen in the fetching process). The actual [PR](https://github.com/buildkite/agent/pull/2465) for the fix was described here. If you’re using an older version of the Buildkite agent than this, I’d suggest updating it to that version (or latest) to get this inclusive!

Another way that I’ve coined (transparently from the inbuilt agent resolution and from the commentary previously) is something like the below: you could potentially set the `BUILDKITE_COMMIT` with a `git log` to get the full SHA back, or potentially query the BitBucket [API](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get) to list the commits and obtain the relevant **full** SHA from the responses’ payload (note you’ll need to `export` below in hooks - before the `checkout` phase)

`export BUILDKITE_COMMIT=$(git log -1 --format="%H" $BUILDKITE_COMMIT 2>/dev/null)`

Hope the above does help 🙂

---

<div class="post-metadata">

**Author:** ![sindhuja](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sindhuja](https://forum.buildkite.community/u/sindhuja)\
**Post date:** [December 14, 2023, 1:41am UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/3 "2023-12-14T01:41:26Z")

</div>

Hi @james.s  
Thank you for the quick reply and the suggestion with the details.

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [December 14, 2023, 1:44am UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/4 "2023-12-14T01:44:46Z")

</div>

No worries @sindhuja!

Please let us know if anything else pops up 🙂

---

<div class="post-metadata">

**Author:** ![sindhuja](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sindhuja](https://forum.buildkite.community/u/sindhuja)\
**Post date:** [December 14, 2023, 2:50am UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/5 "2023-12-14T02:50:08Z")

</div>

Thanks @james.s upgrading to the latest Buildkite agent version solved the issue.

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [December 14, 2023, 2:51am UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/6 "2023-12-14T02:51:04Z")

</div>

Excellent to hear!

Thanks for confirming the solution too 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/system/32/1321_2.png) [@system](https://forum.buildkite.community/u/system)\
**Post date:** [January 13, 2024, 12:51pm UTC](https://forum.buildkite.community/t/buildkite-pull-request-build-failed-for-existing-commits/3416/7 "2024-01-13T12:51:35Z")

</div>

Closed on January 13, 2024, 12:51pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
