Listing docker image in reverse chronological order using Artifactory API

Viewed 354

I am trying to use the below API to get the list of docker images so that I could populate the dropdown on Jenkins build. Is there a way that this could be listed in a reverse chronological order rather than alphanumerical so that the newest image is at the top ? Thanks.

/artifactory/api/docker/repo/v2/image/tags/list

1 Answers

You will have to take help of Artifactory AQL query language. An example AQL fragment is...

items.find({"repo":{"$eq":"<repositoryname>"}, "name":{"$eq" : "<artifactoryItemName>"}}) .sort({"$desc" : ["created"]})

The descending sort order is specified with $desc sort operator on the timestamp field created.

You can also limit the number of results returned by adding an extra limit to the above query...

items.find({"repo":{"$eq":"<repositoryname>"}, "name":{"$eq" : "<artifactoryItemName>"}}) .sort({"$desc" : ["created"]}).limit(10)

The AQL needs to be submitted at /artifactory/api/search/aql. The same can be done via REST API as well with a POST request. The content should be posted not as a JSON but directly in the way query is specified as-is as text. The header for content type is Content-Type:text/plain. You can use the Basic authentication or other supported authentication methods.

There are a ton of things you can do with AQL. The syntax can look a bit confusing to begin with.

Related