Create a CI/CD pipeline in Microsoft Azure DevOps for the .NET project
Tags: programming, tutorial, azure, devops
Published: 2022-05-15 17:49:45

**<u>Pre-requisites:</u>**

1. Microsoft Azure Account: If you do not have an active account, sign-up here: [Sign-up](https://azure.microsoft.com/en-us/free/)


2. Visual Studio Dev Essentials: If you do not have Visual Studio subscription, check this out: [Visual Studio](https://visualstudio.microsoft.com/dev-essentials/)



Let's get started. 



**<u>What is DevOps Starter?</u>**


DevOps Starter makes it easy to get started on Azure using either GitHub actions or Azure DevOps. It helps you launch your favorite app on the Azure service of your choice in just a few quick steps from the Azure portal.

DevOps Starter sets up everything you need for developing, deploying, and monitoring your application. You can use the DevOps Starter dashboard to monitor code commits, builds, and deployments, all from a single view in the Azure portal.


**<u>What are the advantages of DevOps Starter?</u>**

DevOps starter the following supports 2 CI/CD providers, to automate your deployments:

1) GitHub Actions
2) Azure DevOps

DevOps Starter automates the setup of an entire continuous integration (CI) and continuous delivery (CD) for your application to Azure. You can start with existing code or use one of the provided sample applications. Then you can quickly deploy that application to various Azure services such as Virtual Machines, App Service, Azure Kubernetes Services (AKS), Azure SQL Database, and Azure Service Fabric.

DevOps Starter does all the work for the initial configuration of a DevOps pipeline including everything from setting up the initial Git repository, configuring the CI/CD pipeline, creating an Application Insights resource for monitoring, and providing a single view of the entire solution with the creation of a DevOps Starter dashboard in the Azure portal.

Key benefits of using DevOps Starter:

- Quickly deploy your application to Azure.
- Automate the setup of a CI/CD workflow or pipeline.
- View and understand how to properly set up a CI/CD workflow or pipeline.
- Further customize the release pipelines based on your specific scenarios.



**<u>What is CI/CD pipeline and what is the purpose of CI/CD pipeline?</u>**


A CI/CD pipeline automates your software delivery process. The pipeline builds code, runs tests (CI), and safely deploys a new version of the application (CD). Automated pipelines remove manual errors, provide standardized feedback loops to developers, and enable fast product iterations.



**<u>Step 1:</u>** 


Set up a sample ASP.NET project using DevOps Starter project

- Sign into the Microsoft Azure portal: [https://portal.azure.com/](https://portal.azure.com/)

- In the search box, type DevOps and select DevOps Starter. Then click on Create DevOps Starter.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dklvmxyc6981q74ctp8.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sawh2dxmb6jc6e7xl8t0.png)


- By default, DevOps Starter project setup with GitHub. Click on change settings to change the destination to Azure DevOps and click Done.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rmmjqcikza7sq7qyk94.png)


- Select the .NET sample application and click Next.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6mf907rxjijfd0lbae0p.png)


- The .NET samples include a choice of either the open source ASP.NET framework or the cross-platform .NET Core framework. Select the .NET Core application framework. This is an ASP.NET Core MVC application. Enable Add a database toggle to add the database to the application. When you’re done, choose Next.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z478ib39bm27imsc19zi.png)


- Web App on Windows is the default deployment target. We can optionally choose Virtual Machine. Click Next.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcg88efn69ujwwnh612v.png)


- Select your Azure DevOps organization and choose a name for your project and Web app. Click Review + Create.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yglr76u2wi6c1dcude1.png)


- Click on Additional Settings if you would like to edit web app and database parameters.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgsrpbqiyujsj4gutlg6.png)


- Click Go to resource.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xruabms8b2lj2npjs9aa.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/movnp2xb9408ur891yy2.png)


- We can now work on ASP.NET Core app with a CI/CD process that automatically deploys our latest work to our web site. On the right side of the dashboard, select Browse to view our running application.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8jkskdoow66ydcptsgh.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c97zg5zqna9g0cmxydqy.png)


**<u>Step 2:</u>**



Let's check and validate CI/CD pipelines configuration for the Azure DevOps project.


- Select Build Pipelines from the top of the Azure DevOps project dashboard. This link opens a browser tab and the Azure DevOps build pipeline.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4o56oks9244huvo8ix7j.png)

- Click on Edit.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vw9az7ntyb92gll1j4ut.png)

- This build pipeline performs various tasks such as fetching sources from the Git repository, restoring dependencies, compile the application, run tests and publishing outputs used for deployments.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lm4yfmtfv4w9aqn3biw1.png)



- Go to pipeline name, select History. We can see an audit trail of our recent changes for the build. Azure DevOps keeps track of any changes made to the build definition and allows us to compare versions.


- Select Triggers. The Azure DevOps project automatically created a CI trigger and every commit to the repository initiates a new build.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5posm7aafbbninevi0t.png)


- Click Releases under Pipelines section.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzhascj2m2zr4xan3fme.png)


- Now select the release pipeline. Click Edit.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhzdj4a1786456miow3g.png)


- Under Artifacts, select Drop.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5u7r8p0dy2t1htkyaby.png)


- To the right-hand side of the Drop icon, select the Continuous deployment trigger. This release pipeline has an enabled CD trigger, which executes a deployment every time there is a new build artifact available. Disable this trigger, when our deployments require manual execution.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xw3ft2333nxyklblj3vl.png)


- Select Tasks. The tasks are the activities your deployment process performs.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3c9oyucsq1j49h1fnrcp.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgw0af6veicqe2oryncc.png)


- On the right-hand side of the browser, select View releases.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glcgqgymeue8to02anhi.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wq0cvfpi01cqlvd8lzf.png)

- Now click on the release number.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7brw0n5k6isc7onpc8a.png)


- Click Logs. The logs contain information about the deployment process.



**<u>Step 3:</u>**



Write code. Commit & Push the code changes and execute CI/CD.



- Click on Repos to view the created Git repository by Azure DevOps project.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i0opjkcna3y4x3dhm4pz.png)

- To view the repository, first clone URL by selecting Clone from the top right of the browser.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3348h4v601xmcym25fe4.png)


- Go to left-hand side of the browser, navigate to the Application/aspnet-core-dotnet-core/Pages/Index.cshtml file. Select Edit, and make a change.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/folcpd15wlwc3ludw72l.png)


- Make some changes and commit the code.


- Go to Pipelines. Notice, build is in progress. The changes are automatically built and deployed via Azure DevOps CI/CD pipelines.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4ckslu51b9etnnwzy42.png)


- Once the Build and Release are completed in your browser, navigate to the Azure DevOps project dashboard. On the right side of the dashboard, select Browse to view your updated running application.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n34nyxofm9ev7f5yzcuk.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoge1cx13psnq500f0ch.png)




**<u>Conclusion:</u>**


In this blog we have learned how we can set up a CI/CD pipeline for the sample .NET project in Microsoft Azure DevOps with step by step guide. Hope it helps someone out there. Thank you.