Building CI/CD Pipeline with the Azure DevOps

23 Aug 2022
Intermediate
26.5K Views
7 min read  

Azure DevOps Pipelines provide you the option to do your CI builds for any platform and any tool or language. Azure DevOps Pipelines provides a web interface where you can create jobs that contain steps that need to take place to create a production artifact for your software. The build automation pipelines allow you to trigger from any external repository like GitHub, SVN, or your local Git server or Azure DevOps repositories. The triggers will then fire the build according to the definition you created. Besides, Azure DevOps also provides the following options for automation

  • Build automation

  • Deployment automation

You can very easily deploy your application to Google Cloud, AWS, Azure Cloud or on your on-premises services in many ways. When you use the whole suite of Azure DevOps, so you use the boards to track the work, the repos to track the work, the version control system, and when you also use the build and release tools, you will get full traceability out of the box. This is great for compliance. If you prefer to use other tools, you can all plug them into the integration points that are available.

What is CI/CD?

Continuous integration and continuous delivery (CI/CD) is backbone of DevOps. It helps fast software development and deployment to enable continuous delivery of value to end users by achieving incremental software delivery. Continuous integration (i.e. CI) is an automated way to build, package, and test the applications. These builds are passed as inputs to the CD pipeline.

Figure 1. CI/CD Pipelines

Continuous delivery (i.e. CD) automates the delivery of applications to selected infrastructure environments like development, UAT, production. With Azure DevOps, you deploy any software on any platform.

Steps to create CI/CD pipeline

Let us see the steps to implement build automation and deployment automation with Azure DevOps Pipelines.

Create Your Azure DevOps Organization

The first step is to navigate to https://dev.azure.com and sign-in to Azure DevOps. You need to create at least an organization to store your projects, your repositories.

Figure 2. Create an Azure Organization

Please visit Microsoft’s documentation for more advance organization scenarios.

Create a Project

Please create an Azure DevOps project by selecting values like visibility, source control etc.

Figure 3. Create an Azure DevOps Project

Create a Build Pipeline

Figure 4. Sample .Net Core App running on localhost

I have created a sample .net core app and its running on my machine. Now I want to set up a CI-CD pipeline for this application using Azure DevOps. Please select build option from pipeline menu to set up build pipeline.

Figure 5. Set up a build pipeline

Now choose a build template provided by Azure DevOps as shown below.

Figure 6. Choose build template

I can also select the TFVC version control system or GitHub if I want to as source code. Now give a name to build definition. Please select an appropriate solution file to build & location to save build artifacts. These artifacts will be used as input to release pipeline. You can see which artifacts. Azure DevOps provides multiple predefined templates to build application developed in java, node.js, Php etc.

Figure 7. Queue a build
Figure 7. Build Completed

Create a Release Pipeline

Now once build succeeded, we need to create release definition. You can select release menu from the pipeline or click on the release button as shown below. When you get into the release pipeline screen, you’ll need to select a template.

Figure 8. Create Release Pipeline

Azure DevOps has provided a lot of predefined templates for deployment. Some of them are as follows

  1. Azure App Service Deployment with Test and without Test

  2. Azure App Service Deployment with continuous monitoring

  3. Cloud Service Deployment

  4. On-Premise deployment

  5. Azure VM Scale Set

  6. Service Fabric (Stateful/ stateless)

  7. Azure Policy deployment

  8. Function App to Azure

We can create our own custom template as well as per our requirement.

Figure 9. Choose Release Template

After selecting the template, we can add task so that we can deploy a build multiple environments like dev, test, UAT etc. We can add particular use as a release approver as well. We can set the variable values which are used in the release definition. You can convert those templates to YAML in a later stage as well and then check in version control if you want. You see that there are all kinds of pre-defined templates to do your builds. So for example, a Gradle build or a Go build, or you want to do some load testing, or you want to do Xamarin app for iOS, Ant builds, you name it; it's all there and part of the out-of-the-box experience. Azure DevOps has things like NuGet restore, Test Assemblies, Build the solution, all kinds of things that we can pick from the task picker.

Figure 10. Add tasks to Release Definition

After saving the release definition, you can create a new release. You can choose environments for release if you have added multiple release tasks.

Figure 11. Create New Release

After creating a release, we can track release progress as shown below.

Figure 12. Check Release Progress

We can enable pre-deployment approvals as shown below. Now, what happens when I did a deployment and the deployment failed? Well, I can select to re-deploy the previous well-known stable deployment so I'm always in a good state again, which is quite handy. So that's a way we can define those post approvals before we move to the next phase in our deployment.

Figure 13. Enable Pre-Approval for Deployment

Pipeline History

We can also look at the history where we can track the changes that are made to the release definition, which is also very handy if it comes to compliance and security. Now we can clone those different environments, because after and you want to do the same in let's say dev, as in staging as in test or production. We have different triggers here and one of the triggers is that we wanted to have continuous integration. So every time, changes in our Git repo, I want to trigger build/Release pipeline. We can also schedule things in Azure DevOps.

Figure 14. Schedule Release

After successful completion of a release pipeline, you can visit the deployed version of your application.

Figure 15. An application running on Azure
Summary

Azure Pipeline is a cloud-hosted pipeline for fast CI/CD that works with any language, platform, and cloud. By connecting to any source control like GitHub, this service can release changes continuously to any cloud. YAML files are very useful in writing build and release definitions. Azure Pipelines has components like build, release, library, task groups, deployment groups. Azure Pipelines has advance workflows with native container support and features which allow monitoring CI/CD stages.

About Author
Ketan Agnihotri (MCSE, Consultant)

Ketan has over 6.6 years of experience in software development. He has delivered quality work in Media, Real-Estate, Travel, Social Media, Automobile industries. He is capable of managing multiple projects on strict timelines. Ketan has done the bachelor of engineering in information technology from Pune University, Maharashtra-India. Ketan is MCSE (Microsoft Certified Solutions Expert) and working as Consultant in the information technology and services industry. 

Ketan is a team-oriented & ambitious software professional with a successful track record of delivering performance-driven B2B and B2C apps. His skills are Azure, AWS, Asp.Net MVC, C#, CSS3, ReactJs, HTML, Jquery, Javascript, SQL, Software architecture and designing.

Learn to Crack Your Technical Interview

Accept cookies & close this