Menu Close

Building CI/CD Pipeline using Azure DevOps- Part 1

Building CICD Pipeline using Azure DevOps

In this article we will learn about Building CI/CD Pipeline using Azure DevOps. One of the goals of DevOps is to provide faster and reliable releases. In this regard, the terms Continuous Integration and Continuous Deployment have become very popular. Continuous Integration (CI) is a software development practice that requires developers working on the project to integrate code into a shared repository. For the CI process to be a success, the build, unit tests, integration tests, acceptance tests should be successful. Please read my all Azure article here.

What is Azure DevOps?

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

DevOps Projects 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 Projects dashboard in the Azure portal.

What is CI/CD?

Continuous integration and continuous deployment (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 (CI) is an automated way to build, package, and test the applications. These builds are passed as inputs to the CD pipeline.

azure-devops-ci-cd-architecture
Image source from : Microsoft

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.

CICD-Pipelines

Creating CI/CD pipeline

Below are the steps to implement build automation and deployment automation with Azure DevOps Pipelines.

  • Here I have logged in through GitHub, you can start signup free with putting some basic information. Azure DevOps is free to start.
Azure Devops Signup
Azure DevOps Signup form

Creating New Organization

  • After logging into Azure DevOps, our next step is creating New Organization. The Organization can holds many projects and repositories.
  • Like on the below image [Fig-1] , click into the Organization.
  • It move to the next window [Fig-2], click continue.
  • Then, include the Organization’s name [Fig-3], which should be unique. If already with same name the organization are available it ask to give proper name.
  • Set the Project location name [Fig-3], here we set as south India as it is neared to us and give captcha then click continue.
  • On [Fig-4] you can see it creating the organization.
Azure DevOps- New Organization
[Fig-1] Create the new Organization
Azure DevOps- New Organization Confirmation
[Fig-2]
Azure DevOps- New Organization confirmation done
[Fig-3] Set Organization Name
Azure DevOps- New Organization confirmed and creation success
[Fig-4]

Creating an Azure DevOps Project

  • After creation of the Organization, you can see on the highlighted arrow we click for create the project.
Azure DevOps New Project
[Fig-5] New Project

  • Here we need to set the Project name, the name according to your choice.
  • Make the project visibility as Private, we don’t want to share the repositories to public and then click to Create Project.
Azure DevOps Creation of the Project
[Fig-6] Creation Of Project
  • The Project creation is done, on the [Fig-7] you can see we have the Organization is JT-Dev1 and the project name is azure-devops-demo.
Azure DevOps- New project creation
[Fig-7]

Building CI/CD Pipeline using Azure DevOps

Creating ASP.Net Core Project and Push the file into Azure DevOps

Let’s create a ASP.Net Core MVC Project using below steps

  • Open Visual Studio and Click create New Prokect.
  • Choose template as ASP.Net Core MVC and then give project name, it will create the sample ASP.Net Core project for us. Run the application and you can see now it ran in localhost.

ASP.Net Core application
[Fig-8]

Push the Code into Azure Devops

Our next step is pushing the created .NET Core App code into Azure DevOps.

  • Go to Repos -> Files, you can see highlight git origin, copy the path we can use it in below.
Azure DevOps- adding source files
[Fig-9]

Use the below git command we can add the files into Azure DevOps

  • Initialize the git command, To create a new repo, you’ll use the git init command. git init is a one-time command you use during the initial setup of a new repo.
git init

  • The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.
git add .

  • git commit –aCommit a snapshot of all changes in the working directory. This only includes modifications to tracked files (those that have been added with git add at some point in their history). git commit -m “commit message” A shortcut command that immediately creates a commit with a passed commit message.
git commit -m "initial load"

Push the code to repository from the command line

Use the earlier copy command to add the code into repo.

git remote add origin https://[email protected]/JT-Dev1/azure-devops-demo/_git/azure-devops-demo

And make finial push using below command

git push -u origin --all

Azure DevOps- code push into origin
[Fig-10]

Now we can see the code has been pushed to master branch and we can see the our files are available in Repos->Files

Azure DevOps- code pushed confirmed to Azure DevOps
[Fig-11]

Creating CI/CD Pipeline

  • Now we are in the project section. On the left go to Pipelines -> select pipelines
Azure DevOps- Click Pipelines
[Fig-12]
  • It opened up the new window, and click on the create pipeline button.
Azure DevOps- Create new Pipelines
[Fig-13]
  • Now you can see the below template where we can create pipelines; this window asked where our code is, whether it is from Azure repositories or another source, but it still needs to write the YAML files. While we are creating the basic pipeline, click the highlighted link of Use Classics Editor to help create the pipeline without a YAML file.
Azure DevOps- Create new Pipelines- choose classic editor
[Fig-14] Use Classic Editor

  • Then it navigate to below page to select the repository. There is different options to choose the source.
  • We have the code with Azure Repos Git so we checked it and for our case the Team project and repository is azure-devops-demo and the branch is targeting to master. Click continue
Azure DevOps- Create new Pipelines - Select Azure Repos Git
[Fig-15] Repository

  • On the below image you can see the new templates come up, here we can choose a template that builds kind of the app. We can customize it later.
  • Choose .NET Core and on below you can highlight the ASP.NET Core template and then Apply it.
Azure DevOps- Create new Pipelines- Choose ASP.Net Core Template
[Fig-16] Choose ASP.NET Core template

  • Agent : To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you’ll eventually need more. When your pipeline runs, the system begins one or more jobs. An agent is installable software that runs one job at a time.
    1. This screen is final configuration of pipelines. Here you can see the Agent name is Agent Job 1, later I renamed it to JT-Agent-1.
    2. This Agent contains the steps: Restore, Build, Test, Publish and then publish Artifact.
    3. The build pipeline performs the following tasks.
      • Retrieves source code from the code repository
      • Restores the project’s dependencies
      • Builds the application
      • Runs all the automated tests
      • Publishes the outputs
    4. We haven’t create the Unit Test project in our .NET Core application so I disable the Test in the Agent section.
  • Here we set the Pipeline named as “azure-devops-demo-ASP.NET Core-CI
  • The Agent pool name is here as Azure Pipelines.
  • The Agent specification basically the pipeline will run into which platform, whether it is windows/Linux/macOS, We choose here as windows-22.
  • Finally click on Save & queue.
Azure DevOps- Create new Pipelines - Create the pipeline Agents
[Fig-17] Configure the Pipeline

  • After click the Save & queue it asked the modal to run the pipeline for the confirmation of Agent pool, specification and branch. Just click Save & Run button.
Azure DevOps- Create new Pipelines - Agent Save & Run
[Fig-18] Run the pipeline

  • On the next screen you can see the Agent is start for run.
Azure DevOps- Create new Pipelines- Agent Queued
[Fig-19] Agent Job Run

But we are getting the issue as pipeline failed. The error message is “No hosted parallelism has been purchased or granted. To request a free parallelism grant, please fill out the following form https://aka.ms/azpipelines-parallelism-request“. We need to navigate to this URL and fill out the form

Azure DevOps- Create new Pipelines-Agent Run Falied
[Fig 20]- Agent failed

How to resolve the Azure DevOps Parallelism issue

We need to fill out the form and request here the Azure DevOps Parallelism request. It will take 2-3 business days for the approve request.

Azure DevOps- Create new Pipelines- Azure DevOps Parallelism issue
[Fig-21] Azure DevOps Parallelism

After waiting 2 business day, ran the pipeline again using below steps.

  • Open the Pipeline again and click on the highlight Run new button.
Azure DevOps Parallelism issue- Run new pipeline
[Fig-22] Run the Pipeline Again

CI-Pipeline-configured-agent

  • Now you can see the Agent Run is succeeded.
Azure DevOps-Agent Run success
[Fig-23] Agent Jobs succeeded

  • You can see below, the build is succeeded and we got the confirmation email.
Azure DevOps- confirmation with email that the project run completed

Enable Continuous Integration

To enable continuous Integration we follow below steps.

  • Go to the Pipelines and click on Edit
Azure DevOps-Pipeline-Edit

  • Select the Triggers Tab and click on the Enable continuous Integration checkbox, finally click on Save & queue.
  • Now CI is ready, when new push is happen then it automatically trigger the pipelines.
Azure DevOps-Enable continuous integration

Testing Continuous Integration

On below you can see the continuous integration has been completed, When a new push happen the CI automatically trigger and our new code build.

That’s it for the first part of the article about Building CI/CD Pipeline using Azure DevOps. On the next article we will see how to implement the CD process.

Conclusion

So far we discussed about Building CI/CD Pipeline using Azure DevOps. Continuous Integration (CI) is a software development practice that requires developers working on the project to integrate code into a shared repository.

We discussed here by steps to understand to configure the Continuous Integration (CI) process.

Related Articles

Jayant Tripathy
Coder, Blogger, YouTuber

A passionate developer keep focus on learning and working on new technology.

Leave a Reply

Your email address will not be published.