Save cc-model artifacts to Artifactory

Save artifacts from cc-model-generation jobs to Artifactory:
* test-mk-cookiecutter-templates
* test-mk-cookiecutter-templates-chunk
* generate-salt-model-separated-products

Change-Id: I90d76858dbc9343388fffdebb1e028b7bb7805bf
Related-Prod: PROD-28146 (PROD:28146)
diff --git a/generate-cookiecutter-products.groovy b/generate-cookiecutter-products.groovy
index b672c4e..c407d7c 100644
--- a/generate-cookiecutter-products.groovy
+++ b/generate-cookiecutter-products.groovy
@@ -367,6 +367,19 @@
                 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
             }
             // common.sendNotification(currentBuild.result,"",["slack"])
+            stage('Save artifacts to Artifactory') {
+                def artifactory = new com.mirantis.mcp.MCPArtifactory()
+                def buildProps = [ "context=${context['cluster_name']}" ]
+                if (RequesterEmail != '' && !RequesterEmail.contains('example')) {
+                    buildProps.add("emailTo=${RequesterEmail}")
+                }
+                def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory([
+                    'artifactory': 'mcp-ci',
+                    'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${context['cluster_name']}-${BUILD_NUMBER}",
+                    'buildProps': buildProps,
+                ])
+                currentBuild.description += "<br/>${artifactoryLink}"
+            }
         }
     }
 }
diff --git a/test-cookiecutter-reclass-chunk.groovy b/test-cookiecutter-reclass-chunk.groovy
index aa0a65b..8c804a1 100644
--- a/test-cookiecutter-reclass-chunk.groovy
+++ b/test-cookiecutter-reclass-chunk.groovy
@@ -1,5 +1,3 @@
-package com.mirantis.mk
-
 def common = new com.mirantis.mk.Common()
 def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
 
@@ -14,8 +12,8 @@
 timeout(time: 1, unit: 'HOURS') {
     node(slaveNode) {
         stage("RunTest") {
+            extraVars = readYaml text: EXTRA_VARIABLES_YAML
             try {
-                extraVars = readYaml text: EXTRA_VARIABLES_YAML
                 currentBuild.description = extraVars.modelFile
                 sh(script:  'find . -mindepth 1 -delete || true', returnStatus: true)
                 sh(script: """
@@ -49,6 +47,17 @@
                 currentBuild.result = "FAILURE"
                 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
                 throw e
+            } finally {
+                stage('Save artifacts to Artifactory') {
+                    def artifactory = new com.mirantis.mcp.MCPArtifactory()
+                    def envGerritVars = [ "GERRIT_PROJECT=${extraVars.get('GERRIT_PROJECT', '')}", "GERRIT_CHANGE_NUMBER=${extraVars.get('GERRIT_CHANGE_NUMBER', '')}",
+                                          "GERRIT_PATCHSET_NUMBER=${extraVars.get('GERRIT_PATCHSET_NUMBER', '')}", "GERRIT_CHANGE_ID=${extraVars.get('GERRIT_CHANGE_ID', '')}",
+                                          "GERRIT_PATCHSET_REVISION=${extraVars.get('GERRIT_PATCHSET_REVISION', '')}" ]
+                    withEnv(envGerritVars) {
+                        def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory(['artifactory': 'mcp-ci', 'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${BUILD_NUMBER}"])
+                        currentBuild.description += "<br/>${artifactoryLink}"
+                    }
+                }
             }
         }
     }
diff --git a/test-cookiecutter-reclass.groovy b/test-cookiecutter-reclass.groovy
index bd5ec1e..e530bdc 100644
--- a/test-cookiecutter-reclass.groovy
+++ b/test-cookiecutter-reclass.groovy
@@ -458,7 +458,11 @@
             currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
             throw e
         } finally {
-            def dummy = "dummy"
+            stage('Save artifacts to Artifactory') {
+                def artifactory = new com.mirantis.mcp.MCPArtifactory()
+                def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory(['artifactory': 'mcp-ci', 'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${BUILD_NUMBER}"])
+                currentBuild.description += "<br/>${artifactoryLink}"
+            }
         }
     }
 }