Add two non-mandatory options to gerritPatchsetCheckout
In some cases we need to be able to wipe before checkout
and merge checkouted code before starting build. This
patch introduces such changes.
Merge feature is used together with pip install from git
repo, since everything should be merged in branch before
running:
pip git+https://path_to_repo@branch
example:
// Usage example with merging to checkouted branch
node {
gerritPatchsetCheckout{
credentialsId = "credentials-id-string"
withMerge = true
}
}
Change-Id: Ic35725db554c4e5d9e70c338999cf14eb29c1559
diff --git a/vars/gerritPatchsetCheckout.groovy b/vars/gerritPatchsetCheckout.groovy
index 363a256..aa2d2fe 100644
--- a/vars/gerritPatchsetCheckout.groovy
+++ b/vars/gerritPatchsetCheckout.groovy
@@ -5,15 +5,30 @@
body.delegate = config
body()
+
+ def merge = config.withMerge ?: false
+ def wipe = config.withWipeOut ?: false
+
+ // default parameters
+ def scmExtensions = [
+ [$class: 'CleanCheckout'],
+ [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
+ ]
+ // if we need to "merge" code from patchset to GERRIT_BRANCH branch
+ if (merge) {
+ scmExtensions.add([$class: 'LocalBranch', localBranch: "${GERRIT_BRANCH}"])
+ }
+ // we need wipe workspace before checkout
+ if (wipe) {
+ scmExtensions.add([$class: 'WipeWorkspace'])
+ }
+
stage("Gerrit Patchset Checkout") {
checkout(
scm: [
$class: 'GitSCM',
branches: [[name: "${GERRIT_BRANCH}"]],
- extensions: [
- [$class: 'CleanCheckout'],
- [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
- ],
+ extensions: scmExtensions,
userRemoteConfigs: [[
credentialsId: "${config.credentialsId}",
name: 'gerrit',
diff --git a/vars/gerritPatchsetCheckout.txt b/vars/gerritPatchsetCheckout.txt
index 4575695..2372bf6 100644
--- a/vars/gerritPatchsetCheckout.txt
+++ b/vars/gerritPatchsetCheckout.txt
@@ -4,3 +4,19 @@
credentialsId = "credentials-id-string"
}
}
+
+// Usage example with merging to checkouted branch
+node {
+ gerritPatchsetCheckout{
+ credentialsId = "credentials-id-string"
+ withMerge = true
+ }
+}
+
+// wipe our repository and force clone
+node {
+ gerritPatchsetCheckout{
+ credentialsId = "credentials-id-string"
+ withWipeOut = true
+ }
+}