0
votes

I need to write a shell script, that can get outdated artifacts from JFROG by using REST API and delete them.

I get a list of artifacts by command

curl -u user:password "http://artifactory:8081/artifactory/api/search/dates?dateFields=created&from=1467052559000&to=1497588559000&repos=current-repo"

and get an output like

"results" : [ {
    "uri" : "http://artifactory:8081/artifactory/api/storage/current-repo/first artifact/artfoulder folder/file.tzs",
    "created" : "2017-04-10T11:33:50.190+03:00"
  }, {
    "uri" : "http://artifactory:8081/artifactory/api/storage/current-repo/second artifact/artfoulder folder/file2.tzs",
    "created" : "2017-04-10T11:33:50.140+03:00"
  } ]

and other artifacts

After I successfully got the list of these artifacts, I need to delete them.

My questions:

  1. Is there a simple way to do it? Or I need to parse output strings with shell, put links in array and delete by REST API command one by one?
  2. It there a way to get only first-level artifact folders, that are outdated and delete them (first artifact and second artifact in my case)

Thanks a lot in advance!

1

1 Answers

2
votes

Why not using a script is already ready specifically for that: https://github.com/JFrogDev/artifactory-scripts/blob/master/cleanup/aqlCleanup.groovy

All you will need to do is change the AQL query to search artifacts on specific date range and that is it. This will automatically clean up.