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.
This is what I'm doing, based on the example provided in the Jenkins examples repo:
node {
git url: 'https://git.com/myproject.git'
sh 'git rev-parse --abbrev-ref HEAD > GIT_BRANCH'
git_branch = readFile('GIT_BRANCH').trim()
echo git_branch
sh 'git rev-parse HEAD > GIT_COMMIT'
git_commit = readFile('GIT_COMMIT').trim()
echo git_commit
}
Edit you can do this shorter via
git_commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()