Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github-action: does the IF have an ELSE?

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 ":(" 
like image 512
sab Avatar asked Mar 29 '20 15:03

sab


People also ask

Can we use conditional statements in the GitHub action script?

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 !

Do GitHub Actions jobs run in parallel?

You can configure a GitHub Actions workflow to be triggered when an event occurs in your repository, such as a pull request being opened or an issue being created. Your workflow contains one or more jobs which can run in sequential order or in parallel.

How do I set environment variables in GitHub Actions?

To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.

How do you fail an action in GitHub?

GitHub uses the exit code to set the action's check run status, which can be success or failure . The action completed successfully and other tasks that depends on it can begin. Any other exit code indicates the action failed. When an action fails, all concurrent actions are canceled and future actions are skipped.


1 Answers

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 ==, if you surround your statement with ${{ }}.

Here are some links: if statement, operators

like image 180
fabasoad Avatar answered Sep 23 '22 12:09

fabasoad