Starting with AZURE DEVOPS 🚀

Understanding Azure DevOps and Building a Basic CI/CD Pipeline (Part 1)

Harshit Gupta
10 min readJul 19, 2024

Introduction

In the ever-evolving world of software development, delivering high-quality applications quickly and efficiently has become crucial for businesses to stay competitive. Enter Azure DevOps, a comprehensive suite of tools provided by Microsoft that facilitates the entire application lifecycle from planning and development to delivery and operations. Azure DevOps offers an integrated set of services that enable teams to plan smarter, collaborate more effectively, and deliver faster.

Having worked extensively with AWS in the past, I’ve come to appreciate the power and flexibility that cloud platforms bring to the table. My journey with AWS has given me a solid understanding of cloud infrastructure, services, and automation. Now, I’m excited to delve into Azure DevOps and share my insights on how it can further enhance our development workflows.

In this blog post, we will embark on a journey to understand the fundamentals of Azure DevOps and explore how to set up a basic Continuous Integration and Continuous Deployment (CI/CD) pipeline. Whether you are new to DevOps practices or looking to enhance your current workflow, this guide will provide you with the essential knowledge and practical steps to get started with Azure DevOps.

So, let’s dive in and discover how Azure DevOps can transform your development workflow, making it more efficient, collaborative, and streamlined!

::: Reminder :::

If you enjoy my posts and find them helpful, consider buying me a coffee! Your support can help me to earn relevant certifications and continue sharing valuable insights. Buy Me a Coffee

https://buymeacoffee.com/harshit21

Why Azure DevOps???

  1. Comprehensive Toolset: Azure DevOps provides a complete set of tools for the entire software development lifecycle, from planning and development to testing and deployment. This reduces the need for multiple disjointed tools and simplifies the development process.
  2. Enhanced Collaboration: With features like Azure Boards and Repos, teams can easily collaborate and manage work in real-time. This enhances communication and ensures everyone is on the same page, improving overall productivity.
  3. Scalability and Flexibility: Azure DevOps is designed to scale with your organization. Whether you’re a small team or a large enterprise, Azure DevOps can handle your needs. It also supports multiple languages and platforms, making it a flexible choice for diverse development environments.
  4. Continuous Integration and Continuous Delivery (CI/CD): Azure Pipelines enables you to automate the build, test, and deployment processes, ensuring that code changes are tested and deployed quickly and reliably. This helps in reducing the time to market and increasing the frequency of releases.
  5. Security and Compliance: Azure DevOps integrates with Azure Active Directory and provides features like role-based access control, ensuring that only authorized users can access your projects. It also helps in maintaining compliance with industry standards and regulations.

By leveraging Azure DevOps, organizations can streamline their development processes, enhance collaboration, and deliver high-quality applications more efficiently.

Components of Azure DevOps:

Azure DevOps is a comprehensive suite of development tools provided by Microsoft that supports the entire software development lifecycle. It integrates with numerous other tools and services, making it a versatile and powerful solution for modern software development and operations. Azure DevOps consists of several key components:

  1. Azure Boards: This service provides agile planning tools such as Kanban boards, backlogs, team dashboards, and custom reporting. It helps teams to plan, track, and discuss work across the entire development process
  2. Azure Repos: A set of version control tools that you can use to manage your code. Azure Repos provides both Git repositories or Team Foundation Version Control (TFVC) for source control.
  3. Azure Pipelines: This service allows you to build, test, and deploy code automatically. It supports any language, platform, and cloud, including GitHub, enabling continuous integration and continuous delivery (CI/CD).
  4. Azure Test Plans: A set of tools to test your apps. This includes planned manual testing, user acceptance testing, exploratory testing, and continuous testing.
  5. Azure Artifacts: A service that allows teams to share packages such as Maven, npm, NuGet, and more from public and private sources and integrate package sharing into your CI/CD pipelines.

Azure DevOps is designed to be open and extensible, meaning it can be integrated with your existing tools and services. It supports a wide range of third-party services, allowing you to tailor it to your specific needs.

::: BUILDING A CI/CD PIPELINE :::

In today’s fast-paced software development environment, the ability to rapidly integrate and deploy code changes is crucial for maintaining a competitive edge. Continuous Integration (CI) and Continuous Delivery (CD) are practices that help streamline this process, enabling teams to deliver high-quality software faster and more efficiently.

(Source: Ranorex)

Thanks to Abhishek Veeramalla, for providing such helpful content.

In this two-part blog series, we will explore how to set up a CI/CD pipeline using Azure DevOps, a comprehensive suite of tools designed to support every phase of the development lifecycle. By the end of this series, you’ll have a solid understanding of how to automate your build, test, and deployment processes, ensuring that your applications are always in a deployable state.

In Part 1, we’ll focus on Continuous Integration, guiding you through the steps to set up a robust CI pipeline that automates the process of integrating code changes from multiple contributors. This will help catch issues early in the development cycle, improving code quality and collaboration.

In Part 2, we’ll dive into Continuous Delivery, where we’ll expand our pipeline to automate the deployment process, ensuring that every change is deployable at any time.

Part 1: Continuous Integration

In this section, we will walk through the steps to set up Continuous Integration (CI) using Azure DevOps. Let’s get started!

1. Create a New Project in Azure DevOps

First, create a new project in Azure DevOps. I assume you already have a basic understanding of how to set up an Azure account. If you don’t have one, you can create a free account. I’m using a pay-as-you-go account because I wasn’t eligible for the free one. Regardless, the steps remain the same.

2. Import a Repository from GitHub

Once your project is set up, click on the “Repos” section in your Azure DevOps portal and select “Import” to import a repository from GitHub.

3. Screenshot of after importing the repo

4. Set Main Branch as Default Branch

Ensure the main branch is set as the default branch in your repository settings. This is important for the CI process.

5. Create a Container Registry in Microsoft Azure

Next, go to the Microsoft Azure portal to create a container registry for future use.

6. Create a New Container Registry

Create a new container registry with a new resource group. This registry will be used to store your Docker images.

7. Container Registry Created

8. Create a New Pipeline in Azure DevOps

Go back to the Azure DevOps portal. Navigate to the Pipelines section and create a new pipeline with Azure Repos Git, then select the repository you imported earlier.

9. Select a Docker (Build and Push) Pipeline

Select “Docker (Build and Push)” as the pipeline template. We are using Docker’s sample repository from GitHub. Choose the container registry you created earlier.

10. Configure Your YAML Code

Configure your YAML code for the pipeline. Below is an example of what your YAML file might look like:

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
paths:
include:
- result/*

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '780b93a8-1e9e-40ec-8bc4-de2faf5c1a02'
imageRepository: 'resultapp'
containerRegistry: 'harshitcicd.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/result/Dockerfile'
tag: '$(Build.BuildId)'

pool:
name: 'azureagent'

stages:
- stage: Build
displayName: Build
jobs:
- job: Build
displayName: Build
steps:
- task: Docker@2
displayName: Build an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'build'
Dockerfile: 'result/Dockerfile'
tags: '$(tag)'

- stage: Push
displayName: Push
jobs:
- job: Push
displayName: Push
steps:
- task: Docker@2
displayName: Push an image to container registry
inputs:
containerRegistry: '$(dockerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'push'
tags: '$(tag)'

Do not copy “ dockerRegistryServiceConnection: ‘780b93a8–1e9e-40ec-8bc4-de2faf5c1a02’ ” and “ containerRegistry: ‘harshitcicd.azurecr.io’ ”, otherwise everything would be same.

11. Run the Pipeline (Expect an Error)

If you run the pipeline now, it will give an error output because we have not created an agent pool and virtual machine to host the server for the pipeline. Let’s create the virtual machine in Microsoft Azure first.

12. Create a Virtual Machine in Microsoft Azure

Go to the Microsoft Azure portal and create a new virtual machine.

13. Default Options and SSH Key

While creating the virtual machine, go with the default options but remember to save the SSH key to your local machine.

14. Save the Public IP Address

Copy and save the public IP address of the virtual machine.

15. Create an Agent Pool in Azure DevOps

Go back to Azure DevOps, navigate to Project Settings -> Pipelines -> Agent Pools, and click on “Add Pool” to create a new agent pool.

16. Add a New Agent Pool

17. Connect to Your Virtual Machine via SSH

Open your local machine terminal and connect to your virtual machine using SSH with the downloaded key.

18. Install Docker on the Virtual Machine

Once connected, download and install Docker on the virtual machine.

sudo apt install docker.io
sudo usermod -aG docker azureuser
sudo systemctl restart docker
#its better to reconnect the virtual machine now

19. Configure the Agent on the Virtual Machine

Follow the below commands, which you can find in the “New Agent” option in Azure DevOps.

mkdir myagent && cd myagent
wget https://vstsagentpackage.azureedge.net/agent/2.241.0/vsts-agent-linux-x64-2.189.0.tar.gz
tar zxvf vsts-agent-linux-x64-2.241.0.tar.gz
./config.sh

20. Run the Pipeline

Now, go back to the Azure DevOps portal and run the pipeline again. It should work without errors this time.

21. Create More Pipelines for Different Nodes

Repeat the process to create two more pipelines for different nodes (vote and worker). Each should be configured similarly to the initial pipeline.

for vote-service
for worker-service

22. CI Part Completed

Congratulations! You’ve completed the Continuous Integration part. To learn about setting up Continuous Delivery, head over to Part 2 of this blog.

Conclusion

Setting up Continuous Integration (CI) with Azure DevOps is a powerful step towards achieving a streamlined and efficient development workflow. By following the steps outlined in this guide, you’ve learned how to create a new project in Azure DevOps, import a repository from GitHub, set up a container registry, and create a pipeline that builds and pushes Docker images. Additionally, you’ve configured an agent pool and virtual machine to run your pipeline, ensuring that your CI process runs smoothly.

CI is a crucial part of modern software development, enabling teams to detect issues early, improve code quality, and deliver features faster. With Azure DevOps, you have a comprehensive set of tools at your disposal to implement CI practices effectively.

In the next part of this blog series, we will delve into Continuous Delivery (CD), where we will expand on our pipeline to automate the deployment process. By combining CI and CD, you’ll be able to create a robust CI/CD pipeline that automates the entire process from code commit to deployment, ensuring that your applications are always in a deployable state.

Stay tuned for Part 2, where we will cover:

  • Setting up release pipelines
  • Configuring deployment environments
  • Automating deployments with Azure Pipelines
  • Best practices for CD

By the end of the series, you’ll have a comprehensive understanding of how to leverage Azure DevOps for both Continuous Integration and Continuous Delivery, enabling your team to deliver high-quality software quickly and efficiently.

Thank you for following along, and I look forward to exploring Continuous Delivery with you in the next post!

Connect to me, if you have any query, want to share or suggest me anything, here’s my Portfolio or dm me on LinkedIn. Stay tuned and follow me for more chapters of my odyssey, my projects, cybersec and devops articles, and write-ups and also thank you for being part of my story! 🚀

https://buymeacoffee.com/harshit21

Let’s continue to strengthen our skills and build secure, scalable applications together!

--

--