diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
index a6485c6c..3350d92c 100644
--- a/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
+++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
@@ -35,7 +35,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import net.sf.json.JSONObject;
+import org.jenkinsci.plugins.structs.describable.CustomDescribableModel;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest2;
@@ -104,7 +106,7 @@ private static final class ExpanderImpl extends EnvironmentExpander {
}
}
- @Extension public static class DescriptorImpl extends StepDescriptor {
+ @Extension public static class DescriptorImpl extends StepDescriptor implements CustomDescribableModel {
@Override public String getFunctionName() {
return "withEnv";
@@ -152,11 +154,34 @@ private static final class ExpanderImpl extends EnvironmentExpander {
}
}
return b.toString();
+ } else if (overrides instanceof Map) {
+ return ((Map, ?>) overrides).keySet()
+ .stream()
+ .filter(e -> e instanceof String)
+ .map(Object::toString)
+ .collect(Collectors.joining(", "));
} else {
return null;
}
}
+ @NonNull
+ @Override
+ public Map
A list of environment variables to set, each in the form
+ Environment variables to set can also be defined in a map, each entry of the form (Note that here we are using single quotes in Groovy, so the variable expansion is being done by the Bourne shell, not Jenkins.)
+ Environment variables to be set may also be defined in a map. For example:
+VARIABLE=value
or VARIABLE= to unset variables otherwise defined.
You may also use the syntax PATH+WHATEVER=/something
to prepend /something to $PATH.
+[VARIABLE: 'value'].
+
+node {
+ withEnv([MYTOOL_HOME: '/usr/local/mytool']) {
+ sh '$MYTOOL_HOME/bin/start'
+ }
+}
+
+
See the documentation for the env singleton for more information on environment variables.
diff --git a/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java
index 41e41177..73f3855b 100644
--- a/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java
+++ b/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java
@@ -149,6 +149,48 @@ public class EnvStepTest {
});
}
+ @Test public void mapArguments() throws Throwable {
+ sessions.then(j -> {
+ WorkflowJob p = j.createProject(WorkflowJob.class, "p");
+ p.setDefinition(new CpsFlowDefinition(
+ "node {\n" +
+ " withEnv(a: 1, b: 2, c: 'hello world', d: true, e: null) {\n" +
+ " echo(/a=$a b=$b c=$c d=$d e=${env.e}/)" +
+ " }\n" +
+ "}", true));
+ WorkflowRun b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
+ j.assertLogContains("a=1 b=2 c=hello world d=true e=null", b);
+ List