是否可以为节点 Groovy 设置标签而不是名称?我们希望在脚本之外定义标签,以便从 Jenkins 仪表板轻松访问它们。
主意:
代替:
Groovy 脚本
node('Slave_1 || Slave_2'){ echo 'Hello world' }
我们想要这样的东西:
管道配置
Node Label Name: slaveGroup
Node Label Value: Slave_1 || Slave_2
Groovy 脚本
node(slaveGroup){echo 'Hello world'}
或者是否可以直接在 Groovy 脚本中使用可以在从属配置中设置的标签?
最佳答案
刚刚发现管道语法(生成器)提供了这个选项:
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"
更多在 documentation .
关于jenkins - 在 Jenkins 管道中设置节点标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291917/