Pre-create dir path with dummy file if required
Example:
Key: first:second:third:fourth
* dirdepth = 0
Nothing will be be done.
* dirdepth = 1
first dir will be created with second.yml file.
* dirdepth = 2
first/second dir will be created with third.yml file.
* dirdepth = 3
first/second/third dir will be created with fourth.yml file.
* dirdepth = 4
first/second/third/fourth dir will be created.
Change-Id: I6f70bf4107795e5776a23062500f90fbd06c69af
Related-PROD: https://mirantis.jira.com/browse/PROD-33875
diff --git a/src/com/mirantis/mk/ReleaseWorkflow.groovy b/src/com/mirantis/mk/ReleaseWorkflow.groovy
index 51f6218..d2d0e7d 100644
--- a/src/com/mirantis/mk/ReleaseWorkflow.groovy
+++ b/src/com/mirantis/mk/ReleaseWorkflow.groovy
@@ -82,9 +82,10 @@
* - crTopic
* - crAuthorName
* - crAuthorEmail
+ * @param dirdepth level of creation dirs from key param
*/
-def updateReleaseMetadata(String key, String value, Map params) {
+def updateReleaseMetadata(String key, String value, Map params, Integer dirdepth = 0) {
String gitCredentialsId = params.get('metadataCredentialsId', 'mcp-ci-gerrit')
String metadataRepoUrl = params.get('metadataGitRepoUrl', "ssh://${gitCredentialsId}@gerrit.mcp.mirantis.net:29418/mcp/artifact-metadata")
String metadataGerritBranch = params.get('metadataGitRepoBranch', 'master')
@@ -136,6 +137,23 @@
ChangeId = ''
git.createGitBranch(repoDir, crTopic)
}
+
+ def keySize = key.split(':').size() - 1
+ if (dirdepth > 0 && dirdepth - 1 <= keySize) {
+ def dirPath = metadataDir + key.split(':')[0..dirdepth - 1].join('/')
+ if (!new File(dirPath).exists()) {
+ File newDirs = new File(dirPath)
+ newDirs.mkdirs()
+ }
+ if (dirdepth - 1 != keySize) {
+ def pathToDummyFile = dirPath + '/' + key.split(':')[dirdepth] + '.yml'
+ if (!new File(pathToDummyFile).exists()) {
+ File dummyFile = new File(pathToDummyFile)
+ dummyFile.write ''
+ }
+ }
+ }
+
cmdText = "python '${repoDir}/utils/app.py' --path '${metadataDir}' update --key '${key}' --value '${value}'"
python.runVirtualenvCommand(venvDir, cmdText)
commitMessage =