diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java index c51038cb47..4bc691380d 100755 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java @@ -347,29 +347,33 @@ public void onClose(int i, String s) { String.format("cd \"%s\"%s", pwd, NEWLINE).getBytes(StandardCharsets.UTF_8)); } + + EnvVars envVars = new EnvVars(); + //get global vars here, run the export first as they'll get overwritten. if (globalVars != null) { - this.setupEnvironmentVariable(globalVars, watch); + envVars.overrideAll(globalVars); } if(rcEnvVars != null) { - this.setupEnvironmentVariable(rcEnvVars, watch); + envVars.overrideAll(rcEnvVars); } - EnvVars envVars = new EnvVars(); if (environmentExpander != null) { environmentExpander.expand(envVars); } //setup specific command envs passed into cmd if (cmdEnvs != null) { - LOGGER.log(Level.FINEST, "Launching with env vars: {0}", Arrays.toString(cmdEnvs)); for (String cmdEnv : cmdEnvs) { envVars.addLine(cmdEnv); } } + LOGGER.log(Level.FINEST, "Launching with env vars: {0}", envVars.toString()); + this.setupEnvironmentVariable(envVars, watch); + doExec(watch, printStream, masks, commands); if (closables == null) { closables = new ArrayList<>();