0

I end my test step with a simple script that scan a pytest output.log and should exit with -1 if failed, so the job becomes red and not green:

  scripts:
    - lots of test steps
    - bash -c -l "python bin/status.py --statusfile=output.log; exit $?"

But the gitlab-ci-runner returns 0:

20200930123055|ERROR|bin/status.py:53|failed in line:173 
'========================= 2 failed, 5 passed in 16.91s =========================' so returning -1 to shell
Uploading artifacts for successful job
00:01
Uploading artifacts...
output.log: found 1 matching files and directories 
Uploading artifacts as "archive" to coordinator... ok  id=2750517 responseStatus=201 Created token=5Gh42zsB
Job succeeded

program is returning proper exitcode:

python.exe .\bin\status.py --statusfile=C:\users\mobj\Downloads\output.log 
20200930124542|ERROR|.\bin\status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$?
False
python.exe .\bin\status.py --statusfile=C:\users\mobj\Downloads\output2.log 
$?
True

I tried using bin/status.py --statusfile=output.log in sh, but this complains file not found.

MortenB
  • 2,749
  • 1
  • 31
  • 35

1 Answers1

0

I found the error, turns out the ;exit $? in bash wrapping only returns to current instance

$ /bin/bash -c -l "./bin/status.py --statusfile=/mnt/c/Users/mobj/Downloads/output.log --debug; exit $?"
20200930142836|ERROR|./bin/status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$ echo $?
0

So simply removing the ;exit $? makes it correct:

 /bin/bash -c -l "./bin/status.py --statusfile=/mnt/c/Users/mobj/Downloads/output.log --debug"
20200930142754|ERROR|./bin/status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$ echo $?
255
MortenB
  • 2,749
  • 1
  • 31
  • 35