Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-61317

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

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • None

      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

       

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

          bon ch created issue -
          Mark Waite made changes -
          Assignee Original: Mark Waite [ markewaite ]

          Mark Waite added a comment -

          Please provide an example pipeline which shows the issue using a publicly accessible git repository.

          Mark Waite added a comment - Please provide an example pipeline which shows the issue using a publicly accessible git repository.

          bon ch added a comment -

          markewaite

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

          Jenkinsfile in master branch Last commit : 64dd9920
          library in jenkins-lib branch Last commit: a8c235b1

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

          [Pipeline] echo
          13:22:18 stage 1
          [Pipeline] echo
          13:22:18 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9
          [Pipeline] echo
          13:22:18 Hello world
          [Pipeline] }

           

          bon ch added a comment - markewaite I create example repo to this issue: https://github.com/bonfy/JENKINS-61317 Jenkinsfile in master branch Last commit : 64dd9920 library in jenkins-lib branch Last commit: a8c235b1 and when echo GIT_COMMIT, it is overwitten by lib's commit [Pipeline] echo 13:22:18 stage 1 [Pipeline] echo 13:22:18 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9 [Pipeline] echo 13:22:18 Hello world [Pipeline] }  

          Mark Waite added a comment - - edited

          Thank you. Until a fix is available for the issue, you can use the returnStdout capability of the sh and bat and powershell commands to call git rev-parse HEAD

          Mark Waite added a comment - - edited Thank you. Until a fix is available for the issue, you can use the returnStdout capability of the sh and bat and powershell commands to call git rev-parse HEAD

          bon ch added a comment -

          ok, thx

          bon ch added a comment - ok, thx

          bon ch added a comment -

          markewaite

           

          I update the repo https://github.com/bonfy/JENKINS-61317

          Add echo env.GIT_BRANCH, and find that the GIT_BRANCH is also overwritten, maybe other git related env valuables as well.  So maybe you can check and fix them together.

           

          the Jenkins console output now looks like: 

           

          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

           

          Thanks

          bon ch added a comment - markewaite   I update the repo  https://github.com/bonfy/JENKINS-61317 Add echo env.GIT_BRANCH, and find that the GIT_BRANCH is also overwritten, maybe other git related env valuables as well.  So maybe you can check and fix them together.   the Jenkins console output now looks like:    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   Thanks
          bon ch made changes -
          Description Original: 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
          New: 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

          [Pipeline] echo
          13:22:18 stage 1
          [Pipeline] echo
          13:22:18 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9
          [Pipeline] echo
          13:22:18 Hello world
          [Pipeline] }

           
          bon ch made changes -
          Description Original: 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

          [Pipeline] echo
          13:22:18 stage 1
          [Pipeline] echo
          13:22:18 GIT COMMIT : a8c235b10c55e2f065293b1c1ad9b3bffd45d9d9
          [Pipeline] echo
          13:22:18 Hello world
          [Pipeline] }

           
          New: 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

           

          Dee Kryvenko added a comment -

          Dee Kryvenko added a comment - Seems like the same as  https://issues.jenkins-ci.org/browse/JENKINS-45489

            Unassigned Unassigned
            bonfy bon ch
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: