End-To-End CI/CD Automation Using Azure DevOps

This article explains what Azure DevOps is and how to create CI/CD pipelines via Azure DevOps to provide an end-to-end automation experience to users when building .Net Applications.

This article is purely for beginners who want to start learning basic Azure DevOps CI/CD, as a part of this we will cover the following,
  • What is Azure DevOps?
  • Azure Portal
    • Azure Subscription
    • Create App Service
  • Visual Studio
    • Create .Net Core Web Application
    • Push to Azure DevOps
  • Azure DevOps Portal
    • Create Organization
    • Defining service connections
    • Create Build Pipeline - Continuous Integration (CI)
    • Create Release Pipeline - Continuous Deployment (CD)

What is Azure DevOps?

 
A set of practices intended to reduce the time between committing a change to a system and the change being placed into normal production, while ensuring high quality.
 
DevOps is a combination of Development and Operations. It means Dev + Ops = DevOps.
 
It is a culture which automates systems and improves and accelerates delivery to the client in a repeated manner. It’s basically a collaboration between the Development team and the Operations team for serving up a better-quality application. It is a culture for continuous integration and continuous delivery where we make the automated build system as well as an automated deployment system.
 
In other words, DevOps is practice collaboration between Development and Operations from the planning of a project to deployment on production. It involves the complete SDLC life cycle as well as monitoring.
 
Plan => Code => Build => Test (CI)
 
Release => Deploy => Operate =>Monitor(CD)
 
In order to understand the DevOps, we should consider the following points as well,
  • DevOps means only combining the two teams of Development and Operations.
  • It is not a separate team.
  • It is not a product or tool.
Components of Azure DevOps
  1. Azure Boards - contains Work Items, Boards, Backlogs, Sprints to support planning and tracking work, code defects, and issues
  2. Azure Repos - provides Git repositories or Team Foundation Version Control (TFVC) for source control of code
  3. Azure Artifacts - allows teams to share Maven, npm, and NuGet packages from public and private sources and integrate package sharing into your CI/CD pipelines
  4. Azure Test plans - provides several tools to test apps, including manual/exploratory testing and continuous testing
  5. Azure Pipelines - provides build and release services to support continuous integration and delivery for applications

Azure Portal

 
The Azure portal is a web-based, unified console that provides an alternative to command-line tools. With the Azure portal, you can manage your Azure subscription using a graphical user interface. You can build, manage, and monitor everything from simple web apps to complex cloud deployments, create custom dashboards for an organized view of resources, and configure accessibility options for the best experience.
 
Navigate and Login to Azure Portal here.
 
Azure Subscription
 
If you don’t have Azure subscription, get the 30 day free trial services from here.
 
Create App Service
 
Now create Azure App Service to publish web application.
 
Go to App Services and click on Add, fill in the required details and select the App Service Plan as F1 from Dev/Test section. For testing purposes, in real time scenarios this app service plan configurations will be changed based on Application size and usage.
 
Give App Service Name as DemoPipelines, we will use this name later while configuring Release Pipeline(CD).
 
Create new Resource Group if doesn’t have one.
 
For publishing,  just select the Code option -- we are not creating Docker Image.
 
Select Operating System as Windows.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Select App Service Plan
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Finally, review the details and click on Review and Create
 
End-To-End CI/CD Automation Using Azure DevOps 
 

Azure DevOps Portal

 
Navigate and Login to here
 
In order to start work on Azure DevOps portal first we should create Organization and within that, Projects.
 
Create Organization
 
Click Azure DevOps logo which is in the top left corner and click on “New Organization”. Give an organization name and create it.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Create a Project within the created Organization to place our solutions.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Defining service connections
 
This feature of DevOps is you can deploy and automate the whole process as long as you have the right permission, it gives access to all resources within the subscription. In our example, you only need to replace the service connections, then you can get this solution up and running in your subscription. You only need to go to Project settings and add a new service connection as shown below
 
Select Type: Azure Resource Manager -> Give service connection name as DemoPipelinesConnection, we will use this service connection later in Release Pipeline configuration.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Create .Net Application in Visual Studio
 
Create sample core web application project and build the solution as shown below,
 
End-To-End CI/CD Automation Using Azure DevOps
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Push code to Repository - We will select this Source code repository later in Build Pipeline(CI), give Repository Name as CoreWebApplication
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Click on Add to Source control - > Git -> Cick on Publish Git Repo button as shown below and commit to Master branch.
 
End-To-End CI/CD Automation Using Azure DevOps
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Create Build Pipeline(CI)
 
Now we are done with the Project creation and pushed to Azure Repos, now configure build pipeline.
 
