Skip to content

Commit

Permalink
Merge pull request #220 from jglick/CoreWrapperStep.Callback
Browse files Browse the repository at this point in the history
More gracefully handle `StepContext` errors from `CoreWrapperStep.Callback`
  • Loading branch information
jglick authored Jul 27, 2022
2 parents 3f4dda6 + bb5133d commit 6b9c830
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6b9c830

Please sign in to comment.