[feat][si] common function to store SI artifacts in jfrog

PRODX-17228

Change-Id: Ic73b857f9b45f1261faedd617b2dad63a21df035
diff --git a/src/com/mirantis/mk/Workflow.groovy b/src/com/mirantis/mk/Workflow.groovy
index 9281907..ef24280 100644
--- a/src/com/mirantis/mk/Workflow.groovy
+++ b/src/com/mirantis/mk/Workflow.groovy
@@ -483,3 +483,50 @@
         }
     } // finally
 }
+
+/**
+ * Upload artifacts from SI scenario in Jfrog artifactory
+ *
+ * @param:        entrypointDirectory   (string) directory that needs to be archieved
+ * @param:        storeArtsInJenkins    (bool) store artifacts in jenkins as well
+ */
+def manageArtifacts(entrypointDirectory, storeArtsInJenkins = false) {
+    def mcpArtifactory = new com.mirantis.mcp.MCPArtifactory()
+    artifactoryServerName = 'mcp-ci'
+    artifactoryRepoPath = "si-local/jenkins-job-artifacts/${JOB_NAME}/${BUILD_NUMBER}"
+    tests_log = "${entrypointDirectory}/tests.log"
+
+    if (fileExists(tests_log)) {
+        try {
+            size = sh([returnStdout: true, script: "stat --printf='%s' ${tests_log}"]).trim().toInteger()
+            // do not archive unless it is more than 50 MB
+            allowed_size = 1048576 * 50
+            if (size >= allowed_size) {
+                sh("gzip ${tests_log} || true")
+            }
+        } catch (e) {
+            print("Cannot determine tests.log filesize: ${e}")
+        }
+    }
+
+    if (storeArtsInJenkins) {
+        archiveArtifacts(
+            artifacts: "${entrypointDirectory}/**",
+            allowEmptyArchive: true
+        )
+    }
+    artConfig = [
+        deleteArtifacts: false,
+        artifactory    : artifactoryServerName,
+        artifactPattern: "${entrypointDirectory}/**",
+        artifactoryRepo: "artifactory/${artifactoryRepoPath}",
+    ]
+    artDescription = mcpArtifactory.uploadArtifactsToArtifactory(artConfig)
+    currentBuild.description += "${artDescription}<br>"
+
+    junit(testResults: "${entrypointDirectory}/**/*.xml", allowEmptyResults: true)
+
+    artifactoryServer = Artifactory.server(artifactoryServerName)
+    artifactsUrl = "${artifactoryServer.getUrl()}/artifactory/${artifactoryRepoPath}"
+    return artifactsUrl
+}