Add ability to write values from file
Currently when running through tox artefact meta app
works incorrectly with multiline/json values, to fix this
it is possible to supply values from file.
Flag values from file allows to use temporary files,
to read values from.
Related-Prod: https://mirantis.jira.com/browse/PRODX-3921
Change-Id: I8f0198cc164ffac614767a1991a229f98b88a430
diff --git a/src/com/mirantis/mk/ReleaseWorkflow.groovy b/src/com/mirantis/mk/ReleaseWorkflow.groovy
index 1302bbe..66e52d6 100644
--- a/src/com/mirantis/mk/ReleaseWorkflow.groovy
+++ b/src/com/mirantis/mk/ReleaseWorkflow.groovy
@@ -85,6 +85,8 @@
* - crTopic
* - crAuthorName
* - crAuthorEmail
+ * - valuesFromFile (allows to pass json strings, write them to temp files and pass files to
+ * app)
* @param dirdepth level of creation dirs from key param
*/
@@ -103,6 +105,7 @@
String crTopic = params.get('crTopic', '')
String changeAuthorName = params.get('crAuthorName', 'MCP-CI')
String changeAuthorEmail = params.get('crAuthorEmail', 'mcp-ci-jenkins@ci.mcp.mirantis.net')
+ Boolean valuesFromFile = params.get('valuesFromFile', false)
def cred = common.getCredentials(gitCredentialsId, 'key')
String gerritUser = cred.username
@@ -147,7 +150,23 @@
if (keyArr.size() == valueArr.size()) {
docker.image(toxDockerImage).inside("--volume ${repoDir}:/workspace") {
for (i in 0..keyArr.size()-1) {
- sh "cd /workspace && tox -qq -e metadata -- update --create --key '${keyArr[i]}' --value '${valueArr[i]}'"
+ def valueExpression = "--value '${valueArr[i]}'"
+ def tmpFile
+ if (valuesFromFile){
+ def data = readJSON text: valueArr[i]
+ // just print temp file name, so writeyaml can write it
+ tmpFile = sh(script: "mktemp -u -p ${workspace} meta_key_file.XXXXXX", returnStdout: true).trim()
+ // yaml is native format for meta app for loading values
+ writeYaml data: data, file: tmpFile
+ valueExpression = "--file ${tmpFile}"
+ }
+ try {
+ sh "cd /workspace && tox -qq -e metadata -- update --create --key '${keyArr[i]}' ${valueExpression}"
+ } finally {
+ if (valuesFromFile){
+ sh "rm ${tmpFile}"
+ }
+ }
}
}
}