Reader small image

You're reading from  Implementing CI/CD Using Azure Pipelines

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781804612491
Edition1st Edition
Concepts
Right arrow
Authors (2):
Piti Champeethong
Piti Champeethong
author image
Piti Champeethong

Piti Champeethong is a senior consulting engineer at MongoDB, Singapore. He has been a part of the software development community for over 20 years and specializes in database application development and CI/CD implementation. He is a Microsoft Certified Trainer, lecturer, and community leader. He lives in Thailand and engages with Thai tech communities, such as the MongoDB Thailand User Group and the Thailand .NET community by speaking at various events. He has made significant contributions to public repositories on .NET and MongoDB technologies, supporting the growth of the Thai tech community.
Read more about Piti Champeethong

Roberto Mardeni
Roberto Mardeni
author image
Roberto Mardeni

Roberto Mardeni has been working in the IT industry for over two decades. He specializes in software development, architecture, and DevSecOps practices around many different application platforms and CI/CD tools, typically focusing on Microsoft .NET and other open source programming languages. He has been working since 2017 as an application innovation specialist on the enterprise sales side at Microsoft, supporting their cloud business. He lives in the United States and helps some of the largest independent software vendors to adopt the Azure platform. This is his first foray into technical writing, but he has contributed to the open source community in different GitHub public repositories of his own and contributed to others as well.
Read more about Roberto Mardeni

View More author details
Right arrow

Extending Advanced Azure Pipelines Using YAML

We created a build pipeline in the previous chapter by creating jobs, tasks, and triggers. This chapter will teach you how to customize the Azure pipeline using YAML, such as by creating condition statements with variable groups when setting some complex conditions. It also helps to create a flexible pipeline rather than the classic online version. For instance, YAML can do that when you need to deploy mobile applications to both the Google Play Console and the App Store connect simultaneously.

By the end of this chapter, you will have learned about creating a build and release pipeline using YAML. You will also have learned how to clone, export, and import YAML from the classic editor in the Azure DevOps portal.

We will cover the following topics:

  • Creating a build pipeline using YAML
  • Creating a release pipeline using YAML
  • Cloning, exporting, and importing a YAML pipeline
  • Complex YAML configurations
  • Advantages...

Creating a build pipeline using YAML

In this section, you will learn how to build a pipeline using YAML. You will also learn how to view YAML on the Azure DevOps portal and save the YAML file in Azure Repos. To create a build pipeline using YAML, follow these steps:

  1. After logging in via the Azure DevOps portal, please select your organization and then navigate to the Pipelines page. Click on New pipeline:
Figure 4.1 – New pipeline

Figure 4.1 – New pipeline

  1. Click on Azure Repos Git, which is a source code repository for the demo:

Figure 4.2 – Azure Repos Git

Figure 4.2 – Azure Repos Git

  1. Click on the PacktAzureDevOps repository:
Figure 4.3 – Select a repository

Figure 4.3 – Select a repository

  1. If you have existing YAML, you will have to select Existing Azure Pipelines YAML file. However, as we are creating a new one here, we will click on Starter pipeline:
Figure 4.4 – Selecting a starter pipeline

Figure 4.4 – Selecting a starter...

Creating a release pipeline using YAML

This section will teach you how to create a release pipeline using YAML. You will also learn how to create stages, jobs, and tasks in YAML format. To do this, follow these steps:

  1. Edit the existing pipeline by clicking on the ellipses () next to it and then click on Edit pipeline:

Figure 4.14 – Editing an existing pipeline

Figure 4.14 – Editing an existing pipeline

  1. Replace all contents of the existing azure-pipelines.yml file, as shown in the following screenshot:
Figure 4.15 – Advanced pipeline with two stages

Figure 4.15 – Advanced pipeline with two stages

There are two stages, as shown in the preceding screenshot:

  • The first stage will display Build stage job
  • The second stage will display Release stage

This scenario displays build and release stages suitable for building the application (the Build stage) and deploying the application (the Release stage). It is easy to find errors or issues because if the build...

Cloning, exporting, and importing a YAML pipeline

