4

I am trying to query which build number(s) produced artifacts from build foo with artifact property vcs.Revision=aabbccddee123456.

In Artifactory 5.1.3.

I was trying like this so far:

curl -u user:apikey -i -X POST https://artifactory.foobar.com/artifactory/api/search/aql -H "content-type:text/plain" -T query.json

query.json:

builds.find(
{
  "module.artifact.item.repo":"snapshot-local",
  "name":"foo",
  "module.artifact.item.@vcs.Revision":"aabbccddee123456"
}
)

However, none of these 3 lines seem individually correct:

  • builds.find({"module.artifact.item.repo":"snapshot-local"}) returns nothing,

  • builds.find({"name":"foo"}) returns the same empty response,

  • builds.find({"module.artifact.item.@vcs.Revision":"aabbccddee123456"}) also returns this:

{ "results" : [ ], "range" : { "start_pos" : 0, "end_pos" : 0, "total" : 0 } }

What am I doing wrong here? I do see in the webapp the builds I published with this name, and with the correct artifact properties.

Florian Castellane
  • 1,197
  • 2
  • 14
  • 38
  • Are you using the Artifactory CI integration to deploy build to Artifactory (build info)? – Dror Bereznitsky Jul 05 '18 at 10:38
  • yes, I do use `build-publish` in CLI and publish build info in Jenkins. I also can see the build information in the browser, as well as the published artifacts and their properties, used dependencies, etc. – Florian Castellane Jul 05 '18 at 11:11
  • Is it possible that you are running the query with a user that does not have privileges to get this data? see https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language#ArtifactoryQueryLanguage-UsersWithoutAdminPrivileges – Dror Bereznitsky Jul 05 '18 at 11:59
  • shouldn't I get an http 401 error then, instead of the request going through? – Florian Castellane Jul 05 '18 at 12:52
  • its a bit tricky, you are allowed to run AQL queries in general but don't have permissions for some of the entities. The logic behind this type of response is returning only the results you have permissions to view – Dror Bereznitsky Jul 05 '18 at 13:08
  • 1
    then it is not possible to do this from builds.find. I will try using items instead. – Florian Castellane Jul 05 '18 at 13:37
  • Possible duplicate of https://stackoverflow.com/questions/42262029/aql-build-domain-object-does-not-return-results – Ed Randall Mar 30 '19 at 17:42

2 Answers2

5

Here's a working solution that will give build numbers (since giving admin rights to query builds is not a solution for us):

query.json:

items.find(
{
  "repo":"snapshot-local",
  "artifact.module.build.name":"foo",
  "artifact.item.@vcs.Revision":"aabbccddee123456"
}
).include("artifact.module.build.number")

This returns a list of all the artifacts that were built with the relevant properties, with the build number attached, e.g:

{
"results" : [ {
  "repo" : "snapshot-local",
  "path" : "foo/42",
  "name" : "a.out",
  "type" : "file",
  "size" : 123456789,
  "created" : "2018-07-05T12:34:56.789+09:00",
  "created_by" : "jenkins",
  "modified" : "2018-07-05T12:34:56.789+09:00",
  "modified_by" : "jenkins",
  "updated" : "2018-07-05T12:34:56.789+09:00",
  "artifacts" : [ {
    "modules" : [ {
      "builds" : [ {
        "build.number" : "42"
      } ]
    } ]
  } ]
},
[SNIP]
}
 ],
"range" : {
  "start_pos" : 0,
  "end_pos" : 30,
  "total" : 30
}
}

I can then parse this to extract build.number.

Florian Castellane
  • 1,197
  • 2
  • 14
  • 38
  • 1
    Nice lateral-thinking solution, thanks. I shortened to `.include("artifact.module.build")` to get the build name, url, date along with the number also. – Ed Randall Mar 30 '19 at 17:43
  • Apologize for reopening the old post. I recently started working on artifactory. When I run the curl command to query artifactory from Jenkins Shell, I am not able to set Content-Type as application\json. It only takes plaintext. But I would like to get response as Json. How do I do that? Appreciate any help. – Swetha Reddy Jan 08 '21 at 18:34
1

Certain AQL queries requires a user with admin permissions. To ensure that non-privileged users do not gain access to information without the right permissions, users without admin privileges have the following restrictions:

  1. The primary domain in the query may only be item.
  2. The following three fields must be included in the include directive: name, repo, and path.

In your case, you are using the build domain in the query which requires admin permissions

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57