A simple CI/CD pipeline in Azure Devops

rajath venkatesh
6 min readJul 6, 2021

I will be taking you through on an adventure of how you can start up with a simple project locally and put your changes into Azure devops. This would trigger a CI pipeline and would deploy the same into an App Service using a CD release once the CI pipeline generates your artifacts.

Perquisites

  • Azure account with an active subscription.
  • Azure devops organisation and a project within it.
  • Git installed on your local system and since I am familiar with Microsoft frameworks, I will be using a simple scaffolded .NET core web app.
show time!

Local Development environment

I have git installed locally, the setup is simple for both windows as well as mac users.

git version installed

I have created a scaffolded .NET core web app which comes out of the box using visual studio you can see from the project folder path below, git is not setup in this project.

.NET Core Web App Project
Project folder without git

Once git is installed navigate over to the root folder of your project and initialise git, this will create your .git folder which contains all information about your local branches, commits, remote repository address, etc.

Project folder with git initialised

Create a new organisation and a new project in azure devops (choose whatever you like as the work item process in advanced option or leave it as it is, we do not use azure boards here, also choose git as your source control since we will be using azure repos), click on the project which takes you into the project with all your boards, repos, pipelines, test plans and artifacts menus.

Organisation and Project in Azure devops

Click on repos and you will see Push an existing repository from command line copy the commands from there and head over to your local environment terminal, change directory to the project root folder (.git folder exists at this level).

Azure repos

Run the first command copied from azure devops, this creates a new remote repo called origin.

git remote add origin *remoterepourl*

Next create a new branch by the name develop and add all the files from your project folder onto the local git branch using the below commands.

git checkout and git add

Then commit your changes with a message and push all your changes onto the remote repository in Azure devops.

git commit
git push

Hurray! Your develop branch is setup.

develop branch

Azure App Service Setup (Azure Webapp)

In the Azure portal home screen click on create a resource, which takes you to the Azure marketplace, click on web app here.

Azure marketplace

Give your web app a unique name, choose your run time stack. Since mine is a .Net Core 3.1 app, I will choose that and also choose an App service plan of type basic, I will switch off the Application Insights as I don’t need it here.

Create a Web app

Once the resource is created head over to the web app and browse to the web app url.

Web app

CI Pipeline

In Azure devops click on the Pipelines menu and then create a new pipeline.

Create a CI pipeline

While creating the pipeline you can either choose the old classic editor or the new yaml editor, I will use Azure Repos Git with the Yaml editor.

The classic or new editor dilemma!

Select the repository you want to build a CI pipeline for, my repository name is ASPNETCOREdemo.

select your repo

In the configure section, I will go ahead and select the ASP.NET Core existing Yaml template.

Yaml template for .NET Core

When you review your ASP.NET Core yaml template, please add the publish artifacts task in the YAML file (use the show assistant if necessary), this will be used to deploy the artifacts into our web app.

using the YAML task assistant to add publish build artifacts task
Yaml template for .NET Core with publish build artifacts

Click on save and run to run your CI pipeline. (if you get a commit message give a suitable name and click on save and run).

Bravo! Your CI pipeline is ready and ran successfully.

CI build pipeline works!

CD Release Pipeline

In Azure devops click on the Pipelines menu and then on Releases sub menu create a new release pipeline.

new release pipeline

Once you click on new release pipeline you get a template to choose from since we are deploying to Azure app service, I will choose that and click on apply.

Select your deployment environment

I will add the artifact generated from our CI pipeline build by clicking on add artifact.

Add CI build to release

Once this is done I will go ahead and enable the continuous deployment trigger, click on the thunder icon and enable it (it is disabled by default).

Enable CD trigger

Once you create a stage you go ahead click on the task. This opens up Deploy to Azure App service task.

Add your App service

Here you need to provide your azure subscription and if you do not have a existing service principal (which will be used to deploy from Azure devops to your App Service) it will be created for you. Just click on the authorize button, this will ask you to sign into Azure again.

Create a service principal to authenticate to your App service

Once the service principal is created you can select your App service and go back to your pipeline.

Select your app and move to pipelines

Save the pipeline and click on create release.

Save and create release

After a while, if you navigate to your web app url you can see the .NET Core app deployed from Azure devops. Sweet!

.NET Core Azure Web app

I am going to now push my code from my local environment with a change, you can watch as the CI and CD pipelines run and deploy the changes to the Azure Web app.

complete cycle!

Note : In the real world, you won’t be allowed to push changes this way and will have to create peer reviews which are to be approved by other folks in your team.

--

--