Class SystemProperties
System.getProperty(String)
and related calls.
This allows us to get values not just from environment variables but also from
the ServletContext
, so properties like jenkins.whatever.Clazz.disabled
can be set in context.xml
and the app server's boot script does not
have to be changed.
This should be used to obtain hudson/jenkins "app"-level parameters
(e.g. jenkins.whatever.Clazz.disabled
), but not for system parameters
(e.g. os.name
).
If you run multiple instances of Jenkins in the same virtual machine and wish
to obtain properties from context.xml
, make sure these Jenkins instances use
different ClassLoaders. Tomcat, for example, does this automatically. If you do
not use different ClassLoaders, the values of properties specified in
context.xml
is undefined.
Property access is logged on Level.CONFIG
. Note that some properties
may be accessed by Jenkins before logging is configured properly, so early access to
some properties may not be logged.
While it looks like it on first glance, this cannot be mapped to EnvVars
,
because EnvVars
is only for build variables, not Jenkins itself variables.
- Since:
- 2.236
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
allowOnAgent
(String key) Mark a key whose value should be made accessible in agent JVMs.static boolean
getBoolean
(String name) Returnstrue
if the system property named by the argument exists and is equal to the string"true"
.static boolean
getBoolean
(String name, boolean def) Returnstrue
if the system property named by the argument exists and is equal to the string"true"
, or a default value.static Integer
getInteger
(String name) Determines the integer value of the system property with the specified name.static Integer
getInteger
(String name, Integer def) Determines the integer value of the system property with the specified name, or a default value.static Integer
getInteger
(String name, Integer def, Level logLevel) Determines the integer value of the system property with the specified name, or a default value.static Long
Determines the long value of the system property with the specified name.static Long
Determines the integer value of the system property with the specified name, or a default value.static Long
Determines the integer value of the system property with the specified name, or a default value.static String
Gets the system property indicated by the specified key.static String
Gets the system property indicated by the specified key, or a default value.static String
Gets the system property indicated by the specified key, or a default value.static Boolean
optBoolean
(String name) ReturnsBoolean.TRUE
if the named system property exists and is equal to the string"true
(ignoring case), returnsBoolean.FALSE
if the system property exists and doesn't equal"true
otherwise returnsnull
if the named system property does not exist.
-
Method Details
-
allowOnAgent
Mark a key whose value should be made accessible in agent JVMs.- Parameters:
key
- Property key to be explicitly allowed
-
getString
Gets the system property indicated by the specified key. This behaves just likeSystem.getProperty(java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
key
- the name of the system property.- Returns:
- the string value of the system property,
or
null
if there is no property with that key. - Throws:
NullPointerException
- ifkey
isnull
.IllegalArgumentException
- ifkey
is empty.
-
getString
Gets the system property indicated by the specified key, or a default value. This behaves just likeSystem.getProperty(java.lang.String, java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
key
- the name of the system property.def
- a default value.- Returns:
- the string value of the system property,
or
null
if the property is missing and the default value isnull
. - Throws:
NullPointerException
- ifkey
isnull
.IllegalArgumentException
- ifkey
is empty.
-
getString
Gets the system property indicated by the specified key, or a default value. This behaves just likeSystem.getProperty(java.lang.String, java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
key
- the name of the system property.def
- a default value.logLevel
- the level of the log if the provided key is not found.- Returns:
- the string value of the system property,
or
null
if the property is missing and the default value isnull
. - Throws:
NullPointerException
- ifkey
isnull
.IllegalArgumentException
- ifkey
is empty.
-
getBoolean
Returnstrue
if the system property named by the argument exists and is equal to the string"true"
. If the system property does not exist, return"false"
. if a property by this name exists in theServletContext
and is equal to the string"true"
. This behaves just likeBoolean.getBoolean(java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
name
- the system property name.- Returns:
- the
boolean
value of the system property.
-
getBoolean
Returnstrue
if the system property named by the argument exists and is equal to the string"true"
, or a default value. If the system property does not exist, return"true"
if a property by this name exists in theServletContext
and is equal to the string"true"
. If that property does not exist either, return the default value. This behaves just likeBoolean.getBoolean(java.lang.String)
with a default value, except that it also consults theServletContext
's "init" parameters.- Parameters:
name
- the system property name.def
- a default value.- Returns:
- the
boolean
value of the system property.
-
optBoolean
ReturnsBoolean.TRUE
if the named system property exists and is equal to the string"true
(ignoring case), returnsBoolean.FALSE
if the system property exists and doesn't equal"true
otherwise returnsnull
if the named system property does not exist.- Parameters:
name
- the system property name.- Returns:
Boolean.TRUE
,Boolean.FALSE
ornull
- Since:
- 2.16
-
getInteger
Determines the integer value of the system property with the specified name. This behaves just likeInteger.getInteger(java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
name
- property name.- Returns:
- the
Integer
value of the property.
-
getInteger
Determines the integer value of the system property with the specified name, or a default value. This behaves just likeInteger.getInteger(String,Integer)
, except that it also consults theServletContext
's "init" parameters. If neither exist, return the default value.- Parameters:
name
- property name.def
- a default value.- Returns:
- the
Integer
value of the property. If the property is missing, return the default value. Result may benull
only if the default value isnull
.
-
getInteger
Determines the integer value of the system property with the specified name, or a default value. This behaves just likeInteger.getInteger(String,Integer)
, except that it also consults theServletContext
's "init" parameters. If neither exist, return the default value.- Parameters:
name
- property name.def
- a default value.logLevel
- the level of the log if the provided system property name cannot be decoded into Integer.- Returns:
- the
Integer
value of the property. If the property is missing, return the default value. Result may benull
only if the default value isnull
.
-
getLong
Determines the long value of the system property with the specified name. This behaves just likeLong.getLong(java.lang.String)
, except that it also consults theServletContext
's "init" parameters.- Parameters:
name
- property name.- Returns:
- the
Long
value of the property.
-
getLong
Determines the integer value of the system property with the specified name, or a default value. This behaves just likeLong.getLong(String,Long)
, except that it also consults theServletContext
's "init" parameters. If neither exist, return the default value.- Parameters:
name
- property name.def
- a default value.- Returns:
- the
Long
value of the property. If the property is missing, return the default value. Result may benull
only if the default value isnull
.
-
getLong
Determines the integer value of the system property with the specified name, or a default value. This behaves just likeLong.getLong(String, Long)
, except that it also consults theServletContext
's "init" parameters. If neither exist, return the default value.- Parameters:
name
- property name.def
- a default value.logLevel
- the level of the log if the provided system property name cannot be decoded into Long.- Returns:
- the
Long
value of the property. If the property is missing, return the default value. Result may benull
only if the default value isnull
.
-