Getting Started with Azure DevOps YAML

Author

Reads 1.3K

Two business professionals brainstorming and planning software development with a whiteboard in an office.
Credit: pexels.com, Two business professionals brainstorming and planning software development with a whiteboard in an office.

Getting Started with Azure DevOps YAML can be a bit overwhelming, especially if you're new to the technology. Azure DevOps YAML is a powerful tool that allows you to automate your development workflows, and it's widely used in the industry.

To get started, you'll need to create a YAML file that defines your pipeline. This file is called a YAML template, and it's used to create a pipeline in Azure DevOps.

The YAML file is written in a human-readable format, making it easy to understand and modify. Azure DevOps YAML uses a syntax similar to JSON, but with a more readable format.

A YAML template typically includes a version number, a trigger to start the pipeline, and a series of tasks that are executed in sequence.

Readers also liked: Azure Devops Create New Area

Configuring Pipelines

Your pipeline configuration resides in a YAML file named azure-pipelines.yml, alongside your application. This file is versioned alongside your application code, following the same branching structure. Keeping the pipeline configuration in version control ensures that any changes causing issues can be easily identified within your codebase.

Credit: youtube.com, Learn Azure DevOps YAML Pipelines: Simple Guide for Beginners

To access the YAML pipeline editor, sign in to your organization and select your project, then choose Pipelines > Pipelines. From there, select the pipeline you want to edit and choose Edit. You can make edits to your pipeline using Intellisense keyboard shortcuts and the task assistant for guidance.

You can commit directly to your branch, or create a new branch and optionally start a pull request after saving your changes. To validate your changes, choose Validate and save.

Configuring CI/CD as Code

You can define pipelines using a YAML file named azure-pipelines.yml, which resides alongside your application code. This file is versioned alongside your application, adhering to the same branching structure.

Each branch can customize the pipeline by editing the azure-pipelines.yml file. This ensures that any changes that cause issues or unexpected outcomes can be easily identified within your codebase.

To access the YAML pipeline editor, you need to sign in to your organization and select your project. Then, choose Pipelines > Pipelines, and select the pipeline you want to edit.

A fresh viewpoint: Azure Yaml Script

Credit: youtube.com, CI/CD Explained | How DevOps Use Pipelines for Automation

To make edits, you can use Intellisense keyboard shortcuts and the task assistant for guidance. Once you're done, choose Save to commit the changes directly to your branch, or create a new branch and start a pull request.

You can also choose Validate and save to ensure the changes are correct before committing them. This feature is available starting in Azure DevOps Server 2022.1.

Task 3: Configuring Parts Unlimited Project

To configure the Parts Unlimited project, you'll need to navigate to your team project on Azure DevOps in a new browser tab. Before digging into the YAML pipelines, it's essential to disable the existing build pipeline.

First, navigate to Pipelines. This is where you'll find the existing pipeline for the Parts Unlimited project. Select the existing PartsUnlimitedE2E pipeline. From the dropdown, you'll want to select Pause pipeline. This will temporarily stop the pipeline, allowing you to make changes without disrupting your workflow.

Pipeline Validation and Deployment

Credit: youtube.com, Azure DevOps Pipeline Environments | DevOps Pipeline approval

Pipeline validation is a crucial step in ensuring your Azure DevOps pipeline runs smoothly. It's like a quality check for your pipeline configuration.

You can validate your pipeline by choosing More actions > Validate. This will catch syntax errors that might prevent your pipeline from starting.

Azure Pipelines validates your pipelines each time you save. You can choose to validate your pipeline before saving or save without validating. If there are any errors, you can cancel or save anyway.

The validation process detects incorrect variable definitions and YAML conditions at the pipeline, stage, and job level. This helps you catch issues early on and avoid unexpected outcomes.

By keeping your pipeline configuration in version control, you can easily identify any changes that cause issues. This is especially useful when working with multiple branches, as each branch can customize the pipeline by editing the azure-pipelines.yml file.

Here's a summary of the validation options:

  • Validate: catches syntax errors and prevents pipeline from starting
  • Save without validating: saves pipeline without checking for errors

By validating your pipeline regularly, you can ensure it runs smoothly and catch any issues before they become major problems.

Adding and Managing Pipelines

Credit: youtube.com, 9. Azure DevOps Manage YAML Pipelines

To define a pipeline in Azure DevOps, you can use a YAML file named azure-pipelines.yml, which resides alongside your application code and is versioned alongside it.

Each branch can customize the pipeline by editing the azure-pipelines.yml file, and keeping the pipeline configuration in version control ensures that any changes that cause issues or unexpected outcomes can be easily identified within your codebase.

To access the YAML pipeline editor, sign in to your organization, select your project, and choose Pipelines > Pipelines. Then, select the pipeline you want to edit and choose Edit. Make edits to your pipeline using Intellisense keyboard shortcuts and the task assistant for guidance.

You can also create a new pipeline using the wizard by navigating to the Pipelines hub, clicking New pipeline, and selecting the Azure Repos Git as the source hosting platform.

Check this out: Azure Pipelines Yml

Adding a Build Definition

You can create a YAML build definition by navigating to the Pipelines hub and clicking New pipeline. This will automatically create the YAML definition based on your project.

Credit: youtube.com, Azure DevOps Tutorial for Beginners | CI/CD with Azure Pipelines

