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 |
Igor Belikov | 4dc96cd | 2016-09-30 12:26:18 +0300 | [diff] [blame] | 9 | def targetDir = config.targetDir ?: "./" |
Sergey Kulanov | 72f763e | 2016-09-29 17:08:44 +0300 | [diff] [blame] | 10 | def port = config.port ?: "29418" |
| 11 | |
Sergey Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame^] | 12 | // 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 Kulanov | 0a7c17c | 2016-09-30 17:47:22 +0300 | [diff] [blame] | 23 | checkout( |
| 24 | scm: [ |
| 25 | $class: 'GitSCM', |
| 26 | branches: [[name: "${config.branch}"]], |
Sergey Kulanov | bd766a4 | 2016-10-28 17:03:55 +0300 | [diff] [blame^] | 27 | extensions: scmExtensions, |
Sergey Kulanov | 0a7c17c | 2016-09-30 17:47:22 +0300 | [diff] [blame] | 28 | userRemoteConfigs: [[ |
| 29 | credentialsId: "${config.credentialsId}", |
| 30 | name: 'origin', |
| 31 | url: "ssh://${config.credentialsId}@${config.host}:${port}/${config.project}.git" |
| 32 | ]] |
| 33 | ] |
| 34 | ) |
Sergey Kulanov | 72f763e | 2016-09-29 17:08:44 +0300 | [diff] [blame] | 35 | } |