When building using the Branch Source plugin setting so that PR's are discovered as merged with master the commit hash put in the env GIT_COMMIT is not a correct value.

       
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkout
      Fetching changes from the remote Git repository
      Cleaning workspace
      Fetching without tags
      Merging remotes/origin/master commit 327f14dfdcdf41c01089767ae1ee35409df56d0e into PR head commit b03e30ec40954b8b40ca85374e4cf1d8eb3511cb
      Merge succeeded, producing 7461047c83a98c6ded075bba1bc44f2386d526d6
      Checking out Revision 7461047c83a98c6ded075bba1bc44f2386d526d6 (PR-12)
      {{ > git rev-parse --is-inside-work-tree # timeout=10}}
      {{ > git config remote.origin.url ... # timeout=10}}
      {{ > git rev-parse --verify HEAD # timeout=10}}
      Resetting working tree
      {{ > git reset --hard # timeout=10}}
      {{ > git clean -fdx # timeout=10}}
      Fetching upstream changes from ...
      {{ > git --version # timeout=10}}
      using GIT_SSH to set credentials CI användare i GitHub
      {{ > git fetch --no-tags --progress ... +refs/pull/12/head:refs/remotes/origin/PR-12 +refs/heads/master:refs/remotes/origin/master}}
      {{ > git config core.sparsecheckout # timeout=10}}
      {{ > git checkout -f b03e30ec40954b8b40ca85374e4cf1d8eb3511cb}}
      {{ > git merge 327f14dfdcdf41c01089767ae1ee35409df56d0e # timeout=10}}
      {{ > git rev-parse HEAD^

      {commit}

      # timeout=10}}
      {{ > git config core.sparsecheckout # timeout=10}}
      {{ > git checkout -f 7461047c83a98c6ded075bba1bc44f2386d526d6}}
      Commit message: "Merge commit '327f14dfdcdf41c01089767ae1ee35409df56d0e' into HEAD"
      First time build. Skipping changelog.
      Cleaning workspace

      ...

      (later when I print $GIT_COMMIT in an sh step)
      GIT_COMMIT=26053fb12db6deb1f9b129b3d6dbeae505cbae39

      ...

      (to provide som debug info I issue some git command in the same sh step
      latest commit seams ok, since its the result of Jenkins merge locally in the workspace)
      08:42:44 + git log -10
      08:42:44 commit 7461047c83a98c6ded075bba1bc44f2386d526d6
      08:42:44 Merge: b03e30e 327f14d
      08:42:44 Author: Jenkins <nobody@nowhere>
      08:42:44 Date: Tue Jan 15 08:42:40 2019 +0100
      {{08:42:44 }}
      08:42:44 Merge commit '327f14dfdcdf41c01089767ae1ee35409df56d0e' into HEAD
      08:42:44

      ...

      (git show $GIT_COMMIT fails as the hash do not exist)
      08:42:44 + git show 26053fb12db6deb1f9b129b3d6dbeae505cbae39
      08:42:44 fatal: bad object 26053fb12db6deb1f9b129b3d6dbeae505cbae39 

       

      One maybe related issue is that we are depending on an shared library and I see that there has been changes to the behavior around shared libraries.

      This worked on:

      Git Plugin 3.8.0
      Branch Source Plugin 2.3.3
      Jenkins 2.138.3

       

          [JENKINS-55592] GIT_COMMIT contains unknown value

          Mark Waite added a comment -

          Since you're using a shared library, the initial checkout of the repository for the Jenkinsfile is followed by a checkout of the shared library and then may be followed by the merge. Each of those three operations has a SHA1.

          I suspect that is the SHA1 hash of the HEAD of the shared library. Can you confirm that?

          You may need to use the shell / bat technique to get the SHA1 of the HEAD of the workspace. Refer to getSHA1 as an example to do that.

          Mark Waite added a comment - Since you're using a shared library, the initial checkout of the repository for the Jenkinsfile is followed by a checkout of the shared library and then may be followed by the merge. Each of those three operations has a SHA1. I suspect that is the SHA1 hash of the HEAD of the shared library. Can you confirm that? You may need to use the shell / bat technique to get the SHA1 of the HEAD of the workspace. Refer to getSHA1 as an example to do that.

          Jonas Hoglin added a comment -

          markewaite, thanks for the prompt reply, I'm sorry to verify that the HEAD of the shared library was 3bea73fb25791df42493ae4daacd938c661d414c at the time of this build.

          Today this PR is closed and others are not displaying this error, so perhaps it might have been some unknown outside factor came into play for me yesterday. I'm downgrading the priority of this, and wait if the error occurs again under similar circumstances.

          Jonas Hoglin added a comment - markewaite , thanks for the prompt reply, I'm sorry to verify that the HEAD of the shared library was 3bea73fb25791df42493ae4daacd938c661d414c at the time of this build. Today this PR is closed and others are not displaying this error, so perhaps it might have been some unknown outside factor came into play for me yesterday. I'm downgrading the priority of this, and wait if the error occurs again under similar circumstances.

            Unassigned Unassigned
            jhoglin Jonas Hoglin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: