Skip to content

Commit

Permalink
Don't pass PATH to docker containers
Browse files Browse the repository at this point in the history
Docker containers usually have special PATHs; the PATH defined
in on the Agent won't make sense for the container.

[JENKINS-43590] docker.inside()'s -e flags are random
  • Loading branch information
docwhat committed May 22, 2017
1 parent 7f00f5e commit e04959e
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -46,6 +46,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -126,7 +127,11 @@ public static class Execution extends AbstractStepExecutionImpl {
EnvVars envReduced = new EnvVars(env);
EnvVars envHost = computer.getEnvironment();
envReduced.entrySet().removeAll(envHost.entrySet());
LOGGER.log(Level.FINE, "reduced environment: {0}", envReduced);

// Remove PATH during cat.
envReduced.remove("PATH");

LOGGER.log(Level.FINE, "(cat) reduced environment: {0}", envReduced);
workspace.mkdirs(); // otherwise it may be owned by root when created for -v
String ws = workspace.getRemote();
toolName = step.toolName;
Expand Down Expand Up @@ -236,7 +241,17 @@ private static class Decorator extends LauncherDecorator implements Serializable
} // otherwise we are loading an old serialized Decorator
Set<String> envReduced = new TreeSet<String>(Arrays.asList(starter.envs()));
envReduced.removeAll(Arrays.asList(envHost));

// Remove PATH during `exec` as well.
Iterator<String> it = envReduced.iterator();
while (it.hasNext()) {
if (it.next().startsWith("PATH=")) {
it.remove();
}
}
LOGGER.log(Level.FINE, "(exec) reduced environment: {0}", envReduced);
prefix.addAll(envReduced);

// Adapted from decorateByPrefix:
starter.cmds().addAll(0, prefix);
if (starter.masks() != null) {
Expand Down

0 comments on commit e04959e

Please sign in to comment.