[artifactory] Fix race condition state
Avoid race condition state in promoteDockerArtifact method
Change-Id: I4eaf72e3e7c8a3a87e75c19eb283bb6b3131cfff
diff --git a/src/com/mirantis/mcp/MCPArtifactory.groovy b/src/com/mirantis/mcp/MCPArtifactory.groovy
index 1f20325..ffce300 100644
--- a/src/com/mirantis/mcp/MCPArtifactory.groovy
+++ b/src/com/mirantis/mcp/MCPArtifactory.groovy
@@ -257,7 +257,8 @@
String artifactoryProdRepo, String dockerRepo,
String artifactTag, String targetTag, Boolean copy = false) {
def url = "${artifactoryURL}/api/docker/${artifactoryDevRepo}/v2/promote"
- writeFile file: "query.json",
+ String queryFile = UUID.randomUUID()
+ writeFile file: queryFile,
text: """{
\"targetRepo\": \"${artifactoryProdRepo}\",
\"dockerRepository\": \"${dockerRepo}\",
@@ -265,13 +266,14 @@
\"targetTag\" : \"${targetTag}\",
\"copy\": \"${copy}\"
}""".stripIndent()
- sh "cat query.json"
+ sh "cat ${queryFile}"
withCredentials([
[$class : 'UsernamePasswordMultiBinding',
credentialsId : 'artifactory',
passwordVariable: 'ARTIFACTORY_PASSWORD',
usernameVariable: 'ARTIFACTORY_LOGIN']
]) {
- sh "bash -c \"curl -u ${ARTIFACTORY_LOGIN}:${ARTIFACTORY_PASSWORD} -H \"Content-Type:application/json\" -X POST -d @query.json ${url}\""
+ sh "bash -c \"curl -u ${ARTIFACTORY_LOGIN}:${ARTIFACTORY_PASSWORD} -H \"Content-Type:application/json\" -X POST -d @${queryFile} ${url}\""
}
+ sh "rm -v ${queryFile}"
}