Sergey Kulanov | 72f763e | 2016-09-29 17:08:44 +0300 | [diff] [blame] | 1 | def 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 Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame] | 8 | def merge = config.withMerge ?: false |
Sergey Kulanov | 0327d50 | 2016-12-20 13:10:39 +0200 | [diff] [blame] | 9 | def wipe = config.withWipeOut ?: false |
Igor Belikov | 4dc96cd | 2016-09-30 12:26:18 +0300 | [diff] [blame] | 10 | def targetDir = config.targetDir ?: "./" |
Sergey Kulanov | 72f763e | 2016-09-29 17:08:44 +0300 | [diff] [blame] | 11 | def port = config.port ?: "29418" |
| 12 | |
Sergey Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame] | 13 | // 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 Kulanov | 0327d50 | 2016-12-20 13:10:39 +0200 | [diff] [blame] | 23 | // we need wipe workspace before checkout |
| 24 | if (wipe) { |
| 25 | scmExtensions.add([$class: 'WipeWorkspace']) |
| 26 | } |
Sergey Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame] | 27 | |
Sergey Kulanov | 0a7c17c | 2016-09-30 17:47:22 +0300 | [diff] [blame] | 28 | checkout( |
| 29 | scm: [ |
| 30 | $class: 'GitSCM', |
| 31 | branches: [[name: "${config.branch}"]], |
Sergey Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame] | 32 | extensions: scmExtensions, |
Sergey Kulanov | 0a7c17c | 2016-09-30 17:47:22 +0300 | [diff] [blame] | 33 | userRemoteConfigs: [[ |
| 34 | credentialsId: "${config.credentialsId}", |
| 35 | name: 'origin', |
| 36 | url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git" |
| 37 | ]] |
| 38 | ] |
| 39 | ) |
Sergey Kulanov | 72f763e | 2016-09-29 17:08:44 +0300 | [diff] [blame] | 40 | } |