Steps:

ARTIFACTORY: How to retrieve all artifacts in a repo except the latest 2 versions

AuthorFullName__c
Sara Ngo
articleNumber
000005700
ft:sourceType
Salesforce
FirstPublishedDate
2023-04-30T11:53:26Z
lastModifiedDate
2023-04-30
VersionNumber
1
1. Create a File Spec and use AQL to specify the repo and path to the targeted artifacts. All artifacts under the listed repo/path will be sorted in descending order by their names, and the last 2 artifacts will be excluded. If one looks for all artifacts in multiple folders which share the same directory structure, one can include the depth in the AQL query.
Below is an example:
{
  "files": [
    {
      "aql": {
              "items.find": {
                      "repo": "$repoName",
                      "path": "path/to/artifacts",
                      "type": "folder"
                }
        },
    "sortBy": ["name"],
    "sortOrder": "desc",
    "offset": 2
    }
    ]
}

Please note that the offset value can be changed if you are looking to exclude more versions.

2. Run JFrog CLI and pass the File Spec that was created. It will return a list of targeted artifacts that met the requirements:
jf rt s --spec=fileSpec.json