Reputation: 479
I am working on Jfrog Artifactory - Groovy script to delete the complete folder with artifacts. I have a respository with folder 2015.08.18.1.SNAPSHOT and it has child items 2015.08.18.1.12345.pom, 2015.08.18.1.12345.war, matadata.xml. With the below script i am able to delete only the child items (2015.08.18.1.12345.pom, 2015.08.18.1.12345.war, matadata.xml) and not the folder(2015.08.18.1.SNAPSHOT) , my requirement is to delete folder also.
def delete(RESTClient restClient, List itemsToDelete, def dryRun) {
dryMessage = (dryRun) ? "*** This is a dry run ***" : "";
itemsToDelete.each {
println("Trying to delete artifact: '$it'. $dryMessage")
try {
if (!dryRun) {
restClient.delete(path: it)
}
println("Artifact '$it' has been successfully deleted. $dryMessage")
} catch (HttpResponseException e) {
println("Cannot delete artifact '$it': $e.message" + ", $e.statusCode")
} catch (HttpHostConnectException e) {
println("Cannot delete artifact '$it': $e.message")
}
}
}
Here, 'itemsToDelete' holds '2015.08.18.1.SNAPSHOT'
Upvotes: 0
Views: 1736
Reputation: 166
Jfrog provides java client for Artifacory which can be used in this case.
It already contains pre defined http client that configured to work with Artifactory.
The client and documentation can be found at: https://github.com/JFrogDev/artifactory-client-java
Example for deleting item from Artifactory using the client:
Artifactory artifactory = ArtifactoryClient.create("ArtifactoryUrl", username", password");
String result = artifactory.repository("RepoName").delete("path/to/item");
Note that item could be folder or file.
Upvotes: 2