I\'d like to access git variables such as GIT_COMMIT and GIT_BRANCH when I have checked out a repository from git further down in the build stream.
The simplest way to fetch the Git variable in Jenkins through Jenkinsfile
node {
def scmVars = checkout scm
echo 'scm : the commit id is ' +scmVars.GIT_COMMIT
echo 'scm : the commit branch is ' +scmVars.GIT_BRANCH
echo 'scm : the previous commit id is ' +scmVars.GIT_PREVIOUS_COMMIT
def commitEmail = sh(returnStdout: true, script: "git --no-pager show -sformat=\'%ae\'")
echo " the commiter email is'${commitEmail}'"
def commitName = sh(returnStdout: true, script: "git --no-pager show -s format=\'%an\'")
echo " the commiter name is'${commitName}'"
}
In console you will get the
GIT_COMMIT:
GIT_BRANCH:
GIT_PREVIOUS_COMMIT:
commitEmail:
commitName: