jenkinsci / jenkinsci/git-plugin

[JENKINS-61317] env.GIT_COMMIT is overwritten when pull lib (lib and code in the same repo), can not get the right GIT_COMMIT

Open
#3,529 9 comments 1 reaction 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

env.GIT_COMMIT is overwritten when pull lib (lib and code in the same repo)

 

SharedLibrary put in the same code repo, different branch named xxx_lib, and after Declarative: Checkout SCM, can not get the right GIT_COMMIT, always be the xxx_lib's last commit, not the code's commit

 

 

I create example repo to this issue: https://github.com/bonfy/JENKINS-61317

Jenkinsfile in master branch Last commit: 39f25e1a

library in jenkins-lib branch Last commit: a8c235b1

and when echo GIT_COMMIT, it is overwitten by lib's commit

16:55:47 stage 1

[Pipeline] echo

16:55:47 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9

[Pipeline] echo

16:55:47 GIT BRANCH : jenkins-lib

[Pipeline] echo

16:55:48 Hello world

 

---
Originally reported by bonfy, imported from: env.GIT_COMMIT is overwritten when pull lib (lib and code in the same repo), can not get the right GIT_COMMIT


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

Raw content of original issue

env.GIT_COMMIT is overwritten when pull lib (lib and code in the same repo)

 

SharedLibrary put in the same code repo, different branch named xxx_lib, and after Declarative: Checkout SCM, can not get the right GIT_COMMIT, always be the xxx_lib's last commit, not the code's commit

 

 

I create example repo to this issue: https://github.com/bonfy/JENKINS-61317

Jenkinsfile in master branch Last commit: 39f25e1a
library in jenkins-lib branch Last commit: a8c235b1

and when echo GIT_COMMIT, it is overwitten by lib's commit

16:55:47 stage 1
[Pipeline] echo
16:55:47 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9
[Pipeline] echo
16:55:47 GIT BRANCH : jenkins-lib
[Pipeline] echo
16:55:48 Hello world

 

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.