5

I have to validate a pipeline before triggering it. One criterion of the validation is if a CI/CD variable has one of the accepted values. Is there a way to find if it is matching the correct values?

I tried to create an array of values then to check it in the workflow rules but it is not clear from the other questions how to do that.

So it should be looking like this:

#WARNING: invalid yml!
variables:
  ValidValues: ["Value1", "Value2", "SomeOtherValue"]

workflow:
  rules:
    - if: ValidValues contains $GivenValue
      when: always
meJustAndrew
  • 6,011
  • 8
  • 50
  • 76

1 Answers1

6

Searching on this issue, I found that I can add the allowed values to a regex on which I can check at the workflow rules. In the end it looks like this:

workflow:
  rules:
    - if: $GivenValue =~ /\b(Value1|Value2|SomeOtherValue)\b/
      when: always
    - when: never

Unfortunately I did not found a solution on my initial approach (adding the allowed values to an array, then looking for them) but this works as well.

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76