Using 'if' in GitHub actions workflow #27105
-
I am trying to run a job on different runners using matrix configuration. Runners names are given as matrix parameters. I want to run a step only for a particular runner I am using a if statement checking the runners name but the step is run even when the if is false. Example code is:
I expect the print to happen when running on ‘ubuntu-latest’ only but it is printed for both runners. How can I run the step only for one runner? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The problem is that you have only So, either wrap the whole expression you want to be evaluated:
Or (special rule for
|
Beta Was this translation helpful? Give feedback.
The problem is that you have only
matrix.platform
wrapped in${{ ... }}
. That marks it as an expression to evaluate, and the rest of the line is implicitly treated as text. And a non-empty string evaluates to “true”.So, either wrap the whole expression you want to be evaluated:
Or (special rule for
if
) just leave the${{ ... }}
and the whole thing will be treated as an expression: