Skip to content
GitLab
Next
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 51,885
    • Issues 51,885
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,580
    • Merge requests 1,580
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #340390
Closed
Open
Issue created Sep 08, 2021 by James Hogarth@james.hogarth

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 Sep 08, 2021 by James Hogarth
Assignee
Assign to
Time tracking