I have the following JSON object:
{
"_class": "hudson.model.FreeStyleBuild",
"actions": [
{
"_class": "hudson.model.CauseAction",
"causes": [
{
"_class": "hudson.model.Cause$UserIdCause",
"shortDescription": "Started by user SYSTEM",
"userId": "SYSTEM",
"userName": "SYSTEM"
},
{
"_class": "hudson.model.Cause$UserIdCause",
"shortDescription": "Started by user SYSTEM",
"userId": "SYSTEM",
"userName": "SYSTEM"
},
{
"_class": "hudson.model.Cause$UserIdCause",
"shortDescription": "Started by user SYSTEM",
"userId": "SYSTEM",
"userName": "SYSTEM"
},
{
"_class": "com.sonyericsson.rebuild.RebuildCause",
"shortDescription": "Rebuilds build #1",
"upstreamBuild": 1,
"upstreamProject": "gcimpoies-test5",
"upstreamUrl": "job/gcimpoies-test5/"
},
{
"_class": "com.sonyericsson.rebuild.RebuildCause",
"shortDescription": "Rebuilds build #1",
"upstreamBuild": 1,
"upstreamProject": "gcimpoies-test5",
"upstreamUrl": "job/gcimpoies-test5/"
}
]
},
{
"_class": "hudson.model.CauseAction",
"causes": [
{
"_class": "com.sonyericsson.rebuild.RebuildCause",
"shortDescription": "Rebuilds build #1",
"upstreamBuild": 1,
"upstreamProject": "gcimpoies-test5",
"upstreamUrl": "job/gcimpoies-test5/"
}
]
},
{
},
{
"_class": "com.sonyericsson.jenkins.plugins.bfa.model.FailureCauseBuildAction"
},
{
},
{
},
{
}
],
"artifacts": [
],
"building": false,
"description": null,
"displayName": "#2",
"duration": 15,
"estimatedDuration": 61,
"executor": null,
"fullDisplayName": "gcimpoies-test5 #2",
"id": "2",
"keepLog": false,
"number": 2,
"queueId": 6,
"result": "FAILURE",
"timestamp": 1522153325922,
"url": "http://localhost:8080/job/gcimpoies-test5/2/",
"builtOn": "",
"changeSet": {
"_class": "hudson.scm.EmptyChangeLogSet",
"items": [
],
"kind": null
},
"culprits": [
]
}
And I want to extract the username: SYSTEM
I tried using JsonSlurper but with no luck. I believe the right way to go is using JSONObject instead.
Any help is much appreciated.