I couldn't get that to work right but got a little but further using the JsonSlurper (as opposed to JsonSlurperClassic)
Assuming my data structure is represented in json like:
{
"name": "templates",
"tags": [
"qa_tmpl-92",
"qa_tmpl-93",
"qa_tmpl-94"
]
}
I was trying something like this:
import groovy.json.JsonSlurper
try {
List<String> artifacts = new ArrayList<String>()
def artifactsUrl = "
http://localhost:5000/v2/templates/tags/list"
def artifactsObjectRaw = ["curl", "-s", "-H", "accept: application/json", "-k", "--url", "${artifactsUrl}"].execute().tags
def jsonSlurper = new JsonSlurper()
def artifactsJsonObject = jsonSlurper.parseText(artifactsObjectRaw)
def dataArray = artifactsJsonObject.data
for(item in dataArray){
if (item.isMetadata== false)
artifacts.add(item.tags)
}
return artifacts
} catch (Exception e) {
print "There was a problem fetching the artifacts"
}
Running in groovysh, it didn't show me an error, but I ended up in the catch, so I think the way I am trying to do curl, this bit in particular (${artifactsUrl}"].execute().tags) is wrong.
There was a problem fetching the artifacts ===> null
Can anyone point me in the right direction here?