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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.