Azure DevOps Pipelines – Setup and CI/CD Guide for .NET and AKS | FOSSA Guides

Azure DevOps Pipelines – Setup and CI/CD Guide for .NET and AKS

Technical guide to setting up Azure DevOps Pipelines for .NET applications and container deployments to AKS, with Azure Repos, Azure Container Registry integration, and FOSSA for compliance scanning.

March 25, 2025

Contents

Azure DevOps Pipelines – Setup & CI/CD Tutorial

About Azure Pipelines

Azure Pipelines is a cloud service for automating builds, tests, and deployments of code projects as part of Continuous Integration and Continuous Delivery (CI/CD). It's a core service of Azure DevOps that supports many languages and platforms (e.g. .NET, Node, Python) and integrates natively with Azure services. Key points include:

Azure Pipelines Setup Guide – Azure DevOps CI/CD Tutorial

Follow this guide to set up Azure Pipelines from initial project creation to your first successful CI/CD pipeline execution. We'll focus on a typical use case: building a .NET application, containerizing it, and deploying to Azure Kubernetes Service, using Azure Repos for source code and ACR for the container image.

Prerequisites: You should have an Azure DevOps organization and project (sign up free if needed), and an Azure subscription for deploying resources. Also ensure you have an Azure Container Registry and an AKS cluster created (for example, via Azure CLI commands).

Steps:

  1. Create or Select an Azure DevOps Project – Sign in to Azure DevOps and create a new project or use an existing one. Projects are logical containers for your code repos and pipelines.

  2. Import Code into Azure Repos – Push or import your application's code into an Azure Repos Git repository within the project. You can do this via Git commands or the Azure DevOps web interface (e.g. initialize a repo and upload files in the Repos section).

  3. Create a New Pipeline – In Azure DevOps, go to Pipelines > Pipelines and click New Pipeline. The pipeline creation wizard will prompt you to select your source code repository and pipeline type:

    • Choose Azure Repos Git and select your repository (if asked to select a source).
    • For pipeline configuration, select a template. For example, choose "Deploy to Azure Kubernetes Service" if you want a full CI/CD pipeline for AKS. Alternatively, you can start with ".NET Desktop/ASP.NET Core" templates for simpler build/test pipelines.
    • If using the AKS template, you'll be prompted to select your Azure Subscription, AKS cluster, ACR, etc. Provide the requested info (cluster name, namespace, registry, image name, etc.). Azure Pipelines will automatically create a service connection for ACR and AKS if needed.
  4. Review the Generated Pipeline YAML – Azure DevOps will analyze your selections and generate an azure-pipelines.yml in your repo. This YAML defines your CI/CD pipeline:

     # ... (within Build stage job steps)
- task: Docker@2
  displayName: Build and push Docker image to ACR
  inputs:
      command: buildAndPush
      repository: <your ACR name>.azurecr.io/${{ variables.imageName }}
      dockerfile: ${{ variables.dockerfilePath }}
      containerRegistry: ${{ variables.dockerRegistryServiceConnection }}
      tags: |
        $(Build.BuildId)
     ```

- In the **Deploy stage**, the YAML will use Kubernetes deployment tasks to release the app to AKS. For example, Azure Pipelines can apply the Kubernetes manifest files:
 # ... (within Deploy stage job steps)
  1. Save and Run the Pipeline – Commit the YAML file to your repo (the wizard usually does this with a commit message like "Add pipeline to our repository" when you click Save and run). This triggers the first pipeline run. You can follow the pipeline's progress in the Azure DevOps Pipelines UI:

    • The pipeline will queue on a hosted agent. In real-time, you can see logs for each step (e.g. restoring packages, building the app, running tests, building the Docker image, pushing to ACR, deploying to AKS).
    • The Build stage should complete (green check mark), then the Deploy stage will execute. Azure Pipelines shows each stage and job transitioning from running (blue) to successful (green).
    • If anything fails (red X), examine the log output in that step to diagnose (common issues include missing Azure service connections or misconfigured YAML). Fix the YAML or environment and commit again to re-run.
  2. Verify Deployment – Once the pipeline finishes, verify that your application is deployed:

    • In Azure DevOps, go to the Environments or the pipeline run summary to find the deployment details (for AKS deployments, Azure Pipelines registers an environment that you can view under Environments tab, showing the Kubernetes cluster and namespace).
    • For our example, you can check the AKS cluster to see if the application pods are running. Use kubectl get pods (if you have Kubeconfig access) or navigate to Azure Portal > AKS > Workloads.
    • If a service with a LoadBalancer was deployed, get its external IP and try to access the app (e.g. via web browser for a web app). For instance, hitting <EXTERNAL-IP>:8080 should show "Hello world" for the sample app.

By following these steps, you will set up a functioning CI/CD pipeline using Azure DevOps that manages the entire cycle of code deployment, from commit to live application.