Enhance YAML Template Development in Azure DevOps for Productivity

In this article, we are going to learn how to increase your productivity by using the YAML Template editor

Introduction

Azure DevOps engineers find it comfortable working with one of the below approaches which authoring YAML-based CI/CD pipelines.

  • Azure DevOps YAML Editor – it’s available within the Azure DevOps (ADO) portal.
  • Visual Studio Code with YAML extensions.

Both the above options provide Intellisense which would auto-generate the YAML code with proper syntax highlighting etc.

However, when you work with YAML Templates, that’s not the case. YAML templates are to be authored without features like Intellisense etc. So, people find it a little difficult to work with YAML Templates.

Fortunately, Azure DevOps has launched a new feature called YAML Template Editor which is currently in preview.

In this article, we are doing to learn how to enable this new YAML Template Editor and make our lives easy when working with YAML Templates.

YAML Templates

If you are new to Azure DevOps YAML and never worked with YAML templates, they are used for reusability. If you would like to re-use YAML code then you can create YAML templates and use it multiple times. For more information, please go through the official documentation here.

Problems with Template Development

For some reason, if you are developing the YAML Template in the Azure DevOps portal (within the browser), the development experience is not great. You won’t get Intellisense or Syntax highlighting features. All the errors would be known only when you try to execute the pipeline.

Let’s try to understand a simple Template validation error by creating a new YAML pipeline that uses a Template using the below code.

main-pipeline.yml

steps

script: echo Hello, world! This is the main template
displayName: 'Task in Main Template'

- template: template.yml

template.yml

Don’t create any files yet.

Now, if try to run the main pipeline, you will get an error. There could be many such Template validation errors that would be found only when you are about to Run the pipeline which is frustrating during the development.

DevOps Engineer gets to know about the Syntax error in the YAML Template only while running the pipeline which hinders the development experience.

The good news is Microsoft Azure DevOps Team has recently launched a new feature YAML Template editor which is currently in preview. With this new feature, you get the same experience that you have currently for developing the YAML Pipelines. Let’s learn how to enable the YAML Template editor and understand how to use its features.

YAML Template Editor

Let’s now dive into our topic of using the YAML template editor.

YAML Templates Editor Features

Let’s now understand the features of the YAML Templates editor.

Template Validation

Once you enable the YAML Templates editor feature, as shown in the below screenshot you will the Validate button if you use -the template in your YAML pipeline. Clicking on the Validate button shows any errors in the Template file.

Pieline

Let’s now create the template.yml file with empty content and again click on Validate and let is the error.

Validate

Edit the template file

Now, I would like to add some code to the template file. Navigate to the Repos-Files and then add the below simple code to make the template.yml file a valid one.

steps

script: echo 'hello world'

Within the pipeline, click on the Validate button again and if the template is really valid, you will get the below message.

 Validate button

As soon as the template is valid, the Validate button turns into the View template as shown below.

View template

Clicking on the View Template button opens up the template.yml file in the Template editor as shown below.

Template button

The YAML Template editor provides Intellisense and it also allows us to use the YAML Task assistant as shown below.

 YAML Task

That’s it. These are the features that you would love to use to improve your productivity. If I have missed any other feature, please comment in the comment section.

Thanks for reading.


Similar Articles