Using a REST API call to retrieve the latest artifact based on layout.
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.
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:
Then, we deployed an RPM package to Artifactory (to the repository ‘rpm-local’) with the following path:
As can be seen below, Artifactory identifies the version of the package according to the BaseRev we deployed:
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
The latest artifact version based on layout in repository ‘rpm-local’, is 99 (as can be seen in the screenshot below).
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.