通过 curl 使用从 Jenkins 构建 api 调用中获取的 JSON
{
"_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>"
}
}
为什么我能做到jq '{result}' <fileNameWithJSON>
并得到
{ "result" : "UNSTABLE" }
但我不能做jq '{.actions[2] failCount}' <fileNameWithJSON>
或其他变化,如
jq '{actions[2].failCount}'
jq '{actions[2] failCount}'
jq '{actions .[2].failCount}'
等等
得到
{ "failCount" : "1" }
?
我想抓住result
, 以及actions[2] failCount
,actions[2] skipCount
并actions[2] totalCount
创建一个新的 JSON,如下所示:
{ "result" : "UNSTABLE","failCount" : 1, "skipCount" : 14,"totalCount" : 222}
编辑:
我的目标是不必重新指定密钥,以防它们在 api 中发生变化。我基本上不想要这个:
{result, "failCount":.actions[2].failCount, "skipCount":.actions[2].skipCount, "totalCount": .actions[2].totalCount}