user6136315
user6136315

Reputation: 705

list all artifacts in a repository on JFrog Artifactory

I'm new to the Artifactory. Currently I'm working on a project to list all the artifacts in a repository.

Artifactory version:4.1.3 Pro (turned off the cert verification)

curl -u uname:password -X POST -k https://artifactory.xxxx.com/artifactory/api/search/aql -d "items.find({"repo":"war"}).include("name","repo","path","size").sort({"$desc":["size"]}).limit(10)"


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /artifactory/api/search/aql was not found on this server.</p>
<hr>
<address>Apache/2.2.31 (Amazon) Server at artifactory.xxxx.com Port 443</address>
</body></html>

It's throwing an error(Bad request). Try to list out the artifacts in the following repos war,war-dev,war-release,webapp,webapp-dev(get the list of repos from Artifactory database and http request).

Tried to list out the artifacts using REST calls anonymously,But there are no logs in $ARTIFACTORY_HOME/logs/request_trace.log $ARTIFACTORY_HOME/logs/request.log

Get the list of repos from artdb(Artifactory database) and artifactory url. listed repos are different from one to other. Which one is correct?

Listed so many repos

mysql> select distinct(repo) from nodes;
| war                               |
| war-dev                           |
| war-release                       |

https://artifactory.xxxx.com/artifactory/repo/
webapp/                                                       
webapp-dev/                                                    

Can someone help to find out the list of artifacts in repo Please. Thank you!

Upvotes: 14

Views: 46316

Answers (3)

Rudolf Starosta - Rudi
Rudolf Starosta - Rudi

Reputation: 305

For me it worked when I used Content-Type text/plain instead of application/json, i.e.

curl -u uname -X POST http://host:8081/artifactory/api/search/aql -H "content-type: text/plain" -d @filename.aql

Upvotes: 5

user6136315
user6136315

Reputation: 705

This is also working for me. Either you can write the command as specified by @JBaruch or you can run the JSON AQL file.

curl -u uname -X POST http://host:8081/artifactory/api/search/aql -H "content-type: application/json" -d @filename.aql

Upvotes: 3

JBaruch
JBaruch

Reputation: 22893

AQL is the way to go. And your query is almost good (you forgot the $match for all the repos starting with war or web. The problem is curl. If you want to write the query string in the command line you need to escape all the inner " and $. Here's the working query:

curl -u uname:password -X POST -k https://artifactory.xxxx.com/artifactory/api/search/aql -d "items.find({\"type\" : \"file\",\"\$or\":[{\"repo\" : {\"\$match\" : \"war*\"}, \"repo\" : {\"\$match\" : \"web*\"} }]}).include(\"name\",\"repo\",\"path\",\"size\").sort({\"\$desc\": [\"size\"]}).limit(10)"

Now, this is hell. Instead, consider writing the query in a text file and passing it with -d @filename.aql. In this case you don't need all the escaping and the query will look like:

items.find({
  "type" : "file",
  "$or":[{
    "repo" : {"$match" : "war*"}, 
    "repo" : {"$match" : "web*"} }]})
  .include("name","repo","path","size")
  .sort({"$desc": ["size"]})
  .limit(10)

Upvotes: 21

Related Questions