Skip to content

[Bug]: Manual redeploy of a Bitbucket Cloud preview silently builds the base branch instead of the PR code #10806

Description

@johandenhollander

Error Message and Logs

Summary

On a Bitbucket Cloud git source (private deploy key over SSH, no Git App), a manual / non-webhook redeploy of a pull-request preview silently rebuilds the application's base branch (e.g. develop) instead of the PR's code. The deployment is marked successful, so the preview ends up running the wrong code with no error.

Webhook-triggered PR deploys work correctly (they carry pullrequest.source.commit.hash). The problem is specifically a manual redeploy of an existing preview — clicking Redeploy in the UI, or calling the deploy API with ?pr=<id> without a webhook.

Expected

A manual redeploy of a PR preview rebuilds the PR's code (the same commit the webhook used), or fails loudly. It should not silently build the base branch.

Actual

commit = HEAD. Coolify tries to resolve the PR commit via git ls-remote origin pull/<id>/head, which does not exist on Bitbucket Cloud (Bitbucket Cloud exposes no PR refs over git — neither pull/N/head nor refs/pull-requests/N/from). The commit stays HEAD, so Coolify clones -b <base-branch> and checks out HEAD -> it builds the base branch. Green deployment, wrong code.

Relevant log (redacted)

Importing <repo>.git:develop (commit sha HEAD) to /artifacts/<uuid>.
Checking out tag pull/<id>/head.
git clone --recurse-submodules -b 'develop' ... && ... git checkout 'HEAD'
Your branch is up to date with 'origin/develop'.

Root cause

  • The Bitbucket webhook deploy passes commit = pullrequest.source.commit.hash, so it checks out the right commit.
  • A manual redeploy has no such commit. ApplicationDeploymentJob computes lsRemoteRef = "pull/<id>/head" (no bitbucket-specific PR ref in that switch) and runs git ls-remote origin pull/<id>/head. On Bitbucket Cloud this resolves to nothing, so commit stays HEAD and the base branch is built.

Suggested fix

  • Persist the PR's resolved source commit on the preview and reuse it for manual redeploys; or
  • For Bitbucket, resolve the PR head via the Bitbucket API at redeploy time (the source branch name is known) and fail loudly if it cannot be resolved, instead of silently building the base branch.

Note

This is distinct from #9926, which is a hard failure on webhook deploys with shallow clone enabled (worked around by disabling shallow clone). Here shallow clone is off and webhook deploys succeed; the manual redeploy is a separate, silent failure.

Version: Coolify v4.1.2 (self-hosted).

Steps to Reproduce

  1. Create an application with a Bitbucket Cloud git source (private deploy key over SSH), base branch develop, with preview deployments enabled. Make sure Shallow Clone is OFF (so this is not [Bug]: Bitbucket preview deployments fail because Coolify tries to fetch a existing short commit ref #9926).
  2. Open a pull request against develop. The webhook creates a preview and builds the PR commit correctly (verify the PR code is live).
  3. Manually click Redeploy on that preview in the UI (or call the deploy API with ?pr=<id> without a webhook).
  4. Observe: the deployment log shows Importing ...:develop (commit sha HEAD) and git checkout 'HEAD', the deployment is marked successful, but the preview now runs develop instead of the PR code.

Example Repository URL

No response

Coolify Version

4.1.2

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

No response

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔍 TriageIssues that need assessment and prioritization.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions