From cb768d554a4dacb53277dd9989646c8317ccc457 Mon Sep 17 00:00:00 2001 From: swatkiev <51817503+swatkiev@users.noreply.github.com> Date: Tue, 22 Feb 2022 12:32:00 +0200 Subject: [PATCH] Update Artifactory-Cleanup.sh I have changed this script for only two commands: 1) RESULTS=`curl -u $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD "http://127.0.0.1:8081/artifactory/api/search/creation?from=$START_TIME&to=$END_TIME&repos=$REPO" | grep uri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//' | sed -r 's|/api/storage||'` 2) curl -X DELETE -u $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD $RESULTS It works well, for this you have to change all $ENV_VAR for your values, domain http://127.0.0.1:8081/ is only example, you can change it for your domain name, also $START_TIME and $END_TIME must be in millisec: https://currentmillis.com/ --- Artifactory-Cleanup.sh | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Artifactory-Cleanup.sh b/Artifactory-Cleanup.sh index fc9df21..9fc12ff 100644 --- a/Artifactory-Cleanup.sh +++ b/Artifactory-Cleanup.sh @@ -1,20 +1,10 @@ #!/bin/bash -#replace with your artifactory username -#replace with your artifactory password -#replace with your artifactory domain name -# pass to the script the $START_TIME for minimum creation time in milliseconds of artifacts (example 1325376000000 for January 1st 2012) -# pass to the script the $END_TIME for maximum creation time in milliseconds of artifacts (example 1388534400000 for January 1st 2014) +#replace $ARTIFACTORY_USER with your artifactory username +#replace $ARTIFACTORY_PASSWORD with your artifactory password +#replace http://127.0.0.1:8081/ with your artifactory domain name +# pass to the script the $START_TIME for minimum creation time in milliseconds of artifacts https://currentmillis.com/ (example 1325376000000 for January 1st 2012) +# pass to the script the $END_TIME for maximum creation time in milliseconds of artifacts https://currentmillis.com/ (example 1388534400000 for January 1st 2014) # pass to the script the $REPO for the repository where artifacts are located (example: releases) -# find all artifacts created in 2013, time are expressed in milliseconds -# grep look for uri attribute in JSON results returned then awk take the corresponding value of the uri attribute. The first 2 sed commands remove the last character and the last sed command remove the first character, ie stripping off the comma and double quotes from the URL in awk -RESULTS=`curl -s -X GET -u : "https://.artifactoryonline.com//api/search/creation?from=$START_TIME&to=$END_TIME&repos=$REPO" | grep uri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//'` -for RESULT in $RESULTS ; do - echo "fetching path from $RESULT" - # from the URL we fetch the download uri to remove - # grep look for downloadUri attribute in JSON results returned then awk take the corresponding value of the downloadUri attribute. The first 2 sed commands remove the last character and the last sed command remove the first character, ie stripping off the comma and double quotes from the URL in awk - PATH_TO_FILE=`curl -s -X GET -u : $RESULT | grep downloadUri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//'` - echo "deleting path $PATH_TO_FILE" - # deleting the corresponding artifact at last - curl -X DELETE -u : $PATH_TO_FILE -done +RESULTS=`curl -u $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD "http://127.0.0.1:8081/artifactory/api/search/creation?from=$START_TIME&to=$END_TIME&repos=$REPO" | grep uri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//' | sed -r 's|/api/storage||'` +curl -X DELETE -u $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD $RESULTS