What to do when Azure DevOps YAML Pipelines Fail
A lot of times creating YAML Pipelines in Azure DevOps there is a lot of trial and error. A lot of times there are small incremental changes and resubmitting the updated YAML files for build and deployment.
When these pipelines fail it’s not always easy to troubleshoot or gather additional information as to why pipelines might fail. It’s even harder when leveraging YAML Templates
Luckily there are a few tips and tricks to help do some deeper analysis on why a specific job is failing.
First running a PowerShell command that outputs specific values can be very beneficial to us in determining how the Pipeline is treating variables. May this be variables that were defined or more importantly system defined variables such as system paths. If using an Azure hosted agent we don’t have local access to the box to find out where the folder structure is to confirm or deny how the box is interpreting file path.
There is the PowerShell DevOps Task. This task even has a short cut to better access. A simple command like:
-powershell: Get-ChildItem -Path $(Build.SourceDirectory) -recurse
Will return all the folder and files under the Build Directory in the Pipeline task output. This will make the job a lot easier when trying to further troubleshoot what the build agent is actually seeing on the machine.
The next trick comes when dealing with templates. If the pipeline is leveraging templates, these templates are inserted and expanded at compilation time. What also occurs is the variable and parameter handling. Which means the ability to track how a parameter might be passed from template to template.
To access this information and more enable ‘system diagnostic’ by selecting the pipeline and seeing the checkbox at the bottom like below:
Rerun the job and then there is a ‘Download logs’ button after the job runs:
By clicking this button the azure-pipeline.yml fully expanded with all parameters and variable available to it will be inserted into this one file! This little trick can easily remove some of the magic that is occurring behind the schenes.
Hopefully this quick blog post provides some guidance on a couple ways to troubleshoot Azure DevOps YAML Pipelines! Feel free to leave any feedback.