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:
- CI/CD Workflow: Developers push code changes to a repository (Azure Repos Git or GitHub), triggering pipeline runs that build, test, and deploy the application.
- YAML Pipeline-as-Code: Pipeline definitions are typically stored as
azure-pipelines.ymlin your repo, enabling version-controlled, code-reviewed build/deployment processes. - Azure Integration: Out-of-the-box integration with Azure Repos for source control, Azure Container Registry (ACR) for container images, and Azure Kubernetes Service (AKS) for deployments.
- Hosted Agents: Microsoft-hosted build agents on Windows, Linux, and macOS run your pipeline tasks. You specify an agent VM image (like
ubuntu-latest) in the pipeline config. - Common Workloads: Frequently used with .NET applications and containerized workloads. For example, you can compile and test a .NET project, build a Docker image, push it to ACR, and deploy to AKS – all in one pipeline.
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:
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.
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).
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.
Review the Generated Pipeline YAML – Azure DevOps will analyze your selections and generate an
azure-pipelines.ymlin your repo. This YAML defines your CI/CD pipeline:
- It typically includes a trigger on your main branch (so pushes trigger CI builds).
- It defines stages for Build (CI) and Deploy (CD).
- In the Build stage, you'll see steps to build and possibly test your application. For containerized .NET apps, the build might be done via a Docker task. If using a pure .NET template, you'd see tasks like
DotNetCoreCLI@2to restore, build, and test the project. - For example, the pipeline uses the Docker@2 task to build and push a Docker image to ACR:
# ... (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)
- task: KubernetesManifest@1
displayName: Deploy to AKS
inputs:
action: deploy
kubernetesServiceConnection:
manifests: | manifests/deployment.yml manifests/service.yml containers: $(ACR_LOGIN_SERVER)/${{ variables.imageName }}:$(Build.BuildId)
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.
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>:8080should 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.