Denis Egorenko | ff32a4d | 2016-12-21 14:41:53 +0000 | [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 | |
| 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 | |
| 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 | ) |
| 39 | } |