Add withMerge flag for gitSSHCheckout step
Rather than merge the changes to be built into a branch which
tracks the remote I want to push to, it checks out one rev and
merges the others on, resulting in a detached HEAD.
Some tools expects to be run on a specific branch, and it
fails because the repo isn't in that state.
[1]. https://issues.jenkins-ci.org/browse/JENKINS-6856
Change-Id: I9d6e2caf639d1aba651ae5f709c6369ea2848546
diff --git a/vars/gitSSHCheckout.groovy b/vars/gitSSHCheckout.groovy
index 0bb696f..46b76bc 100644
--- a/vars/gitSSHCheckout.groovy
+++ b/vars/gitSSHCheckout.groovy
@@ -5,17 +5,26 @@
body.delegate = config
body()
+ def merge = config.withMerge ?: false
def targetDir = config.targetDir ?: "./"
def port = config.port ?: "29418"
+ // default parameters
+ def scmExtensions = [
+ [$class: 'CleanCheckout'],
+ [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
+ ]
+
+ // https://issues.jenkins-ci.org/browse/JENKINS-6856
+ if (merge) {
+ scmExtensions.add([$class: 'LocalBranch', localBranch: "${config.branch}"])
+ }
+
checkout(
scm: [
$class: 'GitSCM',
branches: [[name: "${config.branch}"]],
- extensions: [
- [$class: 'CleanCheckout'],
- [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
- ],
+ extensions: scmExtensions,
userRemoteConfigs: [[
credentialsId: "${config.credentialsId}",
name: 'origin',