node {
if(env.BRANCH_NAME.startsWith("PR-")) {
if(env.CHANGE_TARGET != null) {
targetBranch = env.CHANGE_TARGET
}
echo "Source branches: ${scm.branches[0].name}"
def ffMode = 'FF_ONLY'
if(nonFFBranches.contains(scm.branches[0].name)) {
ffMode = 'NO_FF'
}
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false, depth: 0, timeout: 60], [$class: 'PruneStaleBranch'], [$class: 'CheckoutOption', timeout: 60], [$class: 'PreBuildMerge', options: [mergeRemote: 'origin', mergeTarget: targetBranch, fastForwardMode: ffMode]]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs,
browser: [$class: 'BitbucketWeb', repoUrl: 'https:]
])
} else {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: true, depth: 1, timeout: 60], [$class: 'PruneStaleBranch'], [$class: 'CheckoutOption', timeout: 60]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs,
browser: [$class: 'BitbucketWeb', repoUrl: 'https:]
])
}
}
There's interest in being able to have webhook-triggered non-PR builds build the specific commit from the event rather than HEAD as well.