jenkinsci / jenkinsci/git-plugin

[JENKINS-12655] GIT_BRANCH is incorrect in build steps when branch choosing strategy is set to inverse (but it is correct in build name macro)

Open
#2,110 4 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

Context: I'm trying to create a parameterized job chain for our branches.

Version info:

Jenkins 1.450

Git 1.1.15

build-name-setter 1.3

parametrized trigger 2.12

1) Set the git branch to */master and in advanced, select branching strategy = inverse

2) Set the build name (using plugin) to #${BUILD_NUMBER}.${GIT_BRANCH}

3) In the build, use shell to execute: echo ${BUILD_BRANCH}

4) Push a change into a branch in git then manually start the build in Jenkins

Result:

The build string is set correctly to the branch used in step#4, but the echo in step #3 incorrectly says origin/master. Note, that the wrong GIT_BRANCH is also sent in my parameterized trigger.

The setting for GIT_BRANCH is correct at all times when Default choosing strategy is selected.

---
Originally reported by rmorgenstein, imported from: GIT_BRANCH is incorrect in build steps when branch choosing strategy is set to inverse (but it is correct in build name macro)


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

Raw content of original issue

Context: I'm trying to create a parameterized job chain for our branches.
Version info:
Jenkins 1.450
Git 1.1.15
build-name-setter 1.3
parametrized trigger 2.12

1) Set the git branch to */master and in advanced, select branching strategy = inverse
2) Set the build name (using plugin) to #${BUILD_NUMBER}.${GIT_BRANCH}
3) In the build, use shell to execute: echo ${BUILD_BRANCH}
4) Push a change into a branch in git then manually start the build in Jenkins

Result:
The build string is set correctly to the branch used in step#4, but the echo in step #3 incorrectly says origin/master. Note, that the wrong GIT_BRANCH is also sent in my parameterized trigger.

The setting for GIT_BRANCH is correct at all times when Default choosing strategy is selected.


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.