blob: 46b76bcdac712d27c1b2d2e6c5df24f3852c8fab [file] [log] [blame]
Sergey Kulanov72f763e2016-09-29 17:08:44 +03001def call(body) {
2 // evaluate the body block, and collect configuration into the object
3 def config = [:]
4 body.resolveStrategy = Closure.DELEGATE_FIRST
5 body.delegate = config
6 body()
7
Sergey Kulanovbd766a42016-10-28 17:03:55 +03008 def merge = config.withMerge ?: false
Igor Belikov4dc96cd2016-09-30 12:26:18 +03009 def targetDir = config.targetDir ?: "./"
Sergey Kulanov72f763e2016-09-29 17:08:44 +030010 def port = config.port ?: "29418"
11
Sergey Kulanovbd766a42016-10-28 17:03:55 +030012 // default parameters
13 def scmExtensions = [
14 [$class: 'CleanCheckout'],
15 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
16 ]
17
18 // https://issues.jenkins-ci.org/browse/JENKINS-6856
19 if (merge) {
20 scmExtensions.add([$class: 'LocalBranch', localBranch: "${config.branch}"])
21 }
22
Sergey Kulanov0a7c17c2016-09-30 17:47:22 +030023 checkout(
24 scm: [
25 $class: 'GitSCM',
26 branches: [[name: "${config.branch}"]],
Sergey Kulanovbd766a42016-10-28 17:03:55 +030027 extensions: scmExtensions,
Sergey Kulanov0a7c17c2016-09-30 17:47:22 +030028 userRemoteConfigs: [[
29 credentialsId: "${config.credentialsId}",
30 name: 'origin',
31 url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git"
32 ]]
33 ]
34 )
Sergey Kulanov72f763e2016-09-29 17:08:44 +030035}