#!/bin/bash
#Year to delete
year=2015
echo "Cleanup Artifactory from $year year artifacts"
for artifactId in `curl -u user:password  http://artifactory.example.com:8081/artifactory/libs-release-local/com/example/product/ 2>/dev/null |grep "href"|grep -v '\.\.'| cut -d\> -f2|cut -d\< -f1 |cut -d/ -f1`;
 do
  echo "Removing old $artifactId"
  for item in `curl -u user:password  http://artifactory.example.com:8081/artifactory/libs-release-local/com/example/product/$artifactId/ 2>/dev/null |grep $year| grep "href"|grep -v '\.\.' |grep -v maven-metadata.xml|cut -d\> -f2|cut -d\< -f1`
   do
    echo removing $artifactId version $item
    curl -u user:password  http://artifactory.example.com:8081/artifactory/libs-release-local/com/example/product/$artifactId/$item;
   done
done

Clean Trash Can and Execute Garbage Collection on Artifactory web interface after the script to speed up free space.

 

 

  • No labels