Home > Mobile >  How to search in Artifactory Repo sub folder only using curl
How to search in Artifactory Repo sub folder only using curl

Time:04-27

So I previously had a script to search for folders in my Artifactory repositories for a certain property.

curl -i -X GET "${ARTIFACTORY_URI}/api/search/prop?my-prop=aaa&repos=my-repo

So far so good. The way I deployed my artifacts was that I placed them in sub folders and each of the sub folders got assigned the property my-prop. Then when I ran this command, I got back a list of the sub folders that satisfied my search criteria. This worked because the sub folders where all directly inside the repo my-repo.

However now we have had to do some restructuring of the Artifactory. Now the sub folders that I'm trying to list are located in a sub folder inside a sub folder inside the repo. My command still works, but it returns all the sub folders.

For example consider this:

my-repo:
   * folder1
        folder1-1
         - folder1-1-1 (my-prop=aaa)
         - folder1-1-2 (my-prop=bbb)
        folder1-2
         - folder1-2-1 (my-prop=aaa)
   * folder2
        folder2-1
         - folder2-1-1 (my-prop=aaa)

So what I get now when searching for my-prop=aaa using the same command is folder1-1-1, folder1-2-1 and folder2-1-1. But what I want to do is limit the search to the sub-sub-folder folder1-1. I tried to simply add the path to the repos parameter but it doesn't work.

curl -i -X GET "${ARTIFACTORY_URI}/api/search/prop?my-prop=aaa&repos=my-repo/folder1/folder1-1

So my question is how would one do that? The Artifactory website being the train wreck that it is, is of course not very helpful. Is there an additional folder/path parameter that I can use? I want to note, that I am working on an incredibly restrictive customer system and do not have access to the JFrog CLI tool, so I've got to do everything using curl and wget.

Any help greatly appreciated!!!

CodePudding user response:

You should be able to use AQL (Artifactory Query Language) for that.

For your example, use something like:

curl -X POST "${ARTIFACTORY_URI}/api/search/aql" \
     -H 'Content-Type: text/plain' \
     --data 'items.find({"repo":"my-repo","@my-prop":"aaa","path":"folder1","type":"folder"})'

This will do a search in my-repo for folders with the given property and under the exact path folder1. You can use other operators, like $match, if the path should be a pattern instead of an exact match.

For the full AQL syntax and guidelines, see: Artifactory Query Language

  • Related