aat -> release I want to g..." /> aat -> release I want to g..." /> aat -> release I want to g..."/>

Artifactory AQL search for builds on promotion.status

863 views Asked by At

I'm trying to use AQL to get a list of all build not promoted to "release".

Our binaries pass through status integration-> aat -> release I want to get a list of those with promotion status integration and aat but not release.

One example of a build has statuses:

"statuses" : [ {
  "status" : "integration",
  "timestamp" : "2016-04-20T08:36:42.009+0000",
  "user" : "user",
  "ciUser" : "changes",
  "timestampDate" : 1461141402009
}, {
  "status" : "aat",
  "repository" : "repo-aat",
  "timestamp" : "2016-04-20T08:56:11.843+0000",
  "user" : "user",
  "ciUser" : "changes",
  "timestampDate" : 1461142571843
}, {
  "status" : "aat",
  "repository" : "repo-aat",
  "timestamp" : "2016-04-20T08:58:55.417+0000",
  "user" : "user",
  "ciUser" : "changes",
  "timestampDate" : 1461142735417
}, {
  "status" : "aat",
  "repository" : "repo-aat",
  "timestamp" : "2016-04-20T09:20:32.619+0000",
  "user" : "user",
  "ciUser" : "changes",
  "timestampDate" : 1461144032619
}, {
  "status" : "release",
  "repository" : "repo-release",
  "timestamp" : "2016-04-20T09:30:12.143+0000",
  "user" : "user",
  "ciUser" : "changes",
  "timestampDate" : 1461144612143
}, {
  "status" : "release",
  "repository" : "repo-release",
  "timestamp" : "2016-04-20T09:40:50.595+0000",
  "user" : "admin",
  "ciUser" : "changes",
  "timestampDate" : 1461145250595
} ],

This build is matched regardless if we set:

{"promotion.status": {"$nmatch":"aat"}}

to

{"promotion.status": {"$nmatch":"release"}}
{"promotion.status": {"$nmatch":"integration"}}

with the request:

builds.find({
  "$and" : [
  {"name": {"$match": "test"}},
  {"created": {"$lt": "2016-12-01"}},
  {"promotion.status": {"$nmatch":"release"}}
  ]
}).include("promotion.status").limit(10)

we get this response:

{
"results" : [ {
  "build.created" : "2016-04-20T10:12:46.905Z",
  "build.created_by" : "test",
  "build.modified" : "2016-04-20T11:45:12.309Z",
  "build.modified_by" : "admin",
  "build.name" : "user",
  "build.number" : "2551",
  "build.promotions" : [ {
    "build.promotion.status" : "aat"
  }, {
    "build.promotion.status" : "integration"
  } ],
  "build.url" : "URL"
} ],
"range" : {
  "start_pos" : 0,
  "end_pos" : 1,
  "total" : 1,
  "limit" : 10
}
2

There are 2 answers

1
Dror Bereznitsky On

If you do not need to use wildcards with $nmatch, you can use $ne instead, for example:

builds.find({
  "$and" : [
  {"name": {"$match": "test"}},
  {"created": {"$lt": "2016-12-01"}},
  {"promotion.status": {"$ne":"release"}}
  ]
}).include("promotion.status").limit(10)

With $nmatch, the following will also work:

builds.find({
  "$and" : [
  {"name": {"$match": "test"}},
  {"created": {"$lt": "2016-12-01"}},
  {"promotion.status": {"$nmatch":"releas*"}}
  ]
}).include("promotion.status").limit(10)
0
Sander F On

What you are trying to do, is to ask Artifactory for the "most recent" status of a build, and filter based on that. However this is not how Artifactory treats your AQL query.

Please note that your build does not have a property "build.promotion.status". Instead, your build has a property of type array with the name "build.promotions". Within this array, any number of promotion history items may be set for your build, including the property "build.promotion.status".

Now suppose your AQL query is going to select builds that have "build.promotion.status" : "aat", what you are really asking Artifactory is this: please return any build for which any of the elements of the build.promotions array has a matching property "build.promotion.status" : "aat".

So eventhough the build #2551 in your example has been promoted from "aat" to "released", you are asking AQL if it did - at any point in time - have promotion status "aat", which it did.

To add to the confusion, when you include("promotion.status"), you are going to see a filtered subset of the promotion history items.

If you are trying to work around this by asking for the reverse question: which builds do not have any build status history item with "build.promotion.status" = "released", even if that would be possible with AQL, it would not tell you what the current status is. Nor would it work correctly if you build is ever "Rolled-back".

I think JFROG should actually introduce a "build.promotion.status" field, which does what people reasonably expect: to give you the current status to display and to query on. Until that time, the only solution I can think of is to fetch all the build promotion items and then do the magic in a higher order language.