Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter based expressions in Jenkinsfile

I would evaluate two conditions in "when" syntax of my Jenkinsfile. In particular, I need to check when params.x is true and params.y is true. Can I insert both in the same expression with the "and" operator?

like image 871
Riccardo Califano Avatar asked Oct 20 '25 13:10

Riccardo Califano


1 Answers

From 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".

So if you insert a valid groovy statement it should work.

Alternatively you can use allOf statement, e.g.

when {
  allOf {
    expression { params.x == true }
    expression { params.y == true }
  }
}
like image 134
ymochurad Avatar answered Oct 22 '25 04:10

ymochurad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!