Azure DevOps – Tips and Tricks – 8 – Improve YAML template development experience and productivity using YAML Template Editor (currently preview)

In this article, we are going to learn how to increase your productivity by using 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 the features like Intellisense etc. So, people find it little difficult working 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 working 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 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 which 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 file yet.

Now, if try to run the main-pipeline, you would 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 get’s to know about the Syntax error in the YAML Template only while running the pipeline which hinders the development experience.

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 it’s features.

YAML Template Editor

Let’s now dive into our topic of using the YAML template editor. As of today, it’s a preview feature and you need to explicitly enable it either for yourself or you can enable it for the entire organization if you are an administrator.

Enable the YAML Template Editor by navigating to the User Setting icon and then click on Preview Features as shown below.

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – User Settings

When you click on the Preview features, the below popup opens and shows all the current preview features. Some of them are enabled automatically and we need to enable a few. As shown below, I have enabled YAML Templates editor.

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – Preview Features

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 -template in your YAML pipeline. Clicking on the Validate button shows any errors in the Template file.

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – YAML Template not found

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

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – Expected Document Parse Error

Edit the template file

Now, I would like to add some code in 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 Validate button again and if the template is really valid, you will get the below message.

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – Validation OK

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

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – View Template

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

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – View Template in Editor

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

Azure DevOps – Tips and Tricks – 8 – YAML Templates Editor – Intellisense

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

Thanks for reading.

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