Artifactory AQL download artifact

江枫思渺然 提交于 2019-12-21 23:19:13

问题


Is there a way to download an artifact using AQL?

I have a query sent with:

curl -u user:pass \
-X POST https://artifactoryURL/artifactory/api/search/aql \
-H 'content-type: text/plain' \
-T query.aql

And my query.aql:

items.find(
    {
        "repo":{"$eq":"repo"},
        "$and": [
          {
            "path": { "$match": "path/*"},
            "name": { "$match": "*.rpm"}
          }
        ]
    }
)
.sort({ "$desc": ["modified"] })
.limit(1)

Now that I know it returns what I want, Is there a way to change the request from api/search/aql to something like api/download/aql and get those items?

EDIT:

I had also tried doing this with the jfrog cli but they don't fully support AQL there (sort and limit didn't work).

This is the command I tried:

jfrog rt s --spec=query-aql.json

And the spec that failed to sort and limit results:

{
  "files": [
    {
      "aql": {
        "items.find": {
          "repo": "repo",
          "$and": [
            {
              "path": { "$match": "path/*"},
              "name": { "$match": "*.rpm"}
            }
          ]
        }
      },
      "sort": {
        "$asc": ["modified"]
      },
      "limit": 1
    }
  ]
}

EDIT 2:

Added a jfrog-cli-go issue: https://github.com/JFrogDev/jfrog-cli-go/issues/56


回答1:


An easy way to use your aql script to download files from artifactory is to use the JFrog cli as mention here : https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-Download,CopyandMoveCommandsSpecSchema

The cli can be downloaded as an executable for linux, mac or windows and should fit your needs

With the curl command the only thing you can do is then to parse the result from your aql query and perform download request for each file.




回答2:


I was just looking for a very similar thing -- use a download spec file to download the latest artifact from a given repo and path. I don't care if I use AQL or not, I just want it in the download-spec.json file. If you go to the link above look at Example 5.

Modified for your example:

{
  "files": [
  {
    "pattern": "path/*.rpm",
    "target": "my/download/path/",
    "sortBy": "created",
    "sortOrder": "desc",
    "limit": 1,
  }
  ]
}



回答3:


jfrog cli supports --limit, --sort-order, and --sort-by arguments.

The following works for me:

jfrog rt search --spec=/tmp/jfrogfilespec.json --sort-by created --sort-order=desc --limit 1 

The contents of the json spec file are:

{ "files": [ { "aql": { "items.find": { "repo":{"$eq":"my-release-repo"}, "name":{"$match":"my-artifact-prefix*"} } } } ] }

This generates the following query (according to debug mode):

items.find( { "repo":{"$eq":"my-release-repo"}, "name":{"$match":"my-artifact-prefix*"} } ).include("name","repo","path","actual_md5","actual_sha1","size","type","created").sort({"$desc":["created"]}).limit(1)

What is frustrating is that I cannot seem to find a way to use "jfrog rt search" with a filespec that allows me to influence the "include" modifier portion of the search.



来源:https://stackoverflow.com/questions/44077569/artifactory-aql-download-artifact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!