提交 b95f2694 编写于 作者: V Vojtech Juranek

[FIXED JENKINS-19926] Add only new env. variables

Previous patch (3eea3964) broke usescases when evn. variable overwrites already existing one
like PATH = $PATH:/my/path
上级 02e00449
......@@ -1087,9 +1087,10 @@ public abstract class Launcher {
*/
private static EnvVars inherit(Map<String,String> overrides) {
EnvVars m = new EnvVars(EnvVars.masterEnvVars);
// first add all values and then eventually expand them as values can refer other newly added values (see JENKINS-19488)
for (Map.Entry<String,String> o : overrides.entrySet())
m.override(o.getKey(),o.getValue());
// first add all new values and then eventually expand them as values can refer other newly added values (see JENKINS-19488)
for (Map.Entry<String,String> o : overrides.entrySet())
if(m.get(o.getKey()) == null)
m.put(o.getKey(), o.getValue());
for (Map.Entry<String,String> o : overrides.entrySet())
m.override(o.getKey(),m.expand(o.getValue()));
return m;
......
......@@ -25,19 +25,22 @@ package hudson;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import java.io.IOException;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Slave;
import hudson.model.StringParameterDefinition;
import hudson.tasks.CommandInterpreter;
import hudson.tasks.BatchFile;
import hudson.tasks.CommandInterpreter;
import hudson.tasks.Shell;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
public class LauncherTest {
......@@ -45,6 +48,7 @@ public class LauncherTest {
@Rule
public JenkinsRule rule = new JenkinsRule();
@Bug(19488)
@Test
public void correctlyExpandEnvVars() throws Exception {
FreeStyleProject project = rule.createFreeStyleProject();
......@@ -63,6 +67,27 @@ public class LauncherTest {
assertThat(log(build), containsString("aaa aaaccc ccc"));
}
@Bug(19926)
@Test
public void overwriteSystemEnvVars() throws Exception {
Map<String, String> env = new HashMap<String,String>();
env.put("jenkins_19926", "original value");
Slave slave = rule.createSlave(new EnvVars(env));
FreeStyleProject project = rule.createFreeStyleProject();
project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("jenkins_19926", "${jenkins_19926} and new value")));
final CommandInterpreter script = Functions.isWindows()
? new BatchFile("echo %jenkins_19926")
: new Shell("echo ${jenkins_19926}")
;
project.getBuildersList().add(script);
project.setAssignedNode(slave.getComputer().getNode());
FreeStyleBuild build = project.scheduleBuild2(0).get();
assertThat(log(build), containsString("original value and new value"));
}
@SuppressWarnings("deprecation")
private String log(FreeStyleBuild build) throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册