How to find the latest artifact version (based on layout)?

Subject

Using a REST API call to retrieve the latest artifact based on layout.

Details

When trying to resolve the latest artifact version using the “Artifact Latest Version Search Based on Layout” REST API call, Artifactory will identify the version according to the configured layout of the repository. Thus, in case the latest desired artifact retrieved is not found, we should verify that the desired artifact follows the repository layout.

In some package types, such as RPM, the client does not enforce a specific layout (unlike the Maven client for example, which imposes the maven-layout).
Thus, there is a need to follow the repository layout when deploying an artifact and then, the REST API call would work as expected.

Resolution

We have created an example of a new layout, according to an RPM package, and changed the layout of the repository to the new one:

[orgPath]/[module]-[baseRev](-[fileItegRev])-[classifier].[ext]

Then, we deployed an RPM package to Artifactory (to the repository ‘rpm-local’) with the following path:

rpm-local/centos/7/x86_64/cloudmunch-def-plugin-87-1.x86_64.rpm

As can be seen below, Artifactory identifies the version of the package according to the BaseRev we deployed:

User-added image

Once the layout matches, you should be able to use the mentioned API to find the latest version. For example:

$ curl ARTIFACTORY_URL/api/search/latestVersion?g=centos.7&a=x86_64&repos=rpm-local

99

The latest artifact version based on layout in repository ‘rpm-local’, is 99 (as can be seen in the screenshot below).

User-added image

In addition, you may also use AQL to query Artifactory for almost anything you want.
AQL is a dedicated query language which can be used to retrieve essential outputs according to your requirements.