jenkinsci / jenkinsci/git-plugin

[JENKINS-17104] Git checkout fails on second build if local branch to merge to is specified as a parameter.

Open
#2,247 1 comment 0 reactions 0 assignees View on GitHub
component:git-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
694
Forks
1.1k
Avg merge
1h 29m
Merged PRs (30d)
3

Description

I am using the Envinject plugin to set some pre-scm variables.

When I specify the local branch to merge to as a parameter, the first build is able to check out (then fails for other reasons).

On the second build, the build will fail with the stack trace that follows. If I replace the variable with the name it resolves to, it works fine.



12:56:03 FATAL: Command "/usr/local/git/bin/git checkout -b ${DATA_DEPLOY_BRANCH} e60ebf368ec03b4e4dd449427d50115203049218" returned status code 128:

12:56:03 stdout:

12:56:03 stderr: fatal: A branch named 'mybranch' already exists.

12:56:03

12:56:03 hudson.plugins.git.GitException: Command "/usr/local/git/bin/git checkout -b ${DATA_DEPLOY_BRANCH} e60ebf368ec03b4e4dd449427d50115203049218" returned status code 128:

12:56:03 stdout:

12:56:03 stderr: fatal: A branch named 'mybranch' already exists.

12:56:03

12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:772)

12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:738)

12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:748)

12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkout(CliGitAPIImpl.java:845)

12:56:03 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1283)

12:56:03 at hudson.plugins.git.GitSCM.access$1100(GitSCM.java:57)

12:56:03 at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1232)

12:56:03 at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1208)

12:56:03 at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2348)

12:56:03 at hudson.remoting.UserRequest.perform(UserRequest.java:118)

12:56:03 at hudson.remoting.UserRequest.perform(UserRequest.java:48)

12:56:03 at hudson.remoting.Request$2.run(Request.java:326)

12:56:03 at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)

12:56:03 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

12:56:03 at java.util.concurrent.FutureTask.run(FutureTask.java:166)

12:56:03 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

12:56:03 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

12:56:03 at hudson.remoting.Engine$1$1.run(Engine.java:58)

12:56:03 at java.lang.Thread.run(Thread.java:722)

---
Originally reported by b2jrock, imported from: Git checkout fails on second build if local branch to merge to is specified as a parameter.


  • status: Open
  • priority: Minor
  • component(s): git-plugin
  • resolution: Unresolved
  • votes: 1
  • watchers: 1
  • imported: 2025-12-02

Raw content of original issue

I am using the Envinject plugin to set some pre-scm variables.

When I specify the local branch to merge to as a parameter, the first build is able to check out (then fails for other reasons).

On the second build, the build will fail with the stack trace that follows. If I replace the variable with the name it resolves to, it works fine.


12:56:03 FATAL: Command "/usr/local/git/bin/git checkout -b ${DATA_DEPLOY_BRANCH} e60ebf368ec03b4e4dd449427d50115203049218" returned status code 128:
12:56:03 stdout:
12:56:03 stderr: fatal: A branch named 'mybranch' already exists.
12:56:03
12:56:03 hudson.plugins.git.GitException: Command "/usr/local/git/bin/git checkout -b ${DATA_DEPLOY_BRANCH} e60ebf368ec03b4e4dd449427d50115203049218" returned status code 128:
12:56:03 stdout:
12:56:03 stderr: fatal: A branch named 'mybranch' already exists.
12:56:03
12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:772)
12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:738)
12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:748)
12:56:03 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkout(CliGitAPIImpl.java:845)
12:56:03 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1283)
12:56:03 at hudson.plugins.git.GitSCM.access$1100(GitSCM.java:57)
12:56:03 at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1232)
12:56:03 at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1208)
12:56:03 at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2348)
12:56:03 at hudson.remoting.UserRequest.perform(UserRequest.java:118)
12:56:03 at hudson.remoting.UserRequest.perform(UserRequest.java:48)
12:56:03 at hudson.remoting.Request$2.run(Request.java:326)
12:56:03 at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
12:56:03 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
12:56:03 at java.util.concurrent.FutureTask.run(FutureTask.java:166)
12:56:03 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
12:56:03 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
12:56:03 at hudson.remoting.Engine$1$1.run(Engine.java:58)
12:56:03 at java.lang.Thread.run(Thread.java:722)

  • environment: jenkins 1.503, osx, latest git plugin

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.