Jenkinsfile 中基于参数的表达式

问题描述 投票:0回答:1

我会评估 Jenkinsfile 的“when”语法中的两个条件。 特别是,我需要检查 params.x 何时为 true,params.y 何时为 true。 我可以使用“and”运算符将两者插入到同一个表达式中吗?

jenkins jenkins-pipeline expression
1个回答
10
投票

来自詹金斯文档

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 }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.