Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-28131] Checks if the executor is a Master
  • Loading branch information
recena committed Jun 27, 2015
1 parent b5c7f4f commit f9e64a4
Showing 1 changed file with 13 additions and 3 deletions.
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.workflow.support.steps;

import com.google.inject.Inject;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -22,6 +23,7 @@
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.slaves.WorkspaceList;

import java.io.IOException;
import java.io.PrintStream;
import java.io.Serializable;
Expand All @@ -33,11 +35,16 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;

import jenkins.model.Jenkins;
import jenkins.model.Jenkins.MasterComputer;
import jenkins.model.queue.AsynchronousExecution;
import jenkins.util.Timer;

import org.acegisecurity.Authentication;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.durabletask.executors.ContinuableExecutable;
import org.jenkinsci.plugins.durabletask.executors.ContinuedTask;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
Expand All @@ -52,6 +59,7 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;

import static java.util.logging.Level.*;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -417,12 +425,14 @@ private final class PlaceholderExecutable implements ContinuableExecutable {
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.getEnvironment();
env.overrideAll(computer.buildEnvironment(listener));
env.put("NODE_NAME", label);
env.put(COOKIE_VAR, cookie);

if (getExecutor().getOwner() instanceof MasterComputer) {
env.put("NODE_NAME", "master");
} else {
env.put("NODE_NAME", label);
}
synchronized (runningTasks) {
runningTasks.put(cookie, new RunningTask(context));
}
Expand Down

0 comments on commit f9e64a4

Please sign in to comment.