Class EnvVars
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
,String> NavigableMap<String,
,String> SortedMap<String,
String>
While all the platforms I tested (Linux 2.6, Solaris, and Windows XP) have the case sensitive
environment variable table, Windows batch script handles environment variable in the case preserving
but case insensitive way (that is, cmd.exe can get both FOO and foo as environment variables
when it's launched, and the "set" command will display it accordingly, but "echo %foo%" results in
echoing the value of "FOO", not "foo" — this is presumably caused by the behavior of the underlying
Win32 API GetEnvironmentVariable
acting in case insensitive way.) Windows users are also
used to write environment variable case-insensitively (like %Path% vs %PATH%), and you can see many
documents on the web that claims Windows environment variables are case insensitive.
So for a consistent cross platform behavior, it creates the least confusion to make the table case insensitive but case preserving.
In Jenkins, often we need to build up "environment variable overrides"
on the controller, then to execute the process on agents. This causes a problem
when working with variables like PATH
. So to make this work,
we introduce a special convention PATH+FOO
— all entries
that starts with PATH+
are merged and prepended to the inherited
PATH
variable, on the process where a new process is executed.
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Modifier and TypeFieldDescriptionEnvironmental variables that we've inherited. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Takes a string that looks like "a=b" and adds that to this map.static EnvVars
Creates a magic cookie that can be used as the model environment variable when we later kill the processes.Expands the variables in the given string by using environment variables represented in 'this'.Convenience messageGets the platform for which these env vars targeted.static EnvVars
getRemote
(hudson.remoting.VirtualChannel channel) Obtains the environment variables of a remote peer.void
Overrides the current entry by the given entry.overrideAll
(Map<String, String> all) Overrides all values in the map by the given map.overrideExpandingAll
(Map<String, String> all) Overrides all values in the map by the given map.void
putAllNonNull
(Map<String, String> map) Add entire map but filter null values out.void
putIfNotNull
(String key, String value) Add a key/value but only if the value is not-null.static void
Resolves environment variables against each other.void
setPlatform
(Platform platform) Sets the platform for which these env vars target.Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, merge, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
-
Field Details
-
masterEnvVars
Environmental variables that we've inherited.Despite what the name might imply, this is the environment variable of the current JVM process. And therefore, it is the Jenkins controller's environment variables only when you access this from the controller.
If you access this field from agents, then this is the environment variable of the agent.
-
-
Constructor Details
-
EnvVars
public EnvVars() -
EnvVars
-
EnvVars
-
EnvVars
Builds an environment variables from an array of the form"key","value","key","value"...
-
-
Method Details
-
getPlatform
Gets the platform for which these env vars targeted.- Returns:
- The platform.
- Since:
- 2.144
-
setPlatform
Sets the platform for which these env vars target.- Parameters:
platform
- the platform to set.- Since:
- 2.144
-
override
Overrides the current entry by the given entry.Handles
PATH+XYZ
notation. -
overrideAll
Overrides all values in the map by the given map. Seeoverride(String, String)
.- Returns:
- this
-
overrideExpandingAll
Overrides all values in the map by the given map. Expressions in values will be expanded. Seeoverride(String, String)
.- Returns:
this
-
resolve
Resolves environment variables against each other. -
get
Convenience message- Since:
- 1.485
-
put
-
putIfNotNull
Add a key/value but only if the value is not-null. Otherwise no-op.- Since:
- 1.556
-
putAllNonNull
Add entire map but filter null values out.- Since:
- 2.214
-
addLine
Takes a string that looks like "a=b" and adds that to this map. -
expand
Expands the variables in the given string by using environment variables represented in 'this'. -
createCookie
Creates a magic cookie that can be used as the model environment variable when we later kill the processes. -
getRemote
public static EnvVars getRemote(hudson.remoting.VirtualChannel channel) throws IOException, InterruptedException Obtains the environment variables of a remote peer.- Parameters:
channel
- Can be null, in which case the map indicating "N/A" will be returned.- Returns:
- A fresh copy that can be owned and modified by the caller.
- Throws:
IOException
InterruptedException
-