How do I use the warn section in a pipeline as code?

Modified on Wed, 21 Jun 2023 at 04:37 PM

The warn section in a pipeline as code allows you to define actions that should be taken when a job produces a warning message during its execution. It provides a way to handle warnings separately from failures and successes, allowing you to take appropriate actions based on the specific warnings generated by a job.


To use the warn section in your pipeline as code, follow these steps:


Define the job you want to handle warnings for in your pipeline YAML file. For example:

stages:
  - build

job1:
  stage: build
  script:
    - echo "Running the job..."
  warn:
    message: "This job produced a warning."
    when: on_warning


Specify the warn section within the job definition and configure its properties. In the example above, the warn section is set with a warning message that will be displayed when the job produces a warning.


Optionally, you can specify the when condition under the warn section to control when the warning message should be displayed. In this case, the warning message will be displayed only when the job generates a warning.


Here's an example of a complete pipeline YAML file that includes the warn section:


stages:
  - build

job1:
  stage: build
  script:
    - echo "Running the job..."
  warn:
    message: "This job produced a warning."
  when: always


In this example, the job1 will display the warning message defined in the warn section when it produces a warning during its execution. The warning message helps draw attention to potential issues or concerns without causing the job to be marked as failed.


By using the warn section, you can handle warnings in your pipeline separately and take appropriate actions based on the specific warnings generated by a job. This allows you to address potential issues proactively and ensure the smooth execution of your pipeline.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article