diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java index 9cf355e0..d2704215 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java @@ -138,7 +138,18 @@ public int getNumber() throws AbortException { @Whitelisted public JSONArray getBuildCauses() throws IOException, ClassNotFoundException { - return getBuildCauses("hudson.model.Cause"); + JSONArray result = new JSONArray(); + + for(Cause cause : build().getCauses()) { + StringWriter w = new StringWriter(); + CauseAction causeAction = new CauseAction(cause); + DataWriter writer = JSON.createDataWriter(causeAction, w); + Model model = new ModelBuilder().get(CauseAction.class); + model.writeTo(causeAction, writer); + // return a slightlly cleaner object by removing the outer object + result.add(JSONObject.fromObject(w.toString()).getJSONArray("causes").get(0)); + } + return result; } /** @@ -151,18 +162,17 @@ public JSONArray getBuildCauses() throws IOException, ClassNotFoundException { * @throws IOException */ @Whitelisted - public JSONArray getBuildCauses(String className) throws IOException, ClassNotFoundException { - Class clazz = Class.forName(className); + public JSONArray getBuildCauses(String className) throws IOException { JSONArray result = new JSONArray(); for(Cause cause : build().getCauses()) { - if (clazz.isInstance(cause)) { + if (className.equals(cause.getClass().getName())) { StringWriter w = new StringWriter(); CauseAction causeAction = new CauseAction(cause); DataWriter writer = JSON.createDataWriter(causeAction, w); Model model = new ModelBuilder().get(CauseAction.class); model.writeTo(causeAction, writer); - // return a slightlly cleaner object by removing the outer object + // return a slightly cleaner object by removing the outer object result.add(JSONObject.fromObject(w.toString()).getJSONArray("causes").get(0)); } }