jenkins - Jenkinsfile 中基于参数的表达式

标签 jenkins jenkins-pipeline expression

我会在 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/

相关文章:

作为 jenkins 从机的 Linux/mac 权限

node.js - 从 Windows 批处理文件返回字符串

c# - 如何迭代确定 C# 表达式树的深度?

jenkins - 多个项目共享一个 jenkinsfile

docker - 如何在本地机器上查找docker镜像

javascript - AngularJS 通过内联表达式过滤

c# - 将强类型表达式转换为匿名类型返回

linux - 连接 Jenkins 从站到主站已中止 : Ping response time is too long or timed out

jenkins - 将 JSHint 集成到 Jenkins 中,无需使用 Checkstyle 或 JSLint 报告器

c# - Jenkins 未使用新的 MSBuild 恢复目标恢复 NuGet 包