Add saveMetaResult() function
The purpose of the function to store result of a job in yaml file so it
will be easily accessible and parsible from other jobs/scripts with
unified format. At least three mandatory fields must be always there.
Related-To: PRODX-11118
Change-Id: I92102f5dde4b5ff4b7bd256616793409d9cbc9d9
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 448935f..8f2474d 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -1192,3 +1192,22 @@
}
}
}
+
+/**
+ * Save metadata about results in yaml formatted file
+ * @param success (boolean) answer the question "was it success or not?"
+ * @param code (string) some generalized code to determine error
+ * @param msg (string) user-friendly message about what's happend (error?)
+ * @param extraMeta (map) additional data can be added to resulted yaml file trhoug this map
+ * @param dstFile (string) name of yaml file to store the data
+*/
+def saveMetaResult(Boolean success, String code, String msg, Map extraMeta = [:], String dstFile = 'result.yaml') {
+ Map result = extraMeta.clone()
+ result.putAll([
+ 'success': success,
+ 'code': code,
+ 'message': msg,
+ ])
+ writeYaml file: dstFile, data: result, overwrite: true
+ archiveArtifacts artifacts: dstFile
+}