Validating a Harness Expression

Issue:

Trigger does not validate if the required artifact’s inputs exists. This happens when using a StatefulSet image in Kubernetes and the StatefulSet gets stuck, resulting in the user deleting the pod manually to try to redeploy.

Solution:

Use a validation as a shell script step that would fail when it doesn’t evaluate:

export skip="false"

match='$'
match+="{k8s.workload}"

if [ '${k8s.workload}' = $match ]; then
  skip="true"
fi

Reason:

This happens when expression does not resolve to a value. In those cases, Harness will leave the syntax as-is. This is necessary for cases when a Harness expression could represent a valid expression in a script or YAML file. A force failure could break things that appear like a Harness expression but are not.

In the case above, ${k8s.workload} is missing so it evaluates to nothing, and so we leave the string intact as it was.

1 Like