Jenkins conditional steps token logic operators

19,161

Solution 1

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.

Solution 2

Try this instead, It worked for me, we need to mention Boolean Condition with Token mentioned in the image.

enter image description here

Share:
19,161

Related videos on Youtube

Heinz
Author by

Heinz

Updated on September 17, 2022

Comments

  • Heinz
    Heinz over 1 year

    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.