title: Get Git Branch Name that Triggered Jenkins Build
body: <p>I have a Jenkins file and a Git Hook that triggers the Jenkins build whenever a code is committed in any of the branches.</p>
  <p>I wish to print the branch name that triggered the Jenkins Build.</p>
  <p>In the <code>checkout</code> stage below I tried to print the branch name but it prints &quot;Null&quot; for <code>println git_params[&quot;GIT_BRANCH&quot;]</code> instead of the branch name that committed the code and triggered the Jenkins build.</p>
  <pre class="lang-js prettyprint-override"><code>pipeline {
    agent any
  
    environment {
      GIT_CRED_ID = 'SVC-JENKINS-ADM'
  
      GIT_REPO = 'https://bitbucket.hmc.com/scm/mh/docker.git'
    }
  
    stages {
      stage('checkout') {
        steps {
          script {
            def git_params = checkout([$class: 'GitSCM'])
  
            println(git_params)
  
            println 'Getting current Branch'
  
            println git_params['GIT_BRANCH']
          }
        }
      }
  
      stage('DEV') {
        agent any
  
        steps {
          script {
            timeout(time: 25, unit: 'MINUTES') {
              waitUntil {
                try {
                  node() {
                    timestamps {
                      task 'Build Environment Setup'
                      //Loading  environment variables
                      checkout([
                        $class: 'GitSCM',
                        branches: [
                          [name: '*/develop']
                        ],
                        [$class: 'WipeWorkspace'],
                      ],
                        userRemoteConfigs: [[credentialsId: env.GIT_CRED_ID, url: env.GIT_REPO]]
                      )
                      dir('temp1') {
                        checkout([
                          $class: 'GitSCM',
                          branches: [
                            [name: '*/master']
                          ],
                          userRemoteConfigs: [[credentialsId: env.GIT_CRED_ID, url: env.GIT_REPO]]
                        ])
                      }
                      load &quot;temp1/${APP_NAME}_${env.ENV}_EnvFile&quot;
                      env.APP_VERSION = sh(script: 'temp1/git_version.sh', returnStdout: true).toString().trim()
                      sh 'echo REL#=$APP_VERSION'
                    }
                  }
  
                  emailext attachLog: true, body: &quot;PIPELINE SUCCESS - ${JOB_URL}  \n  Check the full log here&quot;, subject: &quot;PIPELINE SUCCESS - ${env.ENV.toUpperCase()} - ${currentBuild.fullDisplayName}&quot;, recipientProviders: [developers(), requestor()], to: &quot;$EMAIL_DEPLOYERS&quot;
  
                  return true
                }
  
                catch (error) {
                  echo &quot;Failed in stage : ${env.ENV.toUpperCase()}&quot;
  
                  emailext attachLog: true, body: &quot;PIPELINE FAILED - ${JOB_URL}  \n  Check the full log here&quot;, subject: &quot;PIPELINE FAILED - ${env.ENV.toUpperCase()} - ${currentBuild.fullDisplayName}&quot;, to: &quot;$EMAIL_DEPLOYERS&quot;
  
                  throw error
  
                  return false
  
                  System.exit(0)
                }
              }
            }
          }
        }
      }
    }
  }
  
  </code></pre>
  <p>Note: in the debug logs the branch name gets printed but I cant print it using <code>println git_params[&quot;GIT_BRANCH&quot;]</code> explicitly.</p>
  <p>Can you please suggest ?</p>