| Igor Belikov | 9021bbe | 2016-09-28 19:22:20 +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 | 6a0686a | 2016-09-30 14:53:18 +0300 | [diff] [blame] | 8 |  | 
|  | 9 | def merge = config.withMerge ?: false | 
|  | 10 | def wipe = config.withWipeOut ?: false | 
|  | 11 |  | 
|  | 12 | // default parameters | 
|  | 13 | def scmExtensions = [ | 
|  | 14 | [$class: 'CleanCheckout'], | 
|  | 15 | [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']] | 
|  | 16 | ] | 
|  | 17 | // if we need to "merge" code from patchset to GERRIT_BRANCH branch | 
|  | 18 | if (merge) { | 
|  | 19 | scmExtensions.add([$class: 'LocalBranch', localBranch: "${GERRIT_BRANCH}"]) | 
|  | 20 | } | 
|  | 21 | // we need wipe workspace before checkout | 
|  | 22 | if (wipe) { | 
|  | 23 | scmExtensions.add([$class: 'WipeWorkspace']) | 
|  | 24 | } | 
|  | 25 |  | 
| Sergey Kulanov | 0a7c17c | 2016-09-30 17:47:22 +0300 | [diff] [blame] | 26 | checkout( | 
|  | 27 | scm: [ | 
|  | 28 | $class: 'GitSCM', | 
|  | 29 | branches: [[name: "${GERRIT_BRANCH}"]], | 
|  | 30 | extensions: scmExtensions, | 
|  | 31 | userRemoteConfigs: [[ | 
|  | 32 | credentialsId: "${config.credentialsId}", | 
|  | 33 | name: 'gerrit', | 
|  | 34 | url: "ssh://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}.git", | 
|  | 35 | refspec: "${GERRIT_REFSPEC}" | 
|  | 36 | ]] | 
|  | 37 | ] | 
|  | 38 | ) | 
| Igor Belikov | 9021bbe | 2016-09-28 19:22:20 +0300 | [diff] [blame] | 39 | } |