我正在尝试解析一些JSON并从'stop-emu'获取状态。
def stageJson = new JsonSlurper().parseText(response?.content)
stageJson.stages.each { echo(it) }
//status = ????
上面的代码返回以下内容:
16:49:47 [_links:[self:test], id:2, name:test_name, execNode:none, status:SUCCESS, pauseDurationMillis:0]
[Pipeline] echo
16:49:47 [_links:[self:test], id:5, name:test_name, execNode:none, status:SUCCESS, pauseDurationMillis:0]
[Pipeline] echo
16:49:47 [_links:[self:test], id:6, name:stop-emu, execNode:none, status:FAILED, pauseDurationMillis:0]
[Pipeline] echo
16:49:47 [_links:[self:test], id:100, name:del-work, execNode:none, status:SUCCESS, pauseDurationMillis:0]
[Pipeline] echo
我已经到了一半,如果名字= stop-emu,我不确定如何获取状态。
答案 0 :(得分:0)
找到第一个
stageJson.stages.find{it.name=='stop-emu'}?.status
如果你有并且需要收集所有这些:
stageJson.stages.findAll{it.name=='stop-emu'}.collect{it.status}