I'm trying to piece together a Release Gate / ServerGate build task calling a webservice, grabbing the Json and then deciding whether to proceed.
The Json returned by the service looks like this:
{
"publisher": {
"publisherId": "c68591c6-8fbd-413b-b7fb-b921737f4f9f",
"publisherName": "jessehouwing",
"displayName": "Jesse Houwing",
"flags": "verified"
},
"extensionId": "252ad2b4-a2c5-43fc-bba5-17e631896091",
"extensionName": "vsts-snyk",
"displayName": "Snyk Task",
"flags": "validated, public",
"lastUpdated": "2018-03-16T18:58:36.327Z",
"publishedDate": "2016-11-16T21:35:28.387Z",
"releaseDate": "2016-11-16T21:35:28.387Z",
"shortDescription": "Snyk continuously finds and fixes vulnerabilities in your dependencies.",
"versions": [
{
"version": "1.1.12",
"flags": "validated",
"lastUpdated": "2018-03-16T18:58:53.133Z"
},
{
"version": "1.1.11",
"flags": "validated",
"lastUpdated": "2018-02-18T13:53:47.83Z"
}
],
"deploymentType": 0
}
I'm calling the service based on the HttpHandler execution handler in the task.json:
"execution": {
"HttpRequest": {
"Execute": {
"EndpointId": "$(connectedServiceName)",
"EndpointUrl": "$(endpoint.url)_apis/gallery/publishers/$(publisherId)/extensions/$(extensionId)$(extensionTag)?flags=1",
"Method": "GET",
"Body": "",
"Headers": "{\"Content-Type\":\"application/json\"}",
"WaitForCompletion": "false",
"Expression": "eq(jsonpath('$.versions[?(@.version==$(extensionVersion))].flags'), 'validated')"
}
}
}
There is very little documentation on the Expression syntax and on the supported jsonpath syntax. I've stolen most of the examples from:
- https://github.com/Microsoft/vsts-tasks/blob/a58b615d3ca0e34ec9814463ab187fd8da10cc5f/Tasks/AzureMonitor/task.json#L106
- https://blogs.msdn.microsoft.com/sriramb/2016/09/15/service-endpoints-data-sources/
- https://github.com/Microsoft/vsts-tasks/blob/8027c121c20250d35bd16218dc930b16033fb54e/docs/authoring/servertaskauthoring.md
I tried a number of different Expressions, none of them have worked so far:
eq(jsonpath('$.versions[?(@.version==$(extensionVersion))].flags'), 'validated')
eq(count(jsonpath('$.versions[?(@.version==$(extensionVersion)), ?(@.flags==validated)]')), 1)
eq(count(jsonpath('$.versions[?(@.version==$(extensionVersion)) && ?(@.flags==validated)]')), 1)
I've tried a number of different things with double escaping '
or mixing "
and '
.
Unfortunately, the server isn't giving me a lot of information other than Expressions failed, thus rather useless.
The log of execution looks like:
2018-04-01T13:34:51.2938460Z GET https://marketplace.visualstudio.com/_apis/gallery/publishers/jessehouwing/extensions/vsts-snyk?flags=1
Response Code: OK
Response: {"publisher":{"publisherId":"c68591c6-8fbd-413b-b7fb-b921737f4f9f","publisherName":"jessehouwing","displayName":"Jesse Houwing","flags":"verified"},"extensionId":"252ad2b4-a2c5-43fc-bba5-17e631896091","extensionName":"vsts-snyk","displayName":"Snyk Task","flags":"validated, public","lastUpdated":"2018-03-16T18:58:36.327Z","publishedDate":"2016-11-16T21:35:28.387Z","releaseDate":"2016-11-16T21:35:28.387Z","shortDescription":"Snyk continuously finds and fixes vulnerabilities in your dependencies.","versions":[{"version":"1.1.12","flags":"validated","lastUpdated":"2018-03-16T18:58:53.133Z"},{"version":"1.1.11","flags":"validated","lastUpdated":"2018-02-18T13:53:47.83Z"},{"version":"1.1.9","flags":"validated","lastUpdated":"2017-03-14T09:40:40.75Z"},{"version":"1.1.8","flags":"validated","lastUpdated":"2017-03-13T19:50:57.603Z"},{"version":"1.1.7","flags":"validated","lastUpdated":"2017-03-13T19:45:29.647Z"},{"version":"1.1.6","flags":"validated","lastUpdated":"2017-02-21T10:58:40.617Z"},{"version":"1.1.3","flags":"validated","lastUpdated":"2017-02-21T10:46:02.86Z"},{"version":"1.1.2","flags":"validated","lastUpdated":"2017-02-21T10:42:05.503Z"},{"version":"1.0.21","flags":"validated","lastUpdated":"2017-01-12T20:54:40.587Z"},{"version":"1.0.20","flags":"validated","lastUpdated":"2017-01-12T20:19:58.767Z"},{"version":"1.0.19","flags":"validated","lastUpdated":"2017-01-12T20:14:43.677Z"},{"version":"1.0.17","flags":"validated","lastUpdated":"2017-01-04T18:49:51.233Z"},{"version":"1.0.16","flags":"validated","lastUpdated":"2017-01-04T10:27:29.48Z"},{"version":"1.0.5","flags":"validated","lastUpdated":"2016-12-15T12:00:16.027Z"},{"version":"1.0.4","flags":"validated","lastUpdated":"2016-12-02T20:03:02.753Z"},{"version":"1.0.3","flags":"validated","lastUpdated":"2016-12-01T18:56:42.703Z"},{"version":"1.0.1","flags":"validated","lastUpdated":"2016-11-29T20:25:24.887Z"},{"version":"0.9.17","flags":"validated","lastUpdated":"2016-11-29T18:41:15.72Z"},{"version":"0.9.16","flags":"validated","lastUpdated":"2016-11-29T16:07:54.787Z"},{"version":"0.9.13","flags":"validated","lastUpdated":"2016-11-29T15:22:14.327Z"},{"version":"0.9.12","flags":"validated","lastUpdated":"2016-11-26T13:38:01.453Z"},{"version":"0.9.9","flags":"validated","lastUpdated":"2016-11-21T23:03:30.797Z"},{"version":"0.9.7","flags":"validated","lastUpdated":"2016-11-20T13:20:51.503Z"},{"version":"0.9.3","flags":"validated","lastUpdated":"2016-11-19T13:38:40.32Z"},{"version":"0.9.2","flags":"validated","lastUpdated":"2016-11-16T21:35:36.59Z"}],"deploymentType":0}
Evaluation of expression 'eq(count(jsonpath('$.versions[?(@.version==''1.1.12''),?(@.flags==''validated'')]')), 1)' failed.
Explicitly causign errors in the expression gives me an error message, so the expression at least seems to parse just fine.
In order to test without having to first create a whole task, you can create an Invoke REST API Release Gate as follows:
And use the following Generic Endpoint:
- Url: https://marketplace.visualstudio.com/
- Password: PAT (All accounts)
{"Items":[{"name":"item1","price":100},{"name":"item2","price":40},{"name":"item3","price":70}]}
the express iseq(count(jsonpath('Items[?(@.price<50)]')), 1)