0
0
Azurecloud~5 mins

Release pipeline basics in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
A release pipeline helps you automatically deliver your app updates to users. It takes your tested code and moves it through stages like testing and production without manual steps.
When you want to automatically deploy your app after code changes are tested
When you need to deliver updates to different environments like staging and production
When you want to reduce human errors by automating deployment steps
When you want to track which version of your app is running in each environment
When you want to quickly roll back to a previous version if a problem occurs
Config File - azure-pipelines.yml
azure-pipelines.yml
trigger:
  branches:
    include:
      - main

stages:
- stage: Build
  jobs:
  - job: BuildJob
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '7.x'
    - script: dotnet build --configuration Release
      displayName: 'Build project'

- stage: Deploy
  dependsOn: Build
  jobs:
  - deployment: DeployJob
    environment: 'staging'
    pool:
      vmImage: 'ubuntu-latest'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo "Deploying to staging environment"
            displayName: 'Deploy step'

This YAML file defines a simple release pipeline in Azure DevOps.

  • trigger: Runs the pipeline when code is pushed to the main branch.
  • stages: Defines two stages: Build and Deploy.
  • Build stage: Compiles the app using .NET SDK.
  • Deploy stage: Runs after build and deploys to the staging environment.
Commands
This command creates a new Azure DevOps pipeline using the YAML file. It connects the pipeline to your code repository and sets it to run on the main branch.
Terminal
az pipelines create --name example-release-pipeline --yml-path azure-pipelines.yml --repository https://github.com/example/repo.git --branch main
Expected OutputExpected
Pipeline 'example-release-pipeline' created successfully.
--name - Sets the name of the pipeline
--yml-path - Specifies the YAML file defining the pipeline
--repository - Links the pipeline to the code repository
This command manually starts the release pipeline to run the build and deploy stages.
Terminal
az pipelines run --name example-release-pipeline
Expected OutputExpected
Run started for pipeline 'example-release-pipeline'.
--name - Specifies which pipeline to run
This command shows the latest run of the pipeline so you can check its status and results.
Terminal
az pipelines runs list --pipeline-name example-release-pipeline --top 1
Expected OutputExpected
[{"id":123,"status":"completed","result":"succeeded","createdDate":"2024-06-01T12:00:00Z"}]
--pipeline-name - Filters runs by pipeline name
--top - Limits output to the most recent run
Key Concept

If you remember nothing else from this pattern, remember: a release pipeline automates moving your tested code through stages to deliver updates safely and quickly.

Common Mistakes
Not linking the pipeline to the correct branch in the repository
The pipeline won't trigger automatically on code changes if the branch is wrong
Always specify the correct branch in the trigger section and when creating the pipeline
Skipping the deploy stage or not defining environments
Without deployment steps, the pipeline builds but never delivers the app to users
Include deploy stages with proper environment names to automate delivery
Running the pipeline without checking the build stage success
Deploying broken code causes failures in production or staging
Verify build stage completes successfully before deploying
Summary
Create a release pipeline YAML file defining build and deploy stages.
Use Azure CLI to create and run the pipeline connected to your code repository.
Check pipeline runs to monitor build and deployment status.