From bb5133d7ea729728973917e652422d12a8a6cfb8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 4 May 2022 10:43:58 -0400 Subject: [PATCH] More gracefully handle `StepContext` errors from `CoreWrapperStep.Callback` (cherry picked from commit 846c7bf8052a498f7050e63a3f8203cd165e8821) --- .../workflow/steps/CoreWrapperStep.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java index 1dcee6c5..e4721039 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java @@ -41,6 +41,8 @@ import java.util.Map; import java.util.Set; import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.logging.Level; +import java.util.logging.Logger; import jenkins.model.Jenkins; import jenkins.tasks.SimpleBuildWrapper; import org.kohsuke.stapler.DataBoundConstructor; @@ -50,6 +52,8 @@ */ public class CoreWrapperStep extends Step { + private static final Logger LOGGER = Logger.getLogger(CoreWrapperStep.class.getName()); + private final SimpleBuildWrapper delegate; @DataBoundConstructor public CoreWrapperStep(SimpleBuildWrapper delegate) { @@ -177,15 +181,26 @@ private static final class Callback extends BodyExecutionCallback.TailCall { assert run != null; final TaskListener listener = context.get(TaskListener.class); assert listener != null; - final FilePath workspace = context.get(FilePath.class); - final Launcher launcher = context.get(Launcher.class); + FilePath workspace; + Launcher launcher; if (disposer.requiresWorkspace()) { + workspace = context.get(FilePath.class); if (workspace == null) { throw new MissingContextVariableException(FilePath.class); } + launcher = context.get(Launcher.class); if (launcher == null) { throw new MissingContextVariableException(Launcher.class); } + } else { + try { + workspace = context.get(FilePath.class); + launcher = context.get(Launcher.class); + } catch (IOException | InterruptedException x) { + LOGGER.log(Level.FINE, null, x); + workspace = null; + launcher = null; + } } // always pass the workspace context when available, even when it is not strictly required if (workspace != null && launcher != null) {