0

I'm really new to Apache Ant,ivy & artifactory. I just have a requirement which someone can help me figuring out how to proceed or the XML code if possible.

Suppose I have 3 artifacts present in artifactory.. Eg. Threshold is 3.. When I'm running the new build, my ant/ivy script should detect that there are 3 files already in artifactory, It should remove the oldest file and then upload the latest build package into artifactory.. This is avoid too many files in artifactory and clean it up easily. We need a standard code put into every Ant script so that the artifactory is clean..

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

1 Answers1

1

If you are referring to Snapshot artifacts than Artifactory has a built in mechanism for limiting the number of snapshots.
To specify the maximum number of snapshots that may be stored, in the Edit Repository dialog, select the Basic Settings tab.
You first need to check the Handle Snapshots checkbox which then enables you to set the Max Unique Snapshots field. This value is zero by default, which means that all snapshots are saved.

In addition you can cleanup artifacts by developing a custom user plugin or create an external script using the Artifactory REST API.
Artifactory supports cleanup by allowing you to write custom User Plugins which you can develop to meet your own specific cleanup requirements. There are a number of cleanup scripts on GitHub which you can use as provided or modify to suit your own needs. Please not that user plugins is a feature of the Artifactory pro version.
Using the Artifactory REST API, you may write scripts to implement virtually any custom cleanup logic. You can use the various search APIs for finding artifacts you want to delete and use the delete item API for deleting them.

For more information and examples you can take a look at Managing Disk Space Usage

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
  • Thanks for replying. Yes it is Snapshot aritifactory. But do you think we should edit the Ant script to delete the oldest file, or do you think this build in mechanism will delete the old file. – Shanu Azeez Jul 22 '14 at 15:55
  • Also can you tell me more about "external script using the Artifactory REST API." – Shanu Azeez Jul 22 '14 at 15:55
  • The build in mechanism will take care of deleting old snapshots. Notice that old snapshots will be deleted once newer ones are deployed. In addition, this is done in a background process that checks the value of Max Unique Snapshots and deletes the oldest snapshots beyond that number. – Dror Bereznitsky Jul 22 '14 at 15:58
  • ..thank u for quick reply... Im trying to figure out the code given for Rest API, which language can we use to implment this. can we use powershell or does Ant script has the ability to take this.... `GET /api/build { "uri": "http://localhost:8080/artifactory/api/build" "builds" : [ { "uri" : "/wicket", "lastStarted" : ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ) }, { "uri" : "/jackrabbit", "lastStarted" : ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ) } ] }` – Shanu Azeez Jul 23 '14 at 15:28
  • You can use whatever can send HTTP requests and parse the JSON response. Notice that the REST API documentation shows both the format of the request and the expected response (usually in JSON format). – Dror Bereznitsky Jul 23 '14 at 19:51
  • Take a look at this stackoverflow [question](http://stackoverflow.com/questions/4598120/how-can-i-use-powershell-to-access-a-restful-webservice) as an example of calling a restful service using powershell – Dror Bereznitsky Jul 24 '14 at 18:21
  • can u help.. Im trying to use ANT task where Im calling a jar APIDocumentation-1.0.7.jar.. In taskdef I have correct mentioned the locaion of Jar. But the error says.. "No public execute() in interface in net.sf.json.JSON" @drorb – Shanu Azeez Aug 08 '14 at 15:28
  • @ShanuAzeez Please create a new question about this and post the relevant code – Dror Bereznitsky Aug 08 '14 at 16:04