Cigizmoond Vyhuholev
Cigizmoond Vyhuholev

Reputation: 431

Artifactory cleanup script by count of versions

There is script that deletes artifact not downloaded in specified period. But I have common necessary to keep last 10 versions (by date) of artifact and delete other versions. How to solve that issue? I need concept or code example.

Upvotes: 2

Views: 501

Answers (1)

Cigizmoond Vyhuholev
Cigizmoond Vyhuholev

Reputation: 431

I have solved that issue for maven repos. It is enough for me.

  1. Get all maven-metadata.xml from repo. /api/search/artifact?name=maven-metadata.xml&repos=${repo} and get uri from that json (except SPNAPSHOT one, it will be cleaned by internal artifactory retention policy), then get another json by uri and use downloadUri for download maven-metadata.xml itself.
  2. Now we have groupId and artifactId and versions. Reverse list of version and use loop with index, all artifacts with index more than 10 will be deleted.

Upvotes: 2

Related Questions