0

I have JenkinsFile where I'm trying to get the hash for my current branch. I saw this post: https://stackoverflow.com/questions/9110478/how-to-find-the-hash-of-branch-in-git

but when I tried to run def BranchHash = sh "git rev-parse ${BRANCH-NAME} I got: fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree

I'm looking for the branch hash, and not the last commit

arielma
  • 339
  • 2
  • 9
  • 21

1 Answers1

2
git show -s --format="%H" <HEAD or Branch Name>

-s supressess the diff output

--format="%H" specifies that only the hash should be shown.

See man git-show for more details.

Rystraum
  • 136
  • 1