2

Context

This question relates to multibranch pipelines where the behaviour merges the PR with the target branch revision (see screenshot of settings)

behaviours from multibranch settings

In this case, the merge may cause a new merge commit. So for a trigger with a given commit from a repository:

commit in blue ocean header

We actually get a different value of the GIT_COMMIT envvar:

printenv output showing GIT_COMMIT

If a tool (such as a build reporting tool) needs to use the GIT_COMMIT envvar to pass information onto a service, it cannot then be linked back to the actual commit from the project (this is a screenshot from Bitbucket but this would be the same for any repo hosting service):

not found commit on Bitbucket

Question

How, in a pipeline step, can I find the commit 709502c is the actual genesis of this build, when the GIT_COMMIT is set to 6781a3d1 (which is not an actual commit in the project)?

M1ke
  • 6,166
  • 4
  • 32
  • 50
  • Would https://stackoverflow.com/a/51619550/6309 works better to get the right GIT_COMMIT? – VonC May 29 '22 at 06:48

1 Answers1

0

Maybe looking at git history can help?

REAL_GIT_COMMIT = sh (
            script: "git rev-parse HEAD",
            returnStdout: true,
    ).trim()
MaratC
  • 6,418
  • 2
  • 20
  • 27
  • That will just give me the current commit, which will be the merge of master and my test branch. I could try HEAD~1 but I am not sure that's guaranteed to be the branch commit that's being tested, because if the merge was able to fast forward, GIT_COMMIT is correct. – M1ke May 23 '22 at 19:20