Using an Array Config Variable in Skip Condition

We can declare arrays as Config Variables for Services in Harness and use them as part of Skip Conditions in Workflows to compare with multiple values without needing to explicitly define them in the Condition.

Step-1

  • Create an Application for a type of deployment (this example uses a k8s type)
  • While creating the Service, we would need to define the Config Variables in the form of an array or comma-delimited Values

ED,STAGE
[“ED”,“STAGE”]

This way we can declare multiple values under one variable

Step-2

  • Creating a Workflow for the above Application with multiple steps/Phases
  • Skip conditions can be defined on these steps
    Screenshot 2021-05-27 at 7.37.46 PM
  • Here we can refer to the Config variable (ENVI/ENVS) declared in the Service and apply the skip condition

${serviceVariable.ENVI} =~ “.*ED.*”

  • This way we can loop through multiple values in the Service variable which is an array and Skip the step if it matches any one of the elements satisfying the condition

  • Once the WF is run and the condition is satisfied it would look something like this

Important Note

The placement of the variables being used in Skip Condition is important, as Harness has an order of resolution for them and JEXL
Placing the Config variable on the ** Right-Hand side** results in the Config variable values not getting resolved as they are in an array or comma-delimited format and the skip condition being ignored.

“.*ED.*” =~ ${serviceVariable.ENVI}

Therefore, it is imp to declare them in the below Format where the Config Variable is on the ** Left-Hand side**

${serviceVariable.ENVI} =~ “.*ED.*”

3 Likes