github-action: does the IF have an ELSE?

sab picture sab · Mar 29, 2020 · Viewed 8.9k times · Source

in github action I have an if, but I still need to run someother thing if I'm in the else case. Is there a clean way to do it or do I have to do another step with the same condition at false?

 - if: contains(['SNAPSHOT'],env.BUILD_VERSION)
   name:IF
   run: echo ":)"
 - if: false == contains(['SNAPSHOT'], env.BUILD_VERSION)
   name: Else
   run: echo ":("

Answer

fabasoad picture fabasoad · Apr 8, 2020

GitHub Actions doesn't have else statement to run a different command/action/code. But you're right, all what you need to do is to create another step with reversed if condition. BTW, you can just use ! instead of false ==.

Here are some links: if statement, operators