Jenkins Workflow Checkout Accessing BRANCH_NAME and GIT_COMMIT
<p>I cannot seem to extract $GIT_COMMIT and $BRANCH_NAME from a Jenkins Workflow Checkout step.</p>

<p>I would like to be able to send this information through to my Gradle scripts in order to pass it onto external sources such as Static analysis etc.</p>

<p>Currently I try to run this:</p>

<pre><code>checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[credentialsId: '2b74a351-67d5-4d00-abd3-49842a984201', url: 'ssh://git@corporate.com:repo.git']]])
</code></pre>

<p>And I would like to achieve the following or something similar:</p>

<pre><code>// Specified variables that can be reused
def branch = ${BRANCH_NAME}
def commit = ${GIT_COMMIT}
</code></pre>

<p>Or maybe this would work too:</p>

<pre><code>print "BRANCH: ${BRANCH_NAME}, COMMIT: ${GIT_COMMIT}"
// or the following
print "BRANCH: ${env.BRANCH_NAME}, COMMIT: ${env.GIT_COMMIT}"
</code></pre>

<p>I did find the following issue which seems to be resolved but it doesn't work in version 1.15:</p>

<p><a href="https://issues.jenkins-ci.org/browse/JENKINS-30252" rel="noreferrer">https://issues.jenkins-ci.org/browse/JENKINS-30252</a></p>

<p>Anyone have any ideas how to workaround this or if there's a variable I cannot find?</p>