how to get git short hash in to a variable in Jenkins running on windows 2008
I didn't see this answer listed here so thought I'd add it:
environment {
GIT_HASH = GIT_COMMIT.take(7)
}
Source: https://issues.jenkins-ci.org/browse/JENKINS-44449?focusedCommentId=361307&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-361307
Probably the simplest way to achieve the result you want would be to use the GIT_REVISION token makro, like this:
${GIT_REVISION,length=6}
Have a look at https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin for more details.
Hope this helps,
Jan
This worked for me in a jenkins pipeline using the git plugin:
SHORT_COMMIT = "${GIT_COMMIT[0..7]}"