blob: aa2d2fed3d1154c39bb2a008101d32ac7739578d [file] [log] [blame]
Igor Belikov9021bbe2016-09-28 19:22:20 +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 Kulanov6a0686a2016-09-30 14:53:18 +03008
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
Igor Belikov9021bbe2016-09-28 19:22:20 +030026 stage("Gerrit Patchset Checkout") {
27 checkout(
28 scm: [
29 $class: 'GitSCM',
30 branches: [[name: "${GERRIT_BRANCH}"]],
Sergey Kulanov6a0686a2016-09-30 14:53:18 +030031 extensions: scmExtensions,
Igor Belikov9021bbe2016-09-28 19:22:20 +030032 userRemoteConfigs: [[
33 credentialsId: "${config.credentialsId}",
34 name: 'gerrit',
35 url: "ssh://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}.git",
36 refspec: "${GERRIT_REFSPEC}"
37 ]]
38 ]
39 )
40 }
41}