This section will teach you how to clone, export, and import a YAML pipeline from the Azure DevOps portal. These actions will help you save time when you need to duplicate the same template and adjust it. If you need to make a new Azure pipeline, you can do so by cloning it from an existing one. Let’s look at the steps that are to be followed to perform these tasks:

  • Clone: You can clone a pipeline using copy and paste, which is the easy, fast way to clone a pipeline.
  • Export and import: The following steps show you can export an entire YAML file from a pipeline:
    1. You can export a YAML pipeline by clicking on Edit:
Figure 4.21 – Edit pipeline

Figure 4.21 – Edit pipeline

  1. Click on | Download full YAML to download a file:

Figure 4.22 – Download the complete YAML

Figure 4.22 – Download the complete YAML

  1. Open a downloaded file and copy and paste it into the new pipeline you created.
  2. ...

Complex YAML configurations

The YAML syntax supports several complex configurations that allow for the modularization and reuse of YAML files. Some examples of these are template reuse and the implementation of template expressions. We’ll explore how these features work in the following sections.

YAML template reuse

When working with large projects and several applications being developed by the same members of a team, it is helpful to define common templates to reuse instead of writing everything from scratch for the CI/CD needs of every application. For this purpose, Azure Pipelines supports making references to templates to reuse steps, jobs, and stages. This is particularly helpful in reducing the duplication of YAML because all applications or deployment processes are the same within the project. It is also possible to include parameters in the templates, to pass values that can be used in the referenced template to customize the behavior.

Let’s look at...

Advantages and limitations of YAML-based pipelines

First, let’s look at the benefits of using YAML-based pipelines:

  • YAML pipelines are stored as code in your version control system, such as Azure Repos. This means they can be versioned, branched, and reviewed like any other code, providing better collaboration and traceability.
  • YAML pipelines allow you to introduce changes in a controlled way when implementing a branch strategy that isolates work from different team members. This ensures changes are tested without affecting other members of the team until completed.
  • YAML pipelines make reproducing the build and release process consistently across different environments easy. This helps reduce configuration drift and ensures consistent results.
  • You can control your build and release processes. You can define the steps, dependencies, and conditions, enabling you to customize pipelines to meet your specific needs.

Despite these benefits, using these pipelines...

Summary

This chapter taught you how to build and release pipelines using YAML. Using this method is more powerful for developers than using the classic editor on the Azure DevOps portal. Developers can save YAML files in their Azure Repos, which will help them review each revision’s pipeline. With YAML-based pipelines, you can deliver more efficient, transparent, and developer-centric CI/CD processes. You also learned about complex scenarios and how to reduce YAML, reuse templates, and add dynamic behavior through expressions. Finally, you learned about the pros and cons of YAML-based pipelines.

In the next chapter, you will learn in depth about implementing a build and release pipeline using YAML and how to reuse build tasks using Node.js, NPM, .NET, and Docker to build a pipeline.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Implementing CI/CD Using Azure Pipelines
Published in: Dec 2023Publisher: PacktISBN-13: 9781804612491
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Piti Champeethong

Piti Champeethong is a senior consulting engineer at MongoDB, Singapore. He has been a part of the software development community for over 20 years and specializes in database application development and CI/CD implementation. He is a Microsoft Certified Trainer, lecturer, and community leader. He lives in Thailand and engages with Thai tech communities, such as the MongoDB Thailand User Group and the Thailand .NET community by speaking at various events. He has made significant contributions to public repositories on .NET and MongoDB technologies, supporting the growth of the Thai tech community.
Read more about Piti Champeethong

author image
Roberto Mardeni

Roberto Mardeni has been working in the IT industry for over two decades. He specializes in software development, architecture, and DevSecOps practices around many different application platforms and CI/CD tools, typically focusing on Microsoft .NET and other open source programming languages. He has been working since 2017 as an application innovation specialist on the enterprise sales side at Microsoft, supporting their cloud business. He lives in the United States and helps some of the largest independent software vendors to adopt the Azure platform. This is his first foray into technical writing, but he has contributed to the open source community in different GitHub public repositories of his own and contributed to others as well.
Read more about Roberto Mardeni