Introduction to Azure Pipelines

Azure Pipelines is a cloud service that you can use to automatically build, test, and deploy your code. It integrates with your chosen repository provider and supports a wide range of languages, platforms, and cloud services.

With Azure Pipelines, you can create a full DevOps lifecycle for your applications, from code commit to production deployment. This section covers the core concepts and features of Azure Pipelines.

Getting Started

To begin using Azure Pipelines, you'll need an Azure DevOps organization. You can create one for free. Once set up, you can connect your repository (e.g., Azure Repos, GitHub, Bitbucket) and start creating your first pipeline.

The simplest way to start is by using the built-in templates that Azure Pipelines provides, which can be tailored to your project's needs.

Tip: Always start with a simple pipeline to understand the basics before moving to complex configurations.

YAML Pipelines

YAML pipelines allow you to define your entire pipeline as code. This approach offers several advantages:

  • Version Control: Your pipeline definition is stored in your repository, allowing you to track changes, revert to previous versions, and collaborate effectively.
  • Portability: YAML files are easily shared and reused across projects.
  • Flexibility: Complex logic and conditional execution are straightforward to implement.

A typical YAML pipeline structure includes:


trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your code.
    echo This is a multi-line script.
  displayName: 'Run a multi-line script'
                

Classic Editor

For users who prefer a visual interface, Azure Pipelines also offers a Classic Editor. This editor allows you to configure your build and release pipelines using a point-and-click interface with pre-defined tasks.

While YAML is the recommended approach for modern DevOps practices, the Classic Editor remains a valuable tool for quick setup or for organizations transitioning to YAML.

Build Pipelines

Build pipelines automate the process of compiling source code, running tests, and producing build artifacts. Key components include:

  • Triggers: Events that initiate a build (e.g., code commit, scheduled runs).
  • Agent Pools: Where your build jobs run (Microsoft-hosted or self-hosted agents).
  • Tasks: Individual steps that perform actions like compiling, testing, packaging, and publishing artifacts.

Release Pipelines

Release pipelines automate the deployment of your build artifacts to various environments. They focus on stages, approvals, and deployment strategies.

  • Stages: Logical divisions of your release process (e.g., Dev, QA, Production).
  • Artifacts: The outputs from your build pipeline that are deployed.
  • Approvals: Gates that require manual sign-off before deployment to a stage.

Deployment Jobs

Deployment jobs are a special type of job in YAML pipelines designed for deploying applications to specific environments. They offer features like deployment strategies (e.g., rolling, canary) and built-in integration with Azure resources.


jobs:
- deployment: DeployWebApp
  environment: 'Production'
  strategy:
    runOnce:
      deploy:
        steps:
        - script: echo Deploying to production...
          displayName: 'Deploy to Production'
                

Stages, Jobs, and Steps

Pipelines are structured hierarchically:

  • Stages: Represent a major division in your pipeline, often corresponding to different environments or phases of deployment (e.g., Build, Test, Deploy).
  • Jobs: A collection of steps that run on an agent. Jobs within a stage can run in parallel or sequentially.
  • Steps: The smallest unit of work in a pipeline, typically a single command or task.

Variables and Parameters

Variables allow you to store and reuse values like connection strings, API keys, or configuration settings. Parameters are used in YAML pipelines to provide input values when a pipeline is run manually.

You can define variables at the pipeline level, stage level, or job level, and they can be marked as secret for sensitive information.

Environments and Approvals

Environments in Azure Pipelines represent your deployment targets (e.g., servers, Kubernetes clusters, cloud services). They provide a central place to manage approvals and check deployment history.

Setting up approvals ensures that deployments to critical environments are reviewed and authorized by designated individuals or groups.

Integrations

Azure Pipelines integrates seamlessly with a vast ecosystem of tools and services, including:

  • Code Repositories: Azure Repos, GitHub, Bitbucket, Subversion.
  • Cloud Providers: Azure, AWS, Google Cloud.
  • Package Managers: npm, NuGet, Maven, Docker.
  • Testing Frameworks: JUnit, NUnit, Pytest.
  • Deployment Targets: Kubernetes, Azure App Service, Virtual Machines.

Extensive marketplace extensions are available for even more integration options.