How to cause a job to finish with warning in Gitlab

Viewed 7496

I mean to get this status:

enter image description here

I can finish my job with failure, by "exit 1" , but can't do the same with warning

2 Answers

Warnings in Gitlab aren't an exit status you can control from within the job, but a configuration option for the job itself. In the .gitlab-ci.yml file, you need to add the flag allow_failure:

somejob:
  stage: test
  script:
    - some_script
  allow_failure: true

If this job then fails (i.e., terminates with an exit code that isn't 0), it will end with a warning status and not block the pipeline from continuing.

This is possible since 13.8:

test_job:
  script:
    - execute_script_that_will_fail 
  # if the script exit code is 137 or 255 the job will allow to be 
  # failed and the pipeline will continue to run
  allow_failure:
    exit_codes: # User defined exit code
      - 137
      - 255
Related