From 7af5454f079ebdae301ec4b4968948a52cc6bf25 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 7 Feb 2024 12:37:06 -0500 Subject: [PATCH] `DefaultStepContext.get` should directly handle certain types --- .../workflow/support/DefaultStepContext.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java b/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java index fb9f7ae1..7ed36589 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java @@ -72,7 +72,20 @@ public abstract class DefaultStepContext extends StepContext { *

{@inheritDoc} */ @Override public final T get(Class key) throws IOException, InterruptedException { - T value = doGet(key); + T value = null; + if (Run.class.isAssignableFrom(key)) { + value = castOrNull(key, getExecution().getOwner().getExecutable()); + } else if (Job.class.isAssignableFrom(key)) { + value = castOrNull(key, get(Run.class).getParent()); + } else if (FlowExecution.class.isAssignableFrom(key)) { + value = castOrNull(key,getExecution()); + } else if (FlowNode.class.isAssignableFrom(key)) { + value = castOrNull(key, getNode()); + } + if (value != null) { + return value; + } + value = doGet(key); if (key == EnvVars.class) { Run run = get(Run.class); EnvironmentAction a = run == null ? null : run.getAction(EnvironmentAction.class); @@ -100,14 +113,6 @@ public abstract class DefaultStepContext extends StepContext { } */ return castOrNull(key, n); - } else if (Run.class.isAssignableFrom(key)) { - return castOrNull(key, getExecution().getOwner().getExecutable()); - } else if (Job.class.isAssignableFrom(key)) { - return castOrNull(key, get(Run.class).getParent()); - } else if (FlowExecution.class.isAssignableFrom(key)) { - return castOrNull(key,getExecution()); - } else if (FlowNode.class.isAssignableFrom(key)) { - return castOrNull(key, getNode()); } else { // unrecognized key return null;