Add git clone over ssh protocol
We need to have some short-hand for clonning over ssh:// protocol
this patch implements such functionality.
Usage example:
node {
gitSSHCheckout {
credentialsId = "mcp-ci-gerrit"
branch = "mcp-0.1"
host = "ci.mcp-ci.local"
project = "projectcalico/calico-containers"
}
}
Change-Id: I5f8390cdbbd3df06cffa703190534fe10ecfd1ca
diff --git a/vars/gitSSHCheckout.groovy b/vars/gitSSHCheckout.groovy
new file mode 100644
index 0000000..7096c61
--- /dev/null
+++ b/vars/gitSSHCheckout.groovy
@@ -0,0 +1,28 @@
+def call(body) {
+ // evaluate the body block, and collect configuration into the object
+ def config = [:]
+ body.resolveStrategy = Closure.DELEGATE_FIRST
+ body.delegate = config
+ body()
+
+ def target_dir = config.target_dir ?: "./"
+ def port = config.port ?: "29418"
+
+ stage("Git Checkout"){
+ checkout(
+ scm: [
+ $class: 'GitSCM',
+ branches: [[name: "${config.branch}"]],
+ extensions: [
+ [$class: 'CleanCheckout'],
+ [$class: 'RelativeTargetDirectory', relativeTargetDir: "${target_dir}"]
+ ],
+ userRemoteConfigs: [[
+ credentialsId: "${config.credentialsId}",
+ name: 'origin',
+ url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git"
+ ]]
+ ]
+ )
+ }
+}
diff --git a/vars/gitSSHCheckout.txt b/vars/gitSSHCheckout.txt
new file mode 100644
index 0000000..087d018
--- /dev/null
+++ b/vars/gitSSHCheckout.txt
@@ -0,0 +1,27 @@
+// Default parameters
+
+ target_dir = "./"
+ port = "29418"
+
+// Usage example
+node {
+ gitSSHCheckout {
+ credentialsId = "mcp-ci-gerrit"
+ branch = "mcp-0.1"
+ host = "ci.mcp-ci.local"
+ project = "projectcalico/calico-containers"
+ }
+}
+
+// or
+
+node {
+ gitSSHCheckout {
+ credentialsId = "mcp-ci-gerrit"
+ branch = "mcp-0.1"
+ host = "ci.mcp-ci.local"
+ project = "projectcalico/calico-containers"
+ target_dir = "some_directory"
+ }
+}
+