Search code examples
jenkinsconditional-statementsboolean-operations

Jenkins conditional steps token logic operators


I inject environmental variable from a file myprop.property that has the contents:

var1=y
var2=y

The build steps:
1. Inject environment variables:

Property File Path:${JENKINS_HOME}/myprop.propertie


  1. Execute Windows batch command (to verify variable injected successully)

echo var1 = %var1%
echo var2 = %var2%

  1. Condition steps (multiple)

Run?: Boolean condition
Token: ${ENV,var="var1"}||${ENV,var="var2"}
Steps to run if condition is met: echo Yes, works!

Run the build, the condition in step 3 never met while step 2 display the correct values of the variables. I have tried the conditions and operators:

var1=y, var2=y: ${ENV,var="var1"}||${ENV,var="var2"}
var1=y, var2=y: ${ENV,var="var1"}|${ENV,var="var2"}

var1=y, var2=n: ${ENV,var="var1"}||${ENV,var="var2"}
var1=y, var2=n: ${ENV,var="var1"}|${ENV,var="var2"}

Uppercase or lower case of the values do not make any difference. I am running jenkins 1.641 on windows 7 pro.
If I use only one e.g. ${ENV,var="var1"} in the token field, it works as expected.


Solution

  • This works, change step 3 to:

    Run?: Or
    Boolean condition
    Token: ${ENV,var="var1"}
    Or
    Boolean condition
    Token: ${ENV,var="var2"}
    Never

    these are actually three conditions. the execution asserts the first condition first, if it's met, stop checking; if not met, asserts the second; and so on until the last condition that is Never, meaning if no condition is met, stop executing the step.