[JENKINS-67073] Jenkins is not using the correct commit SHA when building a force pushed PR
- When force pushing a pull request branch via bitbucket, jenkins keeps building the first commit that the pull request was created with.
- Bitbucket-push-and-pull-request-plugin on jenkins receives the payload from the webhook correctly and the build is triggered but the commit which jenkins fetches is wrong.
- Steps to reproduce:
- Push a PR and check if the build is triggered in jenkins via bitbucket-push-and-pull-request-plugin.
- Check the sha of the commit in bitbucket PR commit summary.
- Make a code change, commit amend and force push the change (you will see that the commit sha has changed in the PR overview).
- Check that jenkins has been triggered and you will see that the build fail with error (stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6) or whatever commit sha you have
hudson.plugins.git.GitException: Command "/usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6" returned status code 128: stdout: stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$1100(CliGitAPIImpl.java:86) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2999) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from my server at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1797) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1001) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131) at com.sun.proxy.$Proxy95.execute(Unknown Source) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1352) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused: hudson.plugins.git.GitException: Could not checkout a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3023) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:160) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:153) at hudson.remoting.UserRequest.perform(UserRequest.java:211) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:117) at java.base/java.lang.Thread.run(Thread.java:834) Finished: FAILURE
The sha1 of the latest commit is different from a5b47104e757b867e58f0e564b439e8d2f770ed6
the git plugin as well as bitbucket-pull-request-plugin were configured to listen to any branch's change
Originally reported by
kafteji, imported from: Jenkins is not using the correct commit SHA when building a force pushed PR
- status: Open
- priority: Major
- component(s): git-plugin
- resolution: Unresolved
- votes: 0
- watchers: 2
- imported: 2025-12-02
Raw content of original issue
- When force pushing a pull request branch via bitbucket, jenkins keeps building the first commit that the pull request was created with.
- Bitbucket-push-and-pull-request-plugin on jenkins receives the payload from the webhook correctly and the build is triggered but the commit which jenkins fetches is wrong.
- Steps to reproduce:
- Push a PR and check if the build is triggered in jenkins via bitbucket-push-and-pull-request-plugin.
- Check the sha of the commit in bitbucket PR commit summary.
- Make a code change, commit amend and force push the change (you will see that the commit sha has changed in the PR overview).
- Check that jenkins has been triggered and you will see that the build fail with error (stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6) or whatever commit sha you have
hudson.plugins.git.GitException: Command "/usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6" returned status code 128: stdout: stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$1100(CliGitAPIImpl.java:86) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2999) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from my server at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1797) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1001) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131) at com.sun.proxy.$Proxy95.execute(Unknown Source) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1352) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused: hudson.plugins.git.GitException: Could not checkout a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3023) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:160) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:153) at hudson.remoting.UserRequest.perform(UserRequest.java:211) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:117) at java.base/java.lang.Thread.run(Thread.java:834) Finished: FAILURE
The sha1 of the latest commit is different from a5b47104e757b867e58f0e564b439e8d2f770ed6
the git plugin as well as bitbucket-pull-request-plugin were configured to listen to any branch's change
environment
Jenkins: LTS 2.303.3<br/>
git-plugin: 4.10.0<br/>
bitbucket-push-and-pull-request-plugin: 2.7.2
kafteji:
- Original comment link
Raw content of original comment:
I have noticed something else while investigating the issue. GIT plugin actually detects the new commit 's SHA but it skips it because it thinks it's originating from another repo.
[Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout The recommended git tool is: /usr/bin/gitusing credential bb202df4-55f2-4c35-8c49-bd821a020498 Cloning the remote Git repositoryCloning repository [email protected]:space/my-repo.git > /usr/bin/git init /home/jenkins/agent/workspace/my-test-job # timeout=10 Fetching upstream changes from [email protected]:space/my-repo.git > /usr/bin/git --version # timeout=10 > git --version # 'git version 2.20.1' using GIT_SSH to set credentials foo Bitbucket > /usr/bin/git fetch --tags --force --progress -- [email protected]:space/my-repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > /usr/bin/git config remote.origin.url [email protected]:space/my-repo.git # timeout=10 > /usr/bin/git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10 > /usr/bin/git config remote.origin.url [email protected]:space/my-repo.git # timeout=10 Fetching upstream changes from [email protected]:space/my-repo.git using GIT_SSH to set credentials foo Bitbucket > /usr/bin/git fetch --tags --force --progress -- [email protected]:space/my-repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 skipping resolution of commit 4d5740fbab24, since it originates from another repositoryChecking out Revision a5b47104e757b867e58f0e564b439e8d2f770ed6 (origin/feature/DS-2815-event-service) [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node Seen branch in repository origin/DS-3059-dockerfile-components Seen branch in repository origin/feature/DS-2815-event-service Seen branch in repository origin/main Seen 3 remote branches > /usr/bin/git show-ref --tags -d # timeout=10 > /usr/bin/git config core.sparsecheckout # timeout=10 > /usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6 # timeout=10 [Pipeline] } [Pipeline] // podTemplate [Pipeline] End of Pipeline hudson.plugins.git.GitException: Command "/usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6" returned status code 128: stdout: stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$1100(CliGitAPIImpl.java:86) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2999) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from server at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1797) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1001) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131) at com.sun.proxy.$Proxy96.execute(Unknown Source) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1352) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused: hudson.plugins.git.GitException: Could not checkout a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3023) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:160) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:153) at hudson.remoting.UserRequest.perform(UserRequest.java:211) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:117) at java.base/java.lang.Thread.run(Thread.java:834) Finished: FAILURE
I have noticed something else while investigating the issue. GIT plugin actually detects the new commit 's SHA but it skips it because it thinks it's originating from another repo.
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: /usr/bin/gitusing credential bb202df4-55f2-4c35-8c49-bd821a020498
Cloning the remote Git repositoryCloning repository git@bitbucket.org:space/my-repo.git
> /usr/bin/git init /home/jenkins/agent/workspace/my-test-job # timeout=10
Fetching upstream changes from git@bitbucket.org:space/my-repo.git
> /usr/bin/git --version # timeout=10
> git --version # 'git version 2.20.1'
using GIT_SSH to set credentials foo Bitbucket
> /usr/bin/git fetch --tags --force --progress -- git@bitbucket.org:space/my-repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > /usr/bin/git config remote.origin.url git@bitbucket.org:space/my-repo.git # timeout=10
> /usr/bin/git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> /usr/bin/git config remote.origin.url git@bitbucket.org:space/my-repo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:space/my-repo.git
using GIT_SSH to set credentials foo Bitbucket
> /usr/bin/git fetch --tags --force --progress -- git@bitbucket.org:space/my-repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
skipping resolution of commit 4d5740fbab24, since it originates from another repositoryChecking out Revision a5b47104e757b867e58f0e564b439e8d2f770ed6 (origin/feature/DS-2815-event-service)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
Seen branch in repository origin/DS-3059-dockerfile-components
Seen branch in repository origin/feature/DS-2815-event-service
Seen branch in repository origin/main
Seen 3 remote branches
> /usr/bin/git show-ref --tags -d # timeout=10
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6 # timeout=10
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "/usr/bin/git checkout -f a5b47104e757b867e58f0e564b439e8d2f770ed6" returned status code 128:
stdout:
stderr: fatal: reference is not a tree: a5b47104e757b867e58f0e564b439e8d2f770ed6 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$1100(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:2999)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from server
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1797)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
at hudson.remoting.Channel.call(Channel.java:1001)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131)
at com.sun.proxy.$Proxy96.execute(Unknown Source)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1352)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused: hudson.plugins.git.GitException: Could not checkout a5b47104e757b867e58f0e564b439e8d2f770ed6
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3023)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:160)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:153)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:117)
at java.base/java.lang.Thread.run(Thread.java:834)
Finished: FAILURE
warlord:
- Original comment link
Raw content of original comment:
I just hit this issue myself.
I wonder if the issue here is that the Webhook is telling Jenkins that the GIT Repo is at HTTPS://... but Jenkins is configured for the SSH URI to the repo, and Jenkins doesn't notice that they are "the same"?
I just hit this issue myself.
I wonder if the issue here is that the Webhook is telling Jenkins that the GIT Repo is at HTTPS://... but Jenkins is configured for the SSH URI to the repo, and Jenkins doesn't notice that they are "the same"?