On normal maven/freestyle jobs the checked out branch can be parameterized with job parameters.
The following job uses the workflow plugin to pull a groovy script from scm.
Here the ${branch} variable is not substituted.
<?xml version="1.0" encoding="UTF-8"?>
<flow-definition plugin="workflow-job@1.15">
<actions />
<description>WARNING: this jobs fails due to not substituting ${branch} on ckeckout.</description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.3">
<useBuildBlocker>false</useBuildBlocker>
<blockLevel>GLOBAL</blockLevel>
<scanQueueFor>DISABLED</scanQueueFor>
<blockingJobs />
</hudson.plugins.buildblocker.BuildBlockerProperty>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>releaseVersion</name>
<description />
<defaultValue />
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>branch</name>
<description />
<defaultValue>6.4.x</defaultValue>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@1.15">
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.4.3">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>ssh: </hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>refs/heads/${branch}</name><!-- THIS should be substituted but isn't -->
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list" />
</scm>
<scriptPath>releasePipeline.groovy</scriptPath>
</definition>
<triggers />
</flow-definition>
The result is:
when it really should substitute ${branch} with 6.4.x as it does in the rest of the script.