Create CI/CD Pipeline for ASP.NET Core Web API by using Azure DevOps Starter

Yohan Malshika
5 min readJul 24, 2020

Hi all, Hope you all are doing well!. I would like to talk about how to deploy ASP.NET Core CRUD API by use Azure CI/CD pipeline. So First I plan to show, how to deploy ASP.NET Core Web API by use Azure CI/CD pipeline.

Create CI/CD Pipeline for ASP.NET Core Web API by using Azure DevOps Starter

Before all of this work, you should have installed Visual Studio 2019 Community with ASP.NET Core environment, install the Postman, create GitHub Account, Set up Git and Free Azure Account.

In this article, I will tell you,

  1. Create ASP.NET Core Web API
  2. What is CI/CD
  3. Deploy the API to AZURE

Let’s get started!

Create ASP.NET Core Web API

Open the visual studio and create a new project and select ASP.NET CORE Web Application, and add the project name and then select “API” as the web application type, then create this application.

Now we created our ASP.NET Web API application and got the directory structure with these pre-created files for the Web API template. So you can see directory structure from below picture and There is a pre-created controller called WeatherForeacastController and one model class called WeatherForecast.

Project Directory Structure

Now we can check it by use postman in the localhost server because it has created pre-created files. So you will get your API result as below picture.

API Testing in localhost using postman

Before we deploy the API, we have to push this project files into GitHub. Because I use existing projects that trying to get it from GitHub to create the Azure CI/CD pipeline to deploy it.

Now we have to create a repository for this and push our commits to GitHub. Then we can use it for deploying the Web API to Azure.

Now we have to configure Azure CI/CD pipeline of deploy the ASP.NET Core Web API project.

What is CI/CD ?

Following definition from the InfoWorld.

Continuous integration (CI) and continuous delivery (CD) embody a culture, set of operating principles, and collection of practices that enable application development teams to deliver code changes more frequently and reliably. The implementation is also known as the CI/CD pipeline.

CI/CD is one of the best practices for DevOps teams to implement. It is also an agile methodology best practice, as it enables software development teams to focus on meeting business requirements, code quality, and security because deployment steps are automated.

CI/CD helps teams to be more productive when shipping software with quality built in.

Deploy ASP.NET Core Web API to Azure.

let’s start to deploy our created web API by use Azure CI/CD Pipeline. To deploy the our Web API application to Azure, first, we need Azure account, if you don’t have an Azure account, you have to create free Azure account first.

After create your azure account, first we have to go to the Azure portal.

Then you have select DevOps starter. We create CI/CD pipeline by using DevOps Starter in Azure DevOps.

Select DevOps Starter

You can see the “Add” button after you go Azure DevOps Starter. You have to click it to start to create or add our existing project to Azure.

Then you can see it like this. If you are creating new application, you can create it by selecting its environment.By the way, I use an existing project from GitHub. So I select “Bring your own code” card.

DevOps Starter

Then you have to get an existing project from GitHub.for that, you have to connect with your GitHub account and then select your project with a necessary branch from GitHub.

Then if your app is dockerized, select it as yes and select a runtime environment for your app, and select the framework you used. My app is not dockerized and I use .Net runtime environment and ASP.NET Core framework.

Select runtime Environment for API

Then select Azure service to deploy the application. And I selected Windows Web App for my project.

Then configure the Azure DevOps and Azure Subscription. When you configure the Azure DevOps, you have to enter project name and select your existing Azure DevOps organization or also you can create new Azure DevOps organization.

Configure Azure service

After configuring the project on Azure DevOps, you can see the Deployment overview and then select Go to Resource to view the DevOps starter dashboard. Then you can see it like below picture.

DevOps starter Dashboard for API Project

So this dashboard provides visibility of our project code and repository and also our CI/CD pipeline for the App in Azure and it’s status.

After succeeded it, we can check our API by using Postman.

Test Deployed API using postman

As we can see, now we are able to get the correct result from our Web API in Azure, and we deployed our .NET CORE Web API to Azure successfully!

Also, You can do small changes to your Web API project and then commit it to GitHub. Then you can see, changes you made are automatically built and deployed through a CI/CD pipeline.

So That’s it for today and I think you learned something new from my article. I hope to meet you guys with second part of this article.

Happy Coding & Good Luck All!

--

--