The first step is to select the source hosting platform, which in this case is Azure Repos Git. You can also choose from other supported platforms.

The build definition will be saved as a new file called “azure-pipelines.yml” in the root of the repository. You can customize the build as needed, for example by updating the pool to specify the build should use a Visual Studio 2017 build VM.

To review and customize the trigger, point to the master branch if your repository does not have main (new repos will have “main” instead of “master”).

Here's a step-by-step guide to creating a YAML build definition:

  1. Navigate to the Pipelines hub.
  2. Click New pipeline.
  3. Select the Azure Repos Git as the source hosting platform.
  4. Select the PartsUnlimited repo.
  5. Select the ASP.NET template as the starting point for your pipeline.
  6. Review the contents of the YAML definition.
  7. Update the pool to specify the build should use a Visual Studio 2017 build VM.
  8. Review trigger and point to master if you repo does not have main.
  9. Click Save and run.
  10. Click Save and run to confirm the commit.
  11. Track the build until it completes.

Each task from the YAML file is available for review, including any warnings and errors.

Copy Steps from Classic UI

You can copy individual steps from the classic UI into your pipeline file by clicking the "View YAML" button in the upper right-hand corner of each task.

This will spit out the YAML for that specific task, which you can then copy and paste into your pipeline file.

Make sure to replace any variables in the YAML with the correct values, so your pipeline runs smoothly.

Unfortunately, you can't convert an entire classic pipeline to YAML at once – you have to do it one step at a time.

Understanding Pipelines

Credit: youtube.com, (Simple?) Real World Azure Pipelines YAML Walkthrough

Pipelines are a crucial part of Azure DevOps, and understanding how they work is essential for any developer or team lead. Pipelines are defined using YAML files, which are versioned alongside the application code.

These YAML files live alongside your application code, adhering to the same branching structure. This means each branch can customize the pipeline by editing the YAML file. Keeping the pipeline configuration in version control ensures that any changes that cause issues or unexpected outcomes can be easily identified within your codebase.

YAML pipelines are a text file committed to a Git repository, supporting most of the same features as classic pipelines. They can be used for both builds (creation of artifacts) and releases (deployment of artifacts). YAML is a configuration format that's similar to JSON, but with some key differences.

Here are the key features of YAML pipelines:

  • No quotes required for keys or basic string values
  • Indentation matters
  • Line order matters
  • 99% of what you write in a pipeline will either be an object or an array of objects

One of the biggest advantages of YAML pipelines is versioning. Since they're code files in your version control, you get version history automatically. This makes it easy to track changes and identify issues.

Pipeline Parameters and Steps

Credit: youtube.com, LetsDevOps: Parameterized YAML Pipeline in Azure DevOps, how to use parameters in yaml pipeline.

Pipeline parameters and steps are crucial to a well-functioning YAML pipeline. Your pipeline configuration resides in a YAML file named azure-pipelines.yml, alongside your application.

To customize the pipeline, you can edit the azure-pipelines.yml file in each branch, making it easy to identify and resolve any issues that arise. This ensures that any changes that cause problems can be easily identified within your codebase.

You can copy YAML steps from the classic UI by clicking the "View YAML" button in the upper right-hand corner of each task. This will spit out the YAML for that task, which you can then copy into your pipeline file.

Pre-Deploy One-Off Changes

You can practice one-off deployments ahead of time by creating a branch in your repo, adding a task definition with enabled: false, and pushing the branch to ADO.

To do this, you'll need to create a branch in your repository, which gives you a separate copy of your code to experiment with.

Credit: youtube.com, Introduction to Pipelines for Power Platform | Deploy Solutions to Environments | Tutorial

Find the task you want to disable and add enabled: false to its definition. This will effectively turn off the task without deleting it.

Commit the change and push the branch to Azure DevOps (ADO).

When you're ready to test the one-off deployment, select that branch when you run the pipeline.

Here's a step-by-step guide to help you get started:

  1. Create a branch in your repo.
  2. Find the task you want to disable.
  3. Add enabled: false to the task definition.
  4. Commit the change.
  5. Push the branch to ADO.
  6. Select that branch when you run the pipeline.

Top-Level Parameters

Top-Level Parameters are a powerful feature that allows you to declare parameters in your pipeline file.

These parameters will appear in the Run Pipeline pane and must be populated by the user or have a default value for the pipeline to run.

You can use top-level parameters to let the user skip certain tasks on a given pipeline run, giving you more control over the pipeline's behavior.

This can be especially useful when you want to perform ad-hoc tasks, like reading out a file or fetching app logs, by entering the name of an environment you want the pipeline to run on.

Top-level parameters can also be keys or values in your pipeline definition, which opens up some fun use cases for interpolation at compile time.

Recommended read: Azure Pipeline Tasks

Frequently Asked Questions

Is Azure pipelines YAML or YML?

Azure Pipelines uses a YAML file, not YML, typically named azure-pipelines.yml. This file is usually located at the root of your repository.

Victoria Kutch

Senior Copy Editor

Victoria Kutch is a seasoned copy editor with a keen eye for detail and a passion for precision. With a strong background in language and grammar, she has honed her skills in refining written content to convey a clear and compelling message. Victoria's expertise spans a wide range of topics, including digital marketing solutions, where she has helped numerous businesses craft engaging and informative articles that resonate with their target audiences.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.