Why a "static" array doesn't work with GitHub contains workflow expression?

Viewed 54

From the documentation, this works:

contains('Hello world', 'llo')

However, this will not:

contains(['6', '7', '8'], matrix.foo)

Unexpected symbol: '['. Located at position 10 within expression: contains(['6', '7', '8'], matrix.foo)

Is there any way to check the that matrix.foo is either 6, 7, or 8 using contains?

1 Answers

The contains function can't achieve the result you expect alone, you would also need to use the fromJson function with an array list.

In that case, your expression should instead look like this:

if: contains(fromJson('["6", "7", "8"]'), matrix.foo)

and the opposite like this:

if: ${{ !contains(fromJson('["6", "7", "8"]'), matrix.foo) }}

I tested it here if you want to have a look:

Related