Jenkinsfile中基于参数的表达式

vlurs2pr  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(130)

我将在Jenkinsfile的“when”语法中计算两个条件。特别是,我需要检查params.x和params.y何时为真。我可以用“and”操作符将这两个条件插入同一个表达式中吗?

6za6bjd0

6za6bjd01#

摘自Jenkins文档:

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 }
  }
}

相关问题