Defines a logical expression which determines which agents may execute builds
of this project. This expression, when tested against the name and labels of
each available agent, will be either
true or
false. If the
expression evaluates to
true, then that agent will be allowed to
execute builds of this project.
If this project should always be built on a specific agent, or on the Jenkins
master, then you can just enter the agent's name, or master
,
respectively.
However, you should generally avoid using the Name of an agent here,
preferring to target the Labels of an agent. As documented on the
configuration page for each agent, and the Configure System page for
the master, labels can be used to represent which operating system the agent
is running on, its CPU architecture, or any number of other characteristics.
Using labels removes the need to re-configure the label expression entered
here each time that you add, remove, or rename agents.
A label expression can be as simple as entering a single label or
agent name, for example android-builder
, or
linux-machine-42
.
You can also make use of various operators to create more complex
expressions.
Supported operators
The following operators are supported, in descending order of precedence:
- (expression)
-
parentheses — used to explicitly define the associativity of an expression
- !expression
-
NOT — negation; the result of expression must not be true
- a && b
-
AND — both of the expressions a and b must be
true
- a || b
-
OR — either of the expressions a or b may be
true
- a -> b
-
"implies" operator — equivalent to !a || b.
For example, windows -> x64 could be thought of as "if a Windows
agent is used, then that agent must be 64-bit", while still
allowing this project to be executed on any agents that do not have
the windows label, regardless of whether they have also have an
x64 label
- a <-> b
-
"if and only if" operator — equivalent to a && b ||
!a && !b
For example, windows <-> dc2 could be thought of as "if a
Windows agent is used, then that agent must be in datacenter 2, but
if a non-Windows agent is used, then it must not be in datacenter
2"
Notes
-
All operators are left-associative, i.e. a -> b -> c is
equivalent to (a -> b) -> c.
-
Labels or agent names can be surrounded with quotation marks if they
contain characters that would conflict with the operator syntax.
For example, "osx (10.11)" || "Windows Server".
-
Expressions can be written without whitespace, but including it is
recommended for readability; Jenkins will ignore whitespace when
evaluating expressions.
-
Matching labels or agent names with wildcards or regular expressions is
not supported.
-
An empty expression will always evaluate to true, matching all
agents.
Examples
- master
- Builds of this project may be executed only on the Jenkins master
-
- linux-machine-42
-
Builds of this project may be executed only on the agent with the name
linux-machine-42 (or on any machine that happens to have a label
called linux-machine-42)
- windows && jdk9
-
Builds of this project may be executed only on any Windows agent that has
version 9 of the Java Development Kit installed (assuming that agents
with JDK 9 installed have been given a jdk9 label)
- postgres && !vm && (linux || freebsd)
-
Builds of this project may be executed only any on Linux or FreeBSD agent,
so long as they are not a virtual machine, and they have PostgreSQL
installed (assuming that each agent has the appropriate labels — in
particular, each agent running in a virtual machine must have the
vm label in order for this example to work as expected)