Gerrit functions extracted into own file
Change-Id: I8589be350238b5886dd44d060266c2c599c9386b
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 02fcada..881f706 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -415,69 +415,4 @@
}
}
}
-}
-
-/**
- * Execute git clone and checkout stage from gerrit review
- *
- * @param config LinkedHashMap
- * config includes next parameters:
- * - credentialsId, id of user which should make checkout
- * - withMerge, prevent detached mode in repo
- * - withWipeOut, wipe repository and force clone
- *
- * Usage example:
- * //anonymous gerrit checkout
- * def gitFunc = new com.mirantis.mcp.Git()
- * gitFunc.gerritPatchsetCheckout([
- * withMerge : true
- * ])
- *
- * def gitFunc = new com.mirantis.mcp.Git()
- * gitFunc.gerritPatchsetCheckout([
- * credentialsId : 'mcp-ci-gerrit',
- * withMerge : true
- * ])
- */
-def gerritPatchsetCheckout(LinkedHashMap config) {
- def merge = config.get('withMerge', false)
- def wipe = config.get('withWipeOut', false)
- def credentials = config.get('credentialsId','')
-
- // default parameters
- def scmExtensions = [
- [$class: 'CleanCheckout'],
- [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
- ]
- def scmUserRemoteConfigs = [
- name: 'gerrit',
- refspec: "${GERRIT_REFSPEC}"
- ]
-
- if (credentials == '') {
- // then try to checkout in anonymous mode
- scmUserRemoteConfigs.put('url',"https://${GERRIT_HOST}/${GERRIT_PROJECT}")
- } else {
- // else use ssh checkout
- scmUserRemoteConfigs.put('url',"ssh://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}.git")
- scmUserRemoteConfigs.put('credentialsId',credentials)
- }
-
- // 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'])
- }
-
- checkout(
- scm: [
- $class: 'GitSCM',
- branches: [[name: "${GERRIT_BRANCH}"]],
- extensions: scmExtensions,
- userRemoteConfigs: [scmUserRemoteConfigs]
- ]
- )
-}
+}
\ No newline at end of file
diff --git a/src/com/mirantis/mk/Gerrit.groovy b/src/com/mirantis/mk/Gerrit.groovy
new file mode 100644
index 0000000..f389df5
--- /dev/null
+++ b/src/com/mirantis/mk/Gerrit.groovy
@@ -0,0 +1,71 @@
+package com.mirantis.mk
+
+/**
+ * Gerrit functions
+ *
+ */
+
+/**
+ * Execute git clone and checkout stage from gerrit review
+ *
+ * @param config LinkedHashMap
+ * config includes next parameters:
+ * - credentialsId, id of user which should make checkout
+ * - withMerge, prevent detached mode in repo
+ * - withWipeOut, wipe repository and force clone
+ *
+ * Usage example:
+ * //anonymous gerrit checkout
+ * def gitFunc = new com.mirantis.mcp.Git()
+ * gitFunc.gerritPatchsetCheckout([
+ * withMerge : true
+ * ])
+ *
+ * def gitFunc = new com.mirantis.mcp.Git()
+ * gitFunc.gerritPatchsetCheckout([
+ * credentialsId : 'mcp-ci-gerrit',
+ * withMerge : true
+ * ])
+ */
+def gerritPatchsetCheckout(LinkedHashMap config) {
+ def merge = config.get('withMerge', false)
+ def wipe = config.get('withWipeOut', false)
+ def credentials = config.get('credentialsId','')
+
+ // default parameters
+ def scmExtensions = [
+ [$class: 'CleanCheckout'],
+ [$class: 'BuildChooserSetting', buildChooser: [$class: 'GerritTriggerBuildChooser']]
+ ]
+ def scmUserRemoteConfigs = [
+ name: 'gerrit',
+ refspec: config.get('gerritRefSpec','')
+ ]
+
+ if (credentials == '') {
+ // then try to checkout in anonymous mode
+ scmUserRemoteConfigs.put('url', config.get('gerritUrl',''))
+ } else {
+ // else use ssh checkout
+ scmUserRemoteConfigs.put('url',config.get('gerritUrl',''))
+ scmUserRemoteConfigs.put('credentialsId',credentials)
+ }
+
+ // if we need to "merge" code from patchset to GERRIT_BRANCH branch
+ if (merge) {
+ scmExtensions.add([$class: 'LocalBranch', localBranch: config.get('gerritBranch','master')])
+ }
+ // we need wipe workspace before checkout
+ if (wipe) {
+ scmExtensions.add([$class: 'WipeWorkspace'])
+ }
+
+ checkout(
+ scm: [
+ $class: 'GitSCM',
+ branches: [[name: config.get('gerritBranch','master')]],
+ extensions: scmExtensions,
+ userRemoteConfigs: [scmUserRemoteConfigs]
+ ]
+ )
+}
\ No newline at end of file
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index bfd00e5..55218cc 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -128,7 +128,7 @@
ssl.prepareSshAgentKey(credentialsId)
ssl.ensureKnownHosts(targetUrl)
- sh "git remote | grep target || git remote add target ${TARGET_URL}"
+ sh "git remote | grep target || git remote add target ${targetUrl}"
agentSh "git remote update --prune"
for (i=0; i < branches.size; i++) {
branch = branches[i]