Search code examples
pythongitgitlabgitlab-ci

How to issue warnings in gitlab pipeline without exit/failure?


I'm new to Gitlab and I have come across a case where we would like to issue warnings when a certain event occurs in a job(example: a table was dropped). I would like to know how to achieve this if possible. I explored and came across setting the allow_failure flag in .gitlab-ci.yml. But this is not something that I need.


Solution

  • In GitLab CI/CD pipelines, you can use the 'script' keyword to run arbitrary commands during pipeline run . You can use echo command to output warning messages during pipeline run, but these messages will not cause the pipeline to fail or exit .

    Example :

    script:
        - echo "This is a warning message"
    

    You can also use the warn command which is similar to echo but it prefixes the message with "WARNING":

    script:
       -warn "This is a warning message"
    

    Additionally, GitLab also provides a specific command warn_only that will issue a warning instead of a failure .

    script:
      -
    command_that_might_fail
    || warn_only