Fix gating job for cookiecutter templates and reclass-system

 * Fix passing of GERRIT_* params, to be able correctly process
   each of jobs in downstream call's

Related-Bug: PROD-23343 (PROD:23343)

Change-Id: I1b3a4610ec91f1d53a4043d282f1b112860c057a
diff --git a/gating-pipeline.groovy b/gating-pipeline.groovy
index 99f487d..c4376e8 100644
--- a/gating-pipeline.groovy
+++ b/gating-pipeline.groovy
@@ -47,10 +47,23 @@
                         if (isJobExists(testJob)) {
                             common.infoMsg("Test job ${testJob} found, running")
                             def patchsetVerified = gerrit.patchsetHasApproval(gerritChange.currentPatchSet, "Verified", "+")
-                            build job: testJob, parameters: [
-                                [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"],
-                                [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: GERRIT_REFSPEC]
-                            ]
+                            // temp workaround, will be removed after full switch
+                            if (gerritProject == "cookiecutter-templates" || gerritProject == "reclass-system") {
+                                def gerritVars = '\n---'
+                                for (envVar in env.getEnvironment()) {
+                                    if (envVar.key.startsWith("GERRIT_")) {
+                                        gerritVars += "\n${envVar}"
+                                    }
+                                }
+                                build job: testJob, parameters: [
+                                    [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', value: gerritVars ]
+                                ]
+                            } else {
+                                build job: testJob, parameters: [
+                                    [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"],
+                                    [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: GERRIT_REFSPEC]
+                                ]
+                            }
                             giveVerify = true
                         } else {
                             common.infoMsg("Test job ${testJob} not found")
diff --git a/test-cookiecutter-reclass.groovy b/test-cookiecutter-reclass.groovy
index 6813be9..598ab01 100644
--- a/test-cookiecutter-reclass.groovy
+++ b/test-cookiecutter-reclass.groovy
@@ -17,6 +17,10 @@
 git = new com.mirantis.mk.Git()
 python = new com.mirantis.mk.Python()
 
+if (env.EXTRA) {
+    common.mergeEnv(env, env.EXTRA)
+}
+
 slaveNode = env.SLAVE_NODE ?: 'docker'
 checkIncludeOrder = env.CHECK_INCLUDE_ORDER ?: false
 
diff --git a/test-system-reclass-pipeline.groovy b/test-system-reclass-pipeline.groovy
index 47dde97..3a3f2f1 100644
--- a/test-system-reclass-pipeline.groovy
+++ b/test-system-reclass-pipeline.groovy
@@ -1,13 +1,15 @@
 def gerrit = new com.mirantis.mk.Gerrit()
 def common = new com.mirantis.mk.Common()
 
+if (env.EXTRA) {
+    common.mergeEnv(env, env.EXTRA)
+}
 
 def slaveNode = env.SLAVE_NODE ?: 'python&&docker'
 def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit'
 
 def gerritRef = env.GERRIT_REFSPEC ?: null
-def defaultGitRef = env.DEFAULT_GIT_REF ?: null
-def defaultGitUrl = env.DEFAULT_GIT_URL ?: null
+def defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
 
 def checkouted = false
 def merged = false
@@ -28,10 +30,8 @@
                         ])
                         systemRefspec = GERRIT_REFSPEC
                     }
-                    // change defaultGit variables if job triggered from Gerrit
-                    defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
-                } else if (defaultGitRef && defaultGitUrl) {
-                    checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
+                } else if (gerritRef && defaultGitUrl) {
+                    checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, gerritRef, "HEAD", gerritCredentials)
                 }
             }