I'm trying to get a Set of installed Jenkins plugins through the API using curl
and jq
but can't seem to flatten nested arrays correctly. An example of the output JSON I'm fetching:
{
"plugins": [
{
"shortName": "foo",
"version": "6.9",
"dependencies": [
{
"shortName": "bar",
"version": "4.2.0"
},
{
"shortName": "baz",
"version": "6.6.6"
}
]
},
{
"shortName": "fah",
"version": "4.2",
"dependencies": [
{
"shortName": "bah",
"version": "1.3"
},
{
"shortName": "bar",
"version": "2.1.0"
},
{
"shortName": "baz",
"version": "6.6.6"
]
}
]
}
And here's the result that I'd like to get:
[
{
"shortName": "bah",
"version": "1.3"
},
{
"shortName": "bar",
"version": "2.1.0"
},
{
"shortName": "bar",
"version": "4.2.0"
},
{
"shortName": "baz",
"version": "6.6.6"
},
{
"shortName": "fah",
"version": "4.2"
},
{
"shortName": "foo",
"version": "6.9"
},
]
I've made various attempts at using map
and flatten
but can't seem to preserve the parent's keys, let alone getting a comprehensive array of each plugin and its version. The payload is easy enough to get with curl
:
curl -u username:token --globoff -H "${JENKINS_CRUMB}" "${JENKINS_URL}/pluginManager/api/json?tree=plugins[shortName,version,dependencies[shortName,version]]"
I'd like to just pipe that output straight into jq
to transform it into the desired results. Am I able to do this within jq
or would I need to have some sort of wrapper for these transformations like Python?