Azure DevOps CI/CD (with self-hosted agents)

Assumptions & Prerequisites:

To follow this guide, ensure you have the following:

  1. Access to Azure DevOps (free subscription is sufficient).
  2. Git installed, along with .NET 6 or 7 SDK.
  3. Code to push to an Azure repository (If you don't have any, we'll generate some for you).
  4. An App Service Plan and a web app as the target for the release pipeline.
  5. An installed and configured local agent on your machine for building and release functions.

Step 1: Check code into Azure Repo

If you already have a web app, check it into an Azure Repo. If you don't have any code, follow these steps:

  • Install the .NET 7 SDK using the command:
    winget install --id Microsoft.DotNet.SDK.7
  • Create a folder named "myapp" and run the following commands:
    cd myapp
    dotnet new web -n MyWebApp
    dotnet run
  • Open the URL provided in the command output to verify if the app runs correctly on your local machine.

Step 2: Download and install local agents

To avoid errors in the build and release pipelines, you need to download and install local agents. If you skip this step, you'll encounter the following error message:

"No hosted parallelism has been purchased or granted. To request a free parallelism grant, please fill out the following form:"

You have two options:

  1. Fill out the form at the provided URL and wait for Microsoft to grant parallelism.
  2. Download and install an agent on your local machine.

Step 3: Establish a service connection to your Azure Subscription

To link Azure DevOps with your Azure subscription for deployment, follow these steps:

  • Navigate to Project Settings and select Service connections.
  • Create a new service connection, choosing "Azure Resource Manager" from the list.
  • Select the default Service Principal (automatic) and follow the prompts to establish the connection.

Step 4: Create a build pipeline

Follow these steps to create a build pipeline:

  • Click the "New pipeline" button.
  • Under "Where is your code?", select "Use the classic editor to create a pipeline without YAML" at the bottom.
  • Choose the "ASP.NET Core" template (or select the starter pipeline if you prefer YAML).
  • Edit the pipeline to use the self-hosted agent (Default pool) instead of the Azure-hosted agent to avoid the parallelism error.

Step 5: Create a release pipeline

To create a release pipeline, follow these steps:

  • Go to "Releases" and select the "Azure App Service Deployment" template.
  • Once you have the basic pipeline in place, configure it to be automatically triggered by a successful build.

Remember to update the pool and agent settings for the release pipeline as well.

Step 6: Configure continuous integration 

To trigger the entire process above automatically after new code is pushed to the repo:

By following these steps, you'll be able to streamline your deployment process using Azure DevOps. With a few configurations and pipelines, you can automate the deployment of your web app to Azure App Service seamlessly.

You should also read:

Azure Key Vault Pt.1

As you learn to use IaC and Terraform, it is natural to progress from initially supplying credentials for a resource in the…

Azure Hybrid Connect

Background: The organization I work for needed to move over 100 internally hosted apps to Azure's web app hosting functionality due to soon-to-be…