Bitbucket failing to checkout after PR gets new commits

Article ID:360055462071
1 minute readKnowledge base

Issue

Updating an existing Pull Request with additional commits leads to broken builds of the Pull Request, because Jenkins tries to check out a non-existent ref in git.

You will see an error in your build similar to this:

[Bitbucket] Build result notified hudson.plugins.git.GitException: Command "git checkout -f *****************************" returned status code 128: stdout: stderr: fatal: reference is not a tree: ***************************** at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1924) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$800(CliGitAPIImpl.java:71) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2214) Caused: hudson.plugins.git.GitException: Could not checkout ***************************** at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2237) at jenkins.plugins.git.MergeWithGitSCMExtension.checkout(MergeWithGitSCMExtension.java:146) at jenkins.plugins.git.MergeWithGitSCMExtension.decorateRevisionToBuild(MergeWithGitSCMExtension.java:112) at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1023) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1116) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:120) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:246) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:405) Finished: FAILURE

Resolution

In investigations this issue is limited to environments that use Bitbucket Enterprise. This is caused by a missing configuration in Jenkins.

  1. Navigate to Manage Jenkins -> Configure System -> Bitbucket Endpoints

  2. Under your Bitbucket Server settings, locate the Call Can Merge checkbox.

  3. This setting will need to be toggled on.

Tested product/plugin versions

Bitbucket Branch Source Plugin version 2.5.0

References

Reported Issue JENKINS-45997

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.