DEV Community

Pranam K
Pranam K

Posted on

Create a CI/CD pipeline in Microsoft Azure DevOps for the .NET project

Pre-requisites:

  1. Microsoft Azure Account: If you do not have an active account, sign-up here: Sign-up

  2. Visual Studio Dev Essentials: If you do not have Visual Studio subscription, check this out: Visual Studio

Let's get started.

What is DevOps Starter?

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.

What are the advantages of DevOps Starter?

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.

What is CI/CD pipeline and what is the purpose of CI/CD pipeline?

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.

Step 1:

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

  • Sign into the Microsoft Azure portal: https://portal.azure.com/

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

Image description

Image description

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

Image description

  • Select the .NET sample application and click Next.

Image description

  • 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

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

Image description

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

Image description

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

Image description

  • Click Go to resource.

Image description

Image description

  • 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

Image description

Step 2:

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

  • Click on Edit.

Image description

  • 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

  • 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

  • Click Releases under Pipelines section.

Image description

  • Now select the release pipeline. Click Edit.

Image description

  • Under Artifacts, select Drop.

Image description

  • 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

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

Image description

Image description

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

Image description

Image description

  • Now click on the release number.

Image description

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

Step 3:

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

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

Image description

  • 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

  • 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

  • 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

Image description

Conclusion:

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.

Top comments (0)