Multiple if-conditional with always() is always true

Hi all,
I have an if-statement in a workflow file. The idea is to run the step if the branch is master and only then. I want to run the step no matter the state from the previous step.

  • name: Send Notification
    if: ${{ always() }} && github.ref == ‘refs/heads/master’

If I remove ${{ always() }} the step is not executed if the previous step fails.
When I have the combination like the one above, the step is executed for all branches.
It seems like the always() function is overriding the the entire conditional.

I have also tried to group the if statement with surrounding parenthesis but no difference.
Can someone please shed some light on this?

All the best

Try wrapping the ${{ ... }} around the whole expression. I suspect like this the second part is interpreted just as text, and only the ${{ always() }} part as an expression.

if: ${{ always() && github.ref == 'refs/heads/master' }}

It should actually work without ${{ }} as well:

if: always() && github.ref == 'refs/heads/master'

Don’t wrap parts of the condition, but only the entire expression or nothing.

When you use expressions in an if conditional, you may omit the expression syntax ( ${{ }} ) because GitHub automatically evaluates the if conditional as an expression.

1 Like

"${{}}" has a lot of incomprehensible behavior.
Example) How to write multi-line condition in if

If these are specs, not parser bugs, I think that the specification should be described in the document.

The behavior of "${{}}" is too mysterious for our team, so we avoid using "${{}}".

1 Like

Hi @swtrustly,

As airtower-luna and Simran-B said, you can wrap the ${{ }} around the whole expression, or directly remove it.

I copied your code, and find another typo for single quote ‘refs/heads/master’ in your code, please change to use 'refs/heads/master'.


Thanks for the answers. I wrapped the statement with the double curly and it works fine now.
Agree with @kei-yamazaki, "${{}}" is pretty mysterious.

1 Like