Skip to content

Gitlab CI does not detect the right exit code from a python script

Summary

A runner for a python (not sure if it affects other languages) does not detect the exit code properly for allow_failure.exit_codes

Steps to reproduce

Minimal CI example:

test_exit_2_allow_2:
  stage: test
  script:
    - echo "Run python with exit code 2, this should not be allowed to fail"
    - python3 -c 'import sys; sys.exit(2)'
  allow_failure:
    exit_codes: 2

test_exit_0_allow_2:
  stage: test
  script:
    - echo "Run python with exit code 0, this should be allowed to fail"
    - python3 -c 'import sys; sys.exit(0)'
  allow_failure:
    exit_codes: 2

test_exit_2_allow_1:
  stage: test
  script:
    - echo "Run python with exit code 2, this should not be allowed to fail"
    - python3 -c 'import sys; sys.exit(2)'
  allow_failure:
    exit_codes: 1

test_exit_1_allow_2:
  stage: test
  script:
    - echo "Run python with exit code 1, this should not be allowed to fail"
    - python3 -c 'import sys; sys.exit(1)'
  allow_failure:
    exit_codes: 2

What is the current bug behavior?

test_exit_2_allow_2 fails instead of skips and test_exit_2_allow_1 skips instead of fails ... the other two behave as expected. In all cases it appears the running thinks there is an exit code of 2 but debugging by capturing and displaying the exit code shows the correct one.

What is the expected correct behavior?

The appropriate exit code should be picked up so that selective failure can be applied to the job.

Relevant logs and/or screenshots

Created fresh repository.
Checking out 9bb3c1d7 as jh_tag_test...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
$ echo "Run python with exit code 2, this should be allowed to fail"
Run python with exit code 2, this should be allowed to fail
$ python3 -c 'import sys; sys.exit(2)'
Cleaning up file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

Results of GitLab environment info

The environment was installed with gitlab-ee-14.2.1-ee.0.el7.x86_64.rpm

Edited by James Hogarth