What is Azure Pipelines?
Azure Pipelines, a core component of Azure DevOps, automates the process of building, testing, and deploying code. It integrates continuous integration, continuous testing, and continuous delivery to streamline the software delivery lifecycle. With support for all major programming languages and project types, Azure Pipelines ensures your code is efficiently built, tested, and deployed to any environment.
Benefits of Azure Pipelines
Azure Pipelines offers a fast, reliable, and secure way to automate the build process. It ensures consistent, high-quality code that is ready for deployment.
Key benefits include:
Getting Started with Azure Pipelines
To set up continuous integration and continuous delivery (CI/CD) for your code, sign up for an Azure DevOps organization and Azure Pipelines. This enables you to manage high-performance pipelines for seamless deployments.
For more details, see What is Azure Pipelines?
You can sign up using either a Microsoft account or a GitHub account.
Sign Up with a Microsoft Account
Follow these steps to sign up for Azure DevOps with a Microsoft account:
You'll then be prompted to create your first project and start building pipelines.
Creating a Project in Azure Pipelines
You can create either a public or private project based on your needs. For more details about public projects, see What is a public project?
Follow these steps to create a project:
Note:
Visibility Options:
Once the project is created, you'll be prompted to select the services you want to use.
You're now ready to create your first pipeline or invite others to collaborate on your project.
Inviting Team Members (Optional)
You can invite others to collaborate on your project by adding their email addresses to your organization and project.
To invite team members, follow these steps:
Create Your First Pipeline: Get the Python Sample Code
To begin, fork the following repository into your GitHub account.
Create Your First Python Pipeline
Follow these steps to set up your first Python pipeline in Azure Pipelines:
1. Access Your Azure DevOps Project:
2. Connect Your GitHub Repository:
3. Configure the Pipeline:
4. Commit the YAML File:
5. Monitor Your Pipeline:
6. Customize Your Pipeline:
View and Manage Your Pipelines
Choose Recent to view recently run pipelines (the default view), or choose All to view all pipelines.
Select Runs to view all pipeline runs. You can optionally filter the displayed runs.
View pipeline details
The details page for a pipeline allows you to view and manage that pipeline.
Choose Edit to edit your pipeline. For more information, see the YAML pipeline editor. You can also edit your pipeline by modifying the azure-pipelines.yml file directly in the repository that hosts the pipeline.
Viewing Pipeline Run Details
The pipeline run summary provides real-time and completed run statuses, allowing you to track progress and outcomes effectively.
Key features of the summary pane include:
Jobs and Stages: The Jobs pane offers an overview of your pipeline's stages and job statuses. Depending on your pipeline configuration, the pane may display multiple tabs for stages and jobs.
For example, a pipeline with Build and Deploy stages will show each stage's progress. You can explore individual pipeline steps by selecting the corresponding job from the Stages or Jobs pane.
Choose a job to see the steps for that job.
From the steps view, you can review the status and details of each step. From the More actions. you can toggle timestamps or view a raw log of all steps in the pipeline.
Cancel or Re-run a Pipeline
Pipeline Run: More Actions Menu
The More Actions menu offers several management options for your pipeline runs, including:
Add a Status Badge to Your Repository
Displaying a status badge in your repository helps showcase your commitment to code quality by highlighting the success of your Azure Pipeline.
Copy the Status Badge:
Add the Badge to GitHub:
The status badge will now appear in your repository's description.
Enable Badge Access for Private Projects (Optional):
Because you just changed the Readme.md file in this repository, Azure Pipelines automatically builds your code, according to the configuration in the azure-pipelines.yml file at the root of your repository. Back in Azure Pipelines, observe that a new run appears. Each time you make an edit, Azure Pipelines starts a new run.
Customize your pipeline
Understanding the azure-pipelines.yml File
The pipeline configuration is defined using a YAML file, typically named azure-pipelines.yml, located at the root of your repository. This file outlines the steps for building, testing, and deploying your code.
To access and edit the pipeline YAML:
Pipeline Execution Overview
This pipeline automatically triggers whenever your team pushes changes to the main branch or creates a pull request. It runs on a Microsoft-hosted Linux machine and includes a single step: executing the Maven task.
Change the Build Platform
You can choose to build your project using:
Recommended by LinkedIn
Change the platform to build on
By default, the pipeline runs on a Linux agent, but you can modify the agent pool in the YAML file as needed.
To choose a different platform like Windows or Mac, change the vmImage value:
Add Steps to Your Pipeline
Enhance your pipeline by adding additional scripts or tasks. A task is a pre-configured script designed for specific actions like building, testing, publishing, or deploying your application.
For Java projects, the Maven task handles testing and result publishing. You can also include tasks to publish code coverage reports or perform other operations.
To add steps:
Build Across Multiple Platforms
You can build and test your project on multiple platforms using the strategy and matrix features. These allow you to define multiple configurations for your pipeline runs. Additionally, you can use variables to pass data throughout the pipeline conveniently.
In this example, we'll use a variable to specify the desired image for the build.
To configure multi-platform builds:
with the following content:
Each agent can run only one job at a time. To run multiple jobs in parallel you must configure multiple agents. You also need sufficient parallel jobs.
Build Using Multiple Versions
To build your project with different language versions, you can define a matrix of versions along with a variable. This approach allows you to either:
To build with multiple versions:
Then replace this line in your maven task:
with this line:
Customize CI Triggers
Pipeline triggers automatically initiate a pipeline run based on specific events. For example, you can use the trigger keyword to initiate a pipeline whenever updates are pushed to a branch.
By default, YAML pipelines include a CI trigger for the default branch (usually main). You can further customize triggers for:
To enable PR validation, replace the trigger: step with pr:, as shown in the examples below. This ensures the pipeline runs for each PR update.
To configure triggers: Add one of the following code snippets at the beginning of your azure-pipelines.yml file.
You can specify the full name of the branch (for example, main) or a prefix-matching wildcard (for example, releases/*).
Pipeline Settings
You can view and configure pipeline settings from the More Actions menu on the pipeline details page.
Here’s what you can manage:
Pipeline Settings Configuration
From the Pipeline Settings pane, you can configure the following options:
🔄 Processing of New Run Requests
Control how your pipeline handles new run requests:
📄 YAML File Path
Specify an alternative path for your pipeline's YAML file. This is useful if you move or rename the YAML file.
🔗 Automatically Link Work Items
Link work items to pipeline runs based on associated changes.
Create Work Item on Failure
YAML pipelines don’t include a built-in Create work item on failure option like classic build pipelines. This is because YAML pipelines can have multiple stages, making a pipeline-level setting less practical.
To implement this functionality in a YAML pipeline, you can use one of the following methods:
Example Workflow:
In the following example, two jobs are defined:
Build a YAML Pipeline with Stages
Using multiple stages in your YAML pipeline helps isolate different parts of the process, enhancing quality control, security, and visibility. It also reduces risk by ensuring each stage runs independently.
In this guide, you'll learn how to create a more advanced YAML pipeline with multiple stages and conditions. The example pipeline includes:
This approach improves pipeline reliability and stability. While the example provided works for most cases, you can further customize it to meet specific language or platform requirements.
1. Create a Starter Pipeline
2. Add the Build Stage
The starter pipeline is just a placeholder. To create a functional pipeline, you'll need to replace the default code with a new YAML configuration that defines a Build stage.
3. Add the Test Stage
The Test stage runs tests on your project and publishes the results to Azure DevOps. For more details, refer to the Publish Test Results task.
This stage will only execute if the Build stage completes successfully and cannot be skipped.
Add the following configuration after the Build stage in your pipeline to include the Test stage.
The Test stage includes an attribute that sets Skippable to false. When you set isSkippable to false, a stage can't be skipped. The option to skip the stage is also disabled in the Azure DevOps UI.
4. Deploy to Staging
Add the DeployToStaging stage after the Test stage in your pipeline.
This stage depends on the successful completion of the Test stage and includes two distinct jobs:
The DeployStagingJobWithValidation job includes a Manual Validation task, which pauses the pipeline until a user manually approves the stage. This ensures that changes undergo thorough review before progressing, enhancing security and mitigating potential risks.
Note that the manual approval process runs on the server pool, as manual validations only execute in this environment.
5. Deploy to Production
Add the DeployToProduction stage after the DeployToStaging stage in your pipeline.
In this stage, the application is deployed to production only if the DeployToStaging stage completes successfully and the source branch is either main or release.
The DeployToProduction stage includes two key jobs:
The Manual Validation task in the waitForValidation job ensures that a second human review occurs before the deployment proceeds, similar to the validation process used in the DeployToStaging stage.
View the entire YAML pipeline
Here's the entire pipeline with all of the referenced stages.
➡ 𝐹𝑜𝑙𝑙𝑜𝑤 Ankit Ranjan Ankit Ranjan (DevOps Engineer) 𝑓𝑜𝑟 𝑚𝑜𝑟𝑒 Azure 𝑡𝑖𝑝𝑠 and subscribe to my Azure Newsletter: