在 Jenkins 管道中设置节点标签
Set node label in Jenkins pipeline
是否可以为节点设置标签而不是名称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。
是否可以为节点设置标签而不是名称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。