Accessing SCM (Git) variables on a Jenkins Pipeline job

This question already has an answer here:

  • Git Variables in Jenkins Workflow plugin

    4 answers

  • How to handle non-standard subversion import to Git
  • Getting rid of temp-xxxx.rdb files
  • How can I see the git command command output in my Jenkins Console Log for a build?
  • how to add all currently untracked files/folders to git ignore?
  • Using GIT with GIT GUI - Master and Branching
  • How do I stop pushing to multiple remote branches in git? (aka, How do I untrack remote git branches?)
  • Merging two branches A and B where A contains files that were deleted from B
  • How would working directory look like in tree diagram?
  • Branches transferred with svn2git
  • Sparse checkout and shallow clone
  • Git refuses to remove a branch
  • Integrating public git repository into private project (without submodules or subtree merge)
  • One Solution collect form web for “Accessing SCM (Git) variables on a Jenkins Pipeline job”

    Here is an example of how you can get GIT_COMMIT –

    You can extend it to expose GIT_BRANCH as well. This script is from the workflow examples git repo managed by cloudbees. Maybe you can send a pull request if you add capability to retrieve GIT_BRANCH variable.

    Git Baby is a git and github fan, let's start git clone.