Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GitHub Actions completes job as success even it receives non-zero exit code

I made my test.bat to be executed from GitHub Actions. The issue I have is that GitHub Actions completes job as success even it receives non-zero exit code from the test.bat.

Here is the YAML file for GitHub Actions.

jobs: 
  run_test:
    runs-on: [self-hosted,Windows]
    steps: 
    - run: ./test.bat

Here is the test.bat file that executes test.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

REM This runs test and returns non-zero exit code when test fails.
test.exe -fail     

REM Now, assume test failed, and it retruns exit code 4.
echo %error_level%

Now, GitHub Actions completes the job as success even it receves non-zero exit code (which is 4).

If I remove echo %error_level% then GitHub Action completes the job as fail, properly.

Why?

>Solution :

The echo command succeeds sucessfully and returns an exit code of 0.

Make sure you either capture the ERRORLEVEL:

REM This runs test and returns non-zero exit code when test fails.
test.exe -fail     
set return_code=%ERRORLEVEL%
REM Now, assume test failed, and it returns exit code 4.
echo %return_code%
exit %return_code%

Or do an if statement and return your own exit code.

REM This runs test and returns non-zero exit code when test fails.
test.exe -fail

IF NOT %ERRORLEVEL% == 0 (
    echo %ERRORLEVEL%
    exit 1  
)     
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading