Conditions

Conditions can be used to control when a zBuilder task, stage or language step is run. They can also be used to determine if an MVS DD Statement should be allocated. Conditions can also be used to dynamically create a variable value at runtime.

  • Tasks and language steps that do not have a condition: property defined are executed by default.
  • MVS DD statements that do not have a condition: property defined are allocated by default.

For information on how to define and use the condition: property with variables see Conditional variables.

Simple condition

A simple condition is used when all the variables that are referenced in the conditional expression are known to exist and have a value when the variable is referenced. Examples of these types of variables are the zBuilder Predefined Variables as well as user-defined basic variables.

tasks:
  # Only run UnitTest for clean (0) builds
  - task: UnitTest
    condition: ${STATUS} == 0

Referencing a variable that does not exist or has a null value in a condition expression results in an error:

tasks:
  - task: UnitTest
    condition: ${Bob} == 0

This will result in error

BGZZB0032W The referenced value 'null' from key 'Bob' is null or not allowed to be concatenated as a reference within this type.

Null check condition

A null check condition should be used if any variables referenced in the conditional expression might not exist or might be null. This can happen when:

  • A variable does not exist with the referenced name.
  • A file associated variable does not apply to a source file and no default basic variable was defined.
  • A conditional variable does not have a true condition, and no default value was defined.
  • A variable created from a command line option that was not passed in.

In those cases, the condition needs to check if the variable and value exists:

tasks:
  - task: UnitTest
    condition: 
      exists: ${Bob}
      eval: ${Bob} == 0

In the example above, the condition evaluates to true if Bob and its value exists and if the value equals 0.

You can also have a non-existence test:

tasks:
  - task: NoBobTask
    condition: 
      notExists: ${Bob}

In this case the condition evaluates to true because Bob does not exist or its value is null.

Null check conditions have an in-line format that is useful when used in a MVS DD Statement:

- { condition: { exists: "${SDSNEXIT}", eval: "${IS_SQL}" }, dsn: "${SDSNEXIT}",  options: "shr" }

Note that null check conditions can generally be avoided by providing default values whenever possible. String variables with a default value of "" do not need null check conditions.

Conditional expressions

Conditional expressions are defined by using Java boolean expressions. zBuilder uses the Apache Commons JEXL library to help evaluate conditional expressions. Both simple and complex boolean expressions are supported:

# test if this program has EXEC CICS calls
condition: ${IS_CICS}

# test if this is not CICS program
condition: ${IS_CICS} != true

# test if the current RC is equal to or less than 8
condition: ${RC} <= 8

# test if this is a CICS program and the current RC is equal to or less than 8
condition: ${IS_CICS} && ${RC} <= 8

# test if this is a CICS or SQL program
condition: ${IS_CICS} || ${IS_SQL} 

# test if this is a CICS program but not a SQL program and the current RC is equal to or less than 8
condition: ( ${IS_CICS} && ( ${IS_SQL} != true ) ) && ${RC} <= 8 

# test if the name variable and value is not null and is not an empty string
condition: 
  exists: ${name}
  eval:   ${name} != ""

# test if the debug variable exists but not the errPrefix variable and if debug is true
condition: 
  exists: ${debug}
  notExits: ${errPrefix}
  eval: ${debug}

Syntax

# simple condition
condition: string # boolean expression to evaluate to determine if value is returned

# null check condition
condition:
  exists: variable # name of variable to test if exists or value is not null
  notExists: variable # name of variable to test if it does not exist or value is null
  eval: string # boolean expression to evaluate to determine if value is returned

Properties

exists

Used to test if a variable exists and that its value is not null. Both variable names Bob or references ${Bob} are supported. Use YAML array notation if more than one exists: is needed:

condition:
  - exists: ${Foo}
  - exists: ${Bar}

notExists

Used to test if a variable does not exist or that its value is null. Use YAML array notation if more than one notExists: is needed:

condition:
  - notExists: ${Foo}
  - notExists: ${Bar}

eval

The boolean expression to evaluate to determine if value is returned. The expression is test after all exists and notExists are evaluated as true.

Additional topics

For more information about conditions see: