jenkinsci / jenkinsci/git-plugin

[JENKINS-33984] Git plugin sets wrong branch name GIT_BRANCH (more than 2 branches with same SHA1)

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

Description

Git plugin ver: 2.4.4

In jenkins job we configure Git plugin ->

Branches to build/Branch specifier: origin/ready/**

Developer pushes code to central git repository, which Jenkins check into 2 branches:

git push origin bugfix:sergey/bugfix

git push origin bugfix:ready/bugfix

When Jenkins job kicks in, it provides this output:

14:01:36 > git branch -a -v --no-abbrev --contains 24ef859065480d5ac965652cfce8a0dd959fd082 # timeout=10

14:01:36 Checking out Revision 24ef859065480d5ac965652cfce8a0dd959fd082 (origin/sergey/bugfix, origin/ready/bugfix)

..

..

14:01:36 HOME=/var/lib/jenkins

14:01:36 GIT_BRANCH=origin/sergey/bugfix

14:01:36 EXECUTOR_NUMBER=1

As you can see GIT_BRANCH got set to "origin/sergey/bugfix"

and this is wrong because we asked for branch to match origin/ready/**

This causes problems in our build process

---
Originally reported by sleonovich, imported from: Git plugin sets wrong branch name GIT_BRANCH (more than 2 branches with same SHA1)


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

Raw content of original issue

Git plugin ver: 2.4.4

In jenkins job we configure Git plugin ->
Branches to build/Branch specifier: origin/ready/**

Developer pushes code to central git repository, which Jenkins check into 2 branches:
git push origin bugfix:sergey/bugfix
git push origin bugfix:ready/bugfix

When Jenkins job kicks in, it provides this output:

14:01:36 > git branch -a -v --no-abbrev --contains 24ef859065480d5ac965652cfce8a0dd959fd082 # timeout=10
14:01:36 Checking out Revision 24ef859065480d5ac965652cfce8a0dd959fd082 (origin/sergey/bugfix, origin/ready/bugfix)
..
..

14:01:36 HOME=/var/lib/jenkins
14:01:36 GIT_BRANCH=origin/sergey/bugfix
14:01:36 EXECUTOR_NUMBER=1

As you can see GIT_BRANCH got set to "origin/sergey/bugfix"
and this is wrong because we asked for branch to match origin/ready/**

This causes problems in our build process

  • environment: Production

1 attachment

- [screenshot-1.png](https://raw.githubusercontent.com/jenkinsci/attachments-from-jira-issues-last/refs/heads/main/attachments/32378/screenshot-1.png)
> ![screenshot-1.png](https://raw.githubusercontent.com/jenkinsci/attachments-from-jira-issues-last/refs/heads/main/attachments/32378/screenshot-1.png)

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.