Search code examples
gitlabgitlab-cigitlab-ci-runnergitlab-ci.yml

Change gitlab CI/CD exit code


I'm using docker to run a program as part of the CI/CD process. at the program, if the exit code is 2 I don't want the CI/CD to fail and only get a warning.

added this to the gitlab-ci.yml file:

  allow_failure:
    exit_codes: 
      - 2

but even tho the docker exit code is (2) at the pipeline I'm getting ERROR: Job failed: exit code 1

How can I change the error code of the pipeline to be like as the docker error code?

Thanks.


Solution

  • With the allow_failure keyword, your job is allowed to fail. It means that it won't failed if the specified exit_code resulted.

    Your job will still have an exit code, but it will be marked in warning in your pipeline instead of failed

    As an example, I made a simple job :

    stages:
        - test
    
    test_error_code:
        stage: test
        image: alpine:3.15.4
        script:
            - echo "bienvenuto"
            - exit 2
        allow_failure:
            exit_codes: 2
    

    After adding the last two line, the pipeline moved to status warning : See pipeline picture

    Hope it helps you!

    You can find more information here : https://docs.gitlab.com/ee/ci/yaml/#allow_failure