This project demonstrates the setup of a Continuous Integration and Continuous Deployment (CI/CD) pipeline using Azure DevOps for a sample application. This pipeline automates the build, testing, and deployment stages, and deploys to either Azure App Service or Azure Kubernetes Service (AKS).
- Configure the CI pipeline in Azure DevOps to build the application, run unit tests, and create artifacts.
- Set up the CD pipeline to deploy artifacts to Azure App Service or Azure Kubernetes Service based on chosen environment.
- Demonstrate the steps to deploy to either Azure App Service (for web applications) or AKS (for containerized applications).
- Azure DevOps account
- Azure subscription with permission to deploy to Azure resources
- Git repository containing the sample application code
- Basic knowledge of YAML for pipeline configuration
-
Create a New Project in Azure DevOps:
- Go to Azure DevOps, create a new project, and link it to your Git repository.
-
Define CI Pipeline (YAML):
- Create a YAML file (
azure-pipelines.yml
) in the root directory of your repository for the CI configuration. - Below is a sample CI configuration:
trigger: branches: include: - main pool: vmImage: 'ubuntu-latest' steps: - task: UseDotNet@2 inputs: packageType: 'sdk' version: '6.x' - script: dotnet build displayName: 'Build Solution' - script: dotnet test --collect:"XPlat Code Coverage" displayName: 'Run Unit Tests' - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop'
- Create a YAML file (
-
Run the CI Pipeline:
- Commit and push the
azure-pipelines.yml
file to trigger the build process, which will run the defined steps, including building and testing the application.
- Commit and push the
-
Create a Release Pipeline:
- In Azure DevOps, go to Pipelines > Releases and create a new release pipeline.
- Choose the artifact generated by the CI pipeline as the source.
-
Define Stages for Deployment:
- Azure App Service: Add an Azure App Service Deploy task to deploy the web application.
- Azure Kubernetes Service (AKS): Add a Kubectl apply task to deploy containers to AKS.
-
Sample YAML for AKS Deployment:
- stage: Deploy jobs: - deployment: DeployToAKS environment: 'aks' pool: vmImage: 'ubuntu-latest' steps: - task: Kubernetes@1 inputs: connectionType: 'Azure Resource Manager' azureSubscription: '<Azure Subscription>' azureResourceGroup: '<Resource Group>' kubernetesCluster: '<AKS Cluster Name>' namespace: default command: apply arguments: '-f k8s/deployment.yaml'
-
Configure Release Triggers:
- Set up Continuous Deployment Trigger in the Release pipeline to automatically deploy artifacts from the build pipeline.
Deployment Options
Option 1: Deploy to Azure App Service
- Use the Azure App Service Deploy task in the release pipeline to deploy a web application to Azure App Service.
Option 2: Deploy to Azure Kubernetes Service (AKS)
- For containerized applications, configure the pipeline to deploy to AKS by applying the Kubernetes configuration files (e.g., deployment.yaml, service.yaml).
Summary of the Pipeline Workflow
-
Code Commit : Push code to the repository.
-
CI Pipeline : Triggers on each commit, building the application, running tests, and publishing artifacts.
-
CD Pipeline : Deploys the latest build to the chosen Azure service (App Service or AKS) automatically.
Contributing : Feel free to submit issues or pull requests to suggest improvements or additional features.
License : This project is licensed under the MIT License.