Go to Pipelines - Click on Builds and click on New Pipeline
 
We can create the build pipeline using YAML file or We can use the Classic editor, in this article we will use YAML file as shown below
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Where is your code? - Select Azure Repos Git
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Select a repository - Select our targeted Project CoreWebApplication
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Configure your pipeline - click on ASP.NET Core. Since we created .NET Core Project, based on project type we can select the respective one here.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Review your pipeline YAML - Click on Save and Run.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Add the following tasks to YAML file, to build and publish the code from Source Repository and to create publish Artifact . We will select this Artifact in Release Pipeline(CD) instead of Repository.
  1. - task: DotNetCoreCLI@2  
  2. inputs:  
  3. command: 'build'  
  4. projects: '**/*.csproj'  
  5. arguments: '--configuration $(BuildConfiguration)'  
  6. - task: DotNetCoreCLI@2  
  7. inputs:  
  8. command: 'publish'  
  9. publishWebProjects: true  
  10. arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'  
  11. - task: PublishBuildArtifacts@1  
  12. inputs:  
  13. PathtoPublish: '$(Build.ArtifactStagingDirectory)'  
  14. ArtifactName: 'drop'  
  15. publishLocation: 'Container'  
Now click on Save and Run, Saving will commit /azure-pipelines.yml to the repository.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Now Build Pipeline is created, and Build is in progress.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Build has been Completed, and we can see the newly created Build Number. For each build a new Build number will be created.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
if we want, we can rename the pipeline name by clicking on Rename/Move option like below
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Enable continuous Integration
 
We can run build pipeline manually or we can enable continuous Integration – whenever we commit the code to selected branch Build pipeline automatically runs.
 
To add continuous Integration, add a Trigger as shown below
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Click on Trigger and check the Override the YAML continuous integration trigger from here and select branch as shown below and click on Save
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Now Test the above configured continuous integration trigger.
 
Let’s go back to Visual Studio and do some changes in Created CoreWebApplication project and see if automated continuous integration has triggered or not
 
Add comment as “Commit to test continuous integration” as shown below
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Push the code to Repository
 
End-To-End CI/CD Automation Using Azure DevOps 
 
As shown below, Continuous integration has been triggered , we can check the comment that we have given “Commit to test continuous integration” as the latest build name with a new build number.
 
We can find the difference between manually triggered build and CI Builds also as shown below:
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Build Pipeline execution has been completed successfully as shown below.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Create Release Pipeline(CD)
 
Now it’s time to create Release pipeline to deploy applications.
 
We can organize the deployment jobs in your release pipeline into stages. Stages are the major divisions in release pipeline like "Dev", "QA", and "Production" are the examples of release stages.
 
A stage in a release pipeline consists of jobs and tasks. The deployment of a release to a stage is controlled through approvals and gates, deployment conditions and triggers, and queuing policies.
 
From Pipelines – Click on Releases and click on New Pipeline
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Select Template as “Azure App Service deployment” since we are planning to Deploy our app into Azure App Service.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Add Artifact –This is the place we need to select the above created Build Pipeline’s Artifact
 
The artifacts published by each version will be available for deployment in release pipelines
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Select the Artifact and Click on Add
 
As above, add a new Stage called Dev and configure Job and Tasks.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Azure subscription – Above defined Service Connection; i.e DemoPipelinesConnection and App Service; i.e., DemoPipelines, here
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Configure Agent job, Select Agent Specification as Windows related since we configured our App Service to run on Windows.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Configure Azure App Service deploy, based on our Agent and Artifact configuration. This task's details will be populated automatically so leave them as they are.
End-To-End CI/CD Automation Using Azure DevOps 
 
We are done with the required configuration, finally click on Save.
 
Enable Continuous deployment trigger
 
We can trigger Release pipeline manually or automatically by switching Enabled option as shown below.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Save the changes and Click on Release then Click on Create
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Finally go back to Visual Studio and do some changes in Created CoreWebApplication project and see if automated Build and Release pipelines triggered or not.
 
After pushing the code to Repository automatically the first Build Pipeline will be triggered and after that the new Release pipeline will be triggered as shown below. Complete CI and CD pipelines have run successfully.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Click on Release name or Stage to view the complete details.
 
End-To-End CI/CD Automation Using Azure DevOps 
 
If we trigger Release pipeline manually it shows “Manually Triggered” as shown below,
 
End-To-End CI/CD Automation Using Azure DevOps 
 
Now navigate to your App Service Url and you can see the latest commits deployed there.
 
End-To-End CI/CD Automation Using Azure DevOps