6

Until now, I used the Artifactory REST API to determine the last version (last snapshot) of a maven artifact with groupId and artifactIid:

/api/search/latestVersion?g={groupid}&a={artifactid}

This gives me exactly a string with the highest/last available (snapshot) version of this artifact.

However, this is sometimes really slow and one recommendation was to use the Artifactory Query Language (AQL).

Unfortunately I have not yet been able to find out how to map this functionality in AQL.

Could someone give me a clue as to what a corresponding query in AQL could look like?

Thanks in advance!

Javier C.
  • 7,859
  • 5
  • 41
  • 53
Matthias Lohr
  • 1,696
  • 2
  • 20
  • 32

1 Answers1

12

You can use AQL's SORT and LIMIT to retrieve your latest artifact, for example:

items.find(
{
            "repo":"my-repo"
    }
).sort({"$desc" : ["created"]}).limit(1)

You can find more examples here.

I would also recommend trying out the Jfrog CLI, which also supports Sorting, and might be easier to use.

Ortsigat
  • 1,259
  • 7
  • 8
  • 1
    But what is with the limitation to groupid/artifactid? How to translate that into the fields provided by AQL? – Matthias Lohr Dec 12 '17 at 08:41
  • you can use the "name" field with "$match" and incorparate wildcards in your query, for example: items.find( { "name":{"$match":"*somename-1.1.1.*"} } ).sort({"$desc" : ["name"]}).limit(1) – Ortsigat Dec 17 '17 at 07:51
  • items.find( { "name":{"$match":"somename-1.1.1.*"} } ).sort({"$desc" : ["name"]}).limit(1) – Ortsigat Dec 17 '17 at 07:58