Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cause a job to finish with warning in Gitlab

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

like image 976
Zhenya1980 Avatar asked Sep 04 '18 13:09

Zhenya1980


People also ask

What is used to restrict when a job is executed on your pipeline GitLab?

Run jobs for scheduled pipelines To configure a job to be executed only when the pipeline has been scheduled, use the rules keyword.

Why does pipeline fail in GitLab?

It might be a security vulnerability. The code in your most recent commit could be vulnerable, or a dependency could be at risk, either of which would trigger a failed security test and thus a failed pipeline.


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.

like image 112
Mureinik Avatar answered Sep 20 '22 19:09

Mureinik


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
like image 41
Justin Lewis Avatar answered Sep 20 '22 19:09

Justin Lewis