Reputation: 1364
Is it possible to set a label instead of a name for nodes Groovy? We want to define labels outside the script to easily access them from the Jenkins Dashboard.
Idea: Instead of:
Groovy Script
node('Slave_1 || Slave_2'){ echo 'Hello world' }
We want something like this:
Pipeline configuration
Node Label Name: slaveGroup
Node Label Value: Slave_1 || Slave_2
Groovy Script
node(slaveGroup){echo 'Hello world'}
Or is it possible to use the labels you can set in slave configuration directly in the Groovy script?
Upvotes: 13
Views: 40951
Reputation: 1364
Just found out that the Pipline Syntax (Generator) gives this option:
Valid Operators
The following operators are supported, in the order of precedence.
(expr)
parenthesis
!expr
negation
expr&&expr
and
expr||expr
or
a -> b
"implies" operator. Equivalent to !a|b. For example, windows->x64 could be thought of as "if run on a Windows slave, that slave must be 64bit." It still allows Jenkins to run this build on linux.
a <-> b
"if and only if" operator. Equivalent to a&&b || !a&&!b. For example, windows<->sfbay could be thought of as "if run on a Windows slave, that slave must be in the SF bay area, but if not on Windows, it must not be in the bay area."
All operators are left-associative (i.e., a->b->c <-> (a->b)->c ) An expression can contain whitespace for better readability, and it'll be ignored.
Label names or slave names can be quoted if they contain unsafe characters. For example, "jenkins-solaris (Solaris)" || "Windows 2008"
More in the documentation.
Upvotes: 12