jenkins - 在 Jenkins 管道中设置节点标签

标签 jenkins groovy 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 .

关于jenkins - 在 Jenkins 管道中设置节点标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291917/

相关文章:

unit-testing - 禁用 grails 命令对象中的验证约束以进行单元测试(使用 Spock)

jenkins - 如何使用 GitHub Org 插件从 jenkins 管道 (jenkinsfile) 触发另一个作业?

Jenkins 管道: Executing a shell script

docker - 推送到 google 容器注册表失败 : Retrying

java - 如何在 2 :45 AM and 4:00 AM on 20th August? 之间每 15 分钟安排一次 Jenkins 作业

java - 在多模块maven项目中查找 Unresolved maven依赖项

jenkins - 如何说服 Jenkins 共享多个工作的内部编号?

java - Jenkins 显示 log4j 提示 : log4j:WARN No appenders could be found for logger

java - 如何将闭包从 groovy 导入到 java?

java - 格式化 XML 的日期以包含 UTC 偏移量