dieses JSON von einem API-Aufruf via curl bauen Jenkins genommen MitVerwenden jq spezifische Schlüssel greifen: Wert-Paar von n-te Objekt in einem JSON-Array
{
"_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions" : [
{
"_class" : "hudson.model.CauseAction",
"causes" : [
{
"_class" : "jenkins.branch.BranchIndexingCause",
"shortDescription" : "Branch indexing"
}
]
},
{
"_class" : "hudson.model.ParametersAction",
"parameters" : [ "..." ]
},
{
"_class" : "hudson.tasks.junit.TestResultAction",
"failCount" : 1,
"skipCount" : 14,
"totalCount" : 222,
"urlName" : "testReport"
}
],
"artifacts" : [ "..." ],
"result" : "UNSTABLE",
"previousBuild" : {
"number" : 98,
"url" : "<some Url>"
}
}
Warum kann ich jq '{result}' <fileNameWithJSON>
tun und bekommen
{ "result" : "UNSTABLE" }
Aber ich kann jq '{.actions[2] failCount}' <fileNameWithJSON>
oder andere Variationen nicht wie
jq '{actions[2].failCount}'
jq '{actions[2] failCount}'
jq '{actions .[2].failCount}'
usw.
{ "failCount" : "1" }
zu bekommen?
Ich möchte die result
sowie actions[2] failCount
, actions[2] skipCount
und actions[2] totalCount
schnappen Sie sich einen neuen JSON wie diese zu erstellen:
{ "result" : "UNSTABLE","failCount" : 1, "skipCount" : 14,"totalCount" : 222}
EDIT:
Mein Ziel war nicht müssen die Schlüssel erneut eingeben, falls sie in der API geändert wurden. Ich wollte das im Wesentlichen nicht:
Dies ist im Wesentlichen das nächste, was ich suche. Ich wollte die Schlüssel nicht noch einmal eingeben müssen: '{result, failCount": .actions [2] .failCount, "skipCount": .actions [2] .skipCount, "totalCount": .actions [2] .totalCount} '. Ich wollte einfach von der API selbst ziehen, so dass ich keine wichtigen Änderungen vornehmen müsste, wenn sich die API aus irgendeinem Grund ändert. Vielen Dank. – Wimateeka