if (exec == null) {
throw new IllegalStateException("running task without associated executor thread");
}
Computer computer = exec.getOwner();
// Set up context for other steps inside this one.
Node node = computer.getNode();
if (node == null) {
throw new IllegalStateException("running computer lacks a node");
}
TaskListener listener = context.get(TaskListener.class);
Launcher launcher = node.createLauncher(listener);
Run<?,?> r = context.get(Run.class);
if (cookie == null) {
// First time around.
cookie = UUID.randomUUID().toString();
// Switches the label to a self-label, so if the executable is killed and restarted via ExecutorPickle, it will run on the same node:
label = computer.getName();
EnvVars env = computer.buildEnvironment(listener);
env.put(COOKIE_VAR, cookie);
synchronized (runningTasks) {
runningTasks.put(cookie, context);
}
// For convenience, automatically allocate a workspace, like WorkspaceStep would:
Job<?,?> j = r.getParent();
if (!(j instanceof TopLevelItem)) {
throw new Exception(j + " must be a top-level job");
}
FilePath p = node.getWorkspaceFor((TopLevelItem) j);
if (p == null) {
throw new IllegalStateException(node + " is offline");
}
WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(p);
FilePath workspace = lease.path;