0

I have set of files uploaded to the global repository. I need to download the latest uploaded file.. How can I do it by using jFrog? Which Curl command should I use?

Currently I am using curl -O https://***/artifactory/snapshots/***/***/***/***-SNAPSHOT/test.xml which downloads the file on the server, but this is useful when there is a specific name, but, I want to download the latest one.

thisisdude
  • 543
  • 1
  • 7
  • 31

1 Answers1

1

You can use Artifactory's AQL to apply your search/delete filters.

specifically, in your example you can use SORT and LIMIT to retrieve your latest artifact

items.find ({
        "repo":"my-global-repo"
}).sort({"$desc" : ["created"]}).limit(1)

AQL can be use in REST as well as with JFrog's CLI. You can find more AQL examples here.

I would also recommend trying out the Jfrog CLI, which also supports Sorting and Limiting without the need to use AQL, and might be easier to use. You can find CLI examples here

Ortsigat
  • 1,259
  • 7
  • 8
  • Thanks for the reply. Ihave gone through the jFrog CLI and it shows me JSON. Which URI to hit while executing that JSON? I'm not sure whether this is appropriate question or not, but I am too new in this jFrog. – thisisdude Jun 28 '18 at 05:24
  • with the CLI you don't really "hit a URI". You can use the CLI 'config' command to define the server connection detail or use the --url option to set the Artifactory URI. – Ortsigat Jun 28 '18 at 06:00
  • It'd be great if you can give me a sample example link. – thisisdude Jun 28 '18 at 06:07
  • with the CLI you don't really "hit a URI". You can use the CLI 'config' command to define the server connection detail or use the --url option to set the Artifactory URL. I would start here - https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory if you are more comfortable using curl, you can POST to http://MyServer:MyPort/artifactory/api/search/aql with the POST body being the json in my original response. This will retrieve the Latest Uploaded Artifact in your repo, which you can then delete by name as you originally did – Ortsigat Jun 28 '18 at 06:12
  • Thanks this helps. I'd use curl rather. – thisisdude Jun 28 '18 at 06:14
  • I tried this _curl -X POST https://***.***/artifactory/api/search/aql -d 'items.sort({"$desc" : ["created"]}).limit(1)'_ and it gave me error Unsupported media type.. Am I missing something here? – thisisdude Jun 28 '18 at 06:54
  • Did you try -H 'Content-Type: text/plain'? – Ortsigat Jun 28 '18 at 08:31