blob: cf6e0e4ea9c14988cdf6ab5c7527fcf1f16e1a10 [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
Sergey Kulanov0327d502016-12-20 13:10:39 +02009 def wipe = config.withWipeOut ?: false
Igor Belikov4dc96cd2016-09-30 12:26:18 +030010 def targetDir = config.targetDir ?: "./"
Sergey Kulanov72f763e2016-09-29 17:08:44 +030011 def port = config.port ?: "29418"
12
Sergey Kulanovbd766a42016-10-28 17:03:55 +030013 // default parameters
14 def scmExtensions = [
15 [$class: 'CleanCheckout'],
16 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${targetDir}"]
17 ]
18
19 // https://issues.jenkins-ci.org/browse/JENKINS-6856
20 if (merge) {
21 scmExtensions.add([$class: 'LocalBranch', localBranch: "${config.branch}"])
22 }
Sergey Kulanov0327d502016-12-20 13:10:39 +020023 // we need wipe workspace before checkout
24 if (wipe) {
25 scmExtensions.add([$class: 'WipeWorkspace'])
26 }
Sergey Kulanovbd766a42016-10-28 17:03:55 +030027
Sergey Kulanov0a7c17c2016-09-30 17:47:22 +030028 checkout(
29 scm: [
30 $class: 'GitSCM',
31 branches: [[name: "${config.branch}"]],
Sergey Kulanovbd766a42016-10-28 17:03:55 +030032 extensions: scmExtensions,
Sergey Kulanov0a7c17c2016-09-30 17:47:22 +030033 userRemoteConfigs: [[
34 credentialsId: "${config.credentialsId}",
35 name: 'origin',
36 url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git"
37 ]]
38 ]
39 )
Sergey Kulanov72f763e2016-09-29 17:08:44 +030040}