我会在 Jenkinsfile 的“when”语法中评估两个条件。 特别是,我需要检查 params.x 和 params.y 何时为真。 我可以使用“and”运算符将两者插入同一个表达式吗?
最佳答案
来自 Jenkins documentation :
expression
Execute the stage when the specified Groovy expression evaluates to true, for example: when { expression { return params.DEBUG_BUILD } }
Note that when returning strings from your expressions they must be converted to booleans or return null to evaluate to false.
Simply returning "0" or "false" will still evaluate to "true".
因此,如果您插入一个有效的 groovy 语句,它应该可以工作。
或者你可以使用allOf
语句,例如
when {
allOf {
expression { params.x == true }
expression { params.y == true }
}
}
关于jenkins - Jenkinsfile 中基于参数的表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65682929/