diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 84c55e8025..d1a8827239 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -521,7 +521,9 @@ public abstract class Computer extends AbstractModelObject implements AccessCont * {@link Publisher}, {@link BuildWrapper}, etc. */ public static Computer currentComputer() { - return Executor.currentExecutor().getOwner(); + Executor e = Executor.currentExecutor(); + // If no executor then must be on master node + return e != null ? e.getOwner() : Hudson.getInstance().toComputer(); } /** diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java index 8ededd42ce..0afc34763b 100644 --- a/core/src/main/java/hudson/model/Executor.java +++ b/core/src/main/java/hudson/model/Executor.java @@ -288,10 +288,11 @@ public class Executor extends Thread implements ModelObject { } /** - * Returns the executor of the current thread. + * Returns the executor of the current thread or null if current thread is not an executor. */ public static Executor currentExecutor() { - return (Executor)Thread.currentThread(); + Thread t = Thread.currentThread(); + return t instanceof Executor ? (Executor)t : null; } private static final Logger LOGGER = Logger.getLogger(Executor.class.getName());