Azure DevOps – Tips and Tricks – 9 – Debug Pipelines using System.Debug or Enable System Diagnostics to fix the YAML Pipeline errors

In this article, we will learn how to review the logs that helps in troubleshoot for any errors in the Pipelines and fix the same.

Advertisements

Objective

One of the most important aspects in the life cycle of the Azure DevOps – Pipeline development is to have tools and techniques in place to find out the root cause of any error that would have occurred during the pipeline Azure DevOps pipeline execution.

In this article, we are going to learn about the features that Azure DevOps pipeline supports the DevOps engineers to quickly understand what’s going on in the pipeline.

By default, Azure DevOps pipeline provides logs which provide information about the execution of each step in the pipeline. In order to view the default logs, click on the specific task which shows the default logs for that task as shown below.

Azure DevOps – Tips and Tricks – 9 – Debug and Troubleshoot Pipelines – System Debug True – Default Logs

At times, the default logs wouldn’t help us in understanding what went wrong and how to provide a fix for the issue.

In such cases, it would be helpful if we get more diagnostic logs about each step in the Azure DevOps pipelines. Below are the two different techniques to enable the feature of getting additional logs.

Advertisements
  1. Enable Diagnostic logs for an Individual pipeline execution.
  2. Enable Diagnostic logs for every pipeline execution

Individual Pipeline Runs:

If you would like to get additional logs for a specific pipeline execution, all you need to do is enable the Enable System Diagnostics checkbox as shown below just before you hit the Run button.

Azure DevOps – Tips and Tricks – 9 – Debug and Troubleshoot Pipelines – Enable System Diagnostics

All Pipeline executions:

If you always want to enable System Diagnostics to capture the Diagnostics traces for cases where the pipeline executed automatically (Continuous Integration scenarios), then in such cases, all you need is to create a variable in the pipeline with the name system.debug and the set the value to true as shown below.

Azure DevOps – Tips and Tricks – 9 – Debug and Troubleshoot Pipelines – System Debug True

System.debug = true variable helps us in getting the diagnostics logs in all the three types of types of pipelines

Advertisements
  1. YAML based Pipelines
  2. Classic Build Pipelines
  3. Classic Release Pipelines

Once we set the value of system.debug to true, then the pipeline starts showing additional logs in the purple colour as shown below.

Azure DevOps – Tips and Tricks – 9 – Debug and Troubleshoot Pipelines – System Debug True – Toggle Timestamps

In the above scenario, the purple color logs might not make any sense. However, in some scenarios these additional logs would be very handy if you are looking for fixing an issue.

As shown in the above screenshot you can also view timestamps by clicking on the Toggle timestamps button.

Advertisements

If you would like to view the logs without any colors, you can click on the View raw log button which opens up the logs in a separate browser window where you can save them as well.

Download Logs

If you would like to share the logs to some other teams who doesn’t have access to your pipeline, you can download the logs by clicking on the Download Logs button in the Pipeline Summary page as shown below.

Azure DevOps – Tips and Tricks – 9 – Debug and Troubleshoot Pipelines – System Debug True – Download Logs

Summary

In this article, we have learnt how to get additional diagnostic logs that would help the Azure DevOps engineer to get additional details for troubleshooting and fixing the error by using the Enable System Diagnostic button or setting the System.Debug variable to true. We have also learnt how to download the logs from the Pipeline Summary Page.

Advertisements

Thanks for reading. Please leave your comments if you have any feedback or comments.

Do you like this article? If you want to get more updates about these kind of articles, you can join my Learning Groups

WhatsApp

Telegram

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s