Azure  

Deploy Azure Apps Automatically Using Azure Pipelines (YAML)

Introduction

Manually deploying apps to Azure can get repetitive — especially when your team updates code often.
That’s where Azure Pipelines comes in. It helps you automate your build and deployment using a simple YAML file.

With every new code push, your app can automatically:

  • Build and package itself

  • Test for errors

  • Deploy to Azure App Service or Azure Function App

Let’s go step-by-step to create one such automated deployment pipeline.

What You Need Before Starting

  1. An Azure account with an existing App Service or Function App.

  2. Source code stored in a Git repo (like GitHub or Azure Repos).

  3. An Azure DevOps project (you can create one for free at dev.azure.com).

  4. A Service Connection between Azure DevOps and your Azure Subscription — this lets the pipeline deploy to your resources.

Step 1: Create a YAML Pipeline

In your code repository, create a file named azure-pipelines.yml at the root.

Here’s a simple example for a .NET web app:

trigger:
  - main  # run the pipeline whenever code is pushed to 'main'

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'

steps:
  # Step 1: Build and publish the project
  - task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      publishWebProjects: true
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'

  # Step 2: Deploy to Azure App Service
  - task: AzureWebApp@1
    inputs:
      azureSubscription: '<your-service-connection-name>'
      appName: '<your-app-service-name>'
      package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

Step 2: Understanding the YAML File

Let’s break it down in plain English:

  • trigger → Tells the pipeline when to run (here, whenever you push to the main branch).

  • pool → Defines which virtual machine image to use for building.

  • DotNetCoreCLI@2 task → Builds your app and packages it into a folder.

  • AzureWebApp@1 task → Uploads your package to the Azure App Service and deploys it.

Step 3: Create the Pipeline in Azure DevOps

  1. Go to your Azure DevOps project → PipelinesNew Pipeline

  2. Choose your repo (GitHub or Azure Repos).

  3. Pick “YAML” and select your azure-pipelines.yml file.

  4. You’ll be asked to authorize your Azure connection (Service Connection).

  5. Save and run the pipeline.

Now, your code will automatically build and deploy to Azure each time you push new changes.

- task: AzureWebApp@1
  inputs:
    azureSubscription: '<your-service-connection-name>'
    appName: '<your-app-service-name>'
    deployToSlotOrASE: true
    resourceGroupName: '<your-resource-group>'
    slotName: 'staging'
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '<your-service-connection-name>'
    WebAppName: '<your-app-service-name>'
    ResourceGroupName: '<your-resource-group>'
    SourceSlot: staging
    SwapWithProduction: true

Step 4: (Optional) Deploy to a Staging Slot

You can deploy to a staging slot first — test your app, then swap it into production:

- task: AzureWebApp@1
  inputs:
    azureSubscription: '<your-service-connection-name>'
    appName: '<your-app-service-name>'
    deployToSlotOrASE: true
    resourceGroupName: '<your-resource-group>'
    slotName: 'staging'
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '<your-service-connection-name>'
    WebAppName: '<your-app-service-name>'
    ResourceGroupName: '<your-resource-group>'
    SourceSlot: staging
    SwapWithProduction: true

Step 5: Make It Smarter with Conditions

You can make the deployment smarter — for example, only deploy from the main branch:

- task: AzureWebApp@1
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
  inputs:
    azureSubscription: '<your-service-connection-name>'
    appName: '<your-app-service-name>'
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

Conclusion

Azure Pipelines takes the pain out of deployments.
Once set up, you’ll have a fully automated CI/CD pipeline — no more manual zip uploads or deployment clicks.

Whether you’re deploying:

  • A Web App,

  • A Function App, or

  • A Containerized App,

The process is almost the same — define your YAML, connect to Azure, and let DevOps handle the rest.