Add ability to check does image with tag exists in registry
Add ability to check does image with provided tag exists in
registry by provided path.
Change-Id: Ib8f10f248f340da7a6c338a352781daf2f40a3ef
Related-bug: PROD-24725
diff --git a/src/com/mirantis/mcp/MCPArtifactory.groovy b/src/com/mirantis/mcp/MCPArtifactory.groovy
index 0101eb8..de4f81f 100644
--- a/src/com/mirantis/mcp/MCPArtifactory.groovy
+++ b/src/com/mirantis/mcp/MCPArtifactory.groovy
@@ -125,6 +125,31 @@
}
/**
+ * Check if image with tag exist by provided path
+ * Returns true or false
+ *
+ * @param artifactoryURL String, an URL to Artifactory
+ * @param imageRepo String, path to image to check, includes repo path and image name
+ * @param tag String, tag to check
+ * @param artifactoryCreds String, artifactory creds to use. Optional, default is 'artifactory'
+ */
+def imageExists(String artifactoryURL, String imageRepo, String tag, String artifactoryCreds = 'artifactory') {
+ def url = artifactoryURL + '/v2/' + imageRepo + '/manifest/' + tag
+ def result
+ withCredentials([
+ [$class : 'UsernamePasswordMultiBinding',
+ credentialsId : artifactoryCreds,
+ passwordVariable: 'ARTIFACTORY_PASSWORD',
+ usernameVariable: 'ARTIFACTORY_LOGIN']
+ ]) {
+ result = sh(script: "bash -c \"curl -X GET -u ${ARTIFACTORY_LOGIN}:${ARTIFACTORY_PASSWORD} \'${url}\'\"",
+ returnStdout: true).trim()
+ }
+ def properties = new groovy.json.JsonSlurperClassic().parseText(result)
+ return properties.get("errors") ? false : true
+}
+
+/**
* Find docker images by tag
* Returns Array of image' hashes with names as full path in @repo
*