Learning Azure Devops - Build And Release Pipeline

Introduction

 
This is the second article in the Azure devops learning series. In this article, I will be covering Azure devops pipelines build and release pipeline. If you want to learn how to setup you project and devops account read my article:

CI/CD pipelines basics

 
The "CI" in CI/CD refers to continuous integration, which is an automation process to build, test, and merge to a shared repository. The CD in CI/CD refers to continuous deployment  and is automatically releasing a developer’s changes from the repository to production, where it is usable by customers.
 
A CI/CD pipeline is a series of steps that must be performed in order to deliver a new version of software. The steps that form a CI/CD pipeline are distinct subsets of tasks grouped into what is known as a pipeline stage. Typical pipeline stages include,
  • Build - The stage where the application is compiled.
  • Test - The stage where code is tested. Automation here can save both time and effort.
  • Release - The stage where the application is delivered to the repository.
  • Deploy - In this stage code is deployed to production.

Azure Devops

 
Azure devops provide complete tool chain to manage, automate and deploy your build very easily and effectively.
 
Benefits of azure devops
  1. Any language any platform
  2. Containers and Kubernetes
  3. Very Extensible
  4. Deploy to any cloud
  5. Free for open source

Pipeline- Build CI

 
After login to the Azure devops and navigating to your project you will be able to see the left menu.
 
Learning Azure Devops - Build And Release Pipeline 
 
Click on the pipeline and you can see multiple option to choose from, click on the pipeline. You will see the below page after clicking on pipeline option from menu. In my case I have added a test project AspnetcoreRnDfor article which is web application using asp.net core 3.1.
 
Learning Azure Devops - Build And Release Pipeline 
 
After clicking on the pipeline option from the menu you will be able to see a dashboard with an existing list of build pipelines. Here below you will be able to see two build pipelines.
 
Build pipeline is the tool chain which collects the latest changes from the repository and the branch and create a package to a location which can later pick up the release pipeline.
 
Learning Azure Devops - Build And Release Pipeline 
 
There is the option of creating a new pipeline or you can open the existing one  from the list, there you can see the list of runs that pipeline has done previously, either pass or fail.
 
Learning Azure Devops - Build And Release Pipeline 
 
You can open the pipeline by clicking on edit the existing pipeline and this will be the interface where the list of tasks is, and every task has certain actions to perform.
 
Learning Azure Devops - Build And Release Pipeline 
 
Let’s choose the option to create a new build pipeline by clicking on New Pipeline.
 
Below is the first screen. It will come with list of different pre-configured options of choosing repository and source control system. In my case I have chosen Azure Repos Git for collecting the latest changes.
 
Learning Azure Devops - Build And Release Pipeline 
 
First question it asks is where is your code, meaning Azure devops need to know the repository address from where it can check the latest code to generate a build package for your deployment pipeline.
 
There is another option of opening classic Edition without YAML file fromwhere you can choose the repo, project and branch.
 
Learning Azure Devops - Build And Release Pipeline 
 
Next screen is where there is an option of choosing a remplate from the list or Empty one. Azure devops is the toolchain which gives you power to deploy any code from any language to any platform and Microsoft has created a lot of templates to start with. If you like to use your own then go for Empty job or YMAL one. In my case as my test app was in asp.net core 3.1 so I have chosen  the below selected option from the list.
 
Learning Azure Devops - Build And Release Pipeline 
 
After applying this Template your page will look as below.
 
Learning Azure Devops - Build And Release Pipeline 
 

Task

 
You can setup you task where are multiple options with pipeline configurations
  1. Name
  2. Agent pool
  3. Agent Specifications
  4. Parameters
  5. Artifact Name
Learning Azure Devops - Build And Release Pipeline 
 
From here we can choose to change project, repository or branch from which we want build to be deployed.
 
Learning Azure Devops - Build And Release Pipeline 
 
Agent Job
 
Display name which you can change and agent pool which is by default <inherit from pipeline> I have kept it as it is, you can have your agent pool setting like the hosted one which you want to secure or manage.
 
NuGet tool installer
 
Acquires a specific version of NuGet from the internet or the tools cache and adds it to the PATH. Use this task to change the version of NuGet used in the NuGet tasks.
 
Nuget Restore
 
Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
 
Visual Studio build
 
Build with MSBuild and set the Visual Studio version property
 
Visual Studio Test
 
Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run.
 
Index sources and publish symbols
 
Index your source code and publish symbols to a file share or Azure Artifacts symbol server
 
Publish build artifacts
 
Publish build artifacts to Azure Pipelines or a Windows file share
 
These are basic step which will restore the dependencies, build your project, run the test and generate and publish the build with a version at shared drop location
 
Variables
 
There is an option of Variables you can set up. I am going to cover the variables later in this article.
  1. Pipeline
  2. Variable groups
Learning Azure Devops - Build And Release Pipeline 
 
Triggers
 
Another option which is for the enabling /disabling continuousintegration trigger, meaning whenever there is a check-in the files of repository defined it will automatically kick the build to generate artifacts with the latest changes included in it. 
 
There is an option to exclude the file folders from the branch filter and you can add as many as you like  to manage the trigger and also you can disable the trigger also if you choose a manual trigger to create the  latest build.
 
Learning Azure Devops - Build And Release Pipeline 
 
Options
 
This is the option for setting up build properties like build artifact naming format, description, or build timeout. In a nutshell you can control the build output settings and setup some action when success / failure happened. 
 
Learning Azure Devops - Build And Release Pipeline 
 
Retention
 
Can set up policy for the retention of builds.
 
History
 
This is a very good feature to keep track of the changes. You can compare the changes for two versions for auditing purposes.
 
Learning Azure Devops - Build And Release Pipeline 
 
It will open up a compare scene with the difference highlighted like any other version control system.
 
Learning Azure Devops - Build And Release Pipeline 
 
Another option is Save, Save and Queue, Draft, Discard for the changes you are doing and how you want to run it after making those changes. There is an explicit option to queue any build manually from here and summary will help you see the history of all run-in lists as a dashboard. From this page you can edit the existing pipeline or run from the Run pipeline button option.
 
Learning Azure Devops - Build And Release Pipeline 
 
Here there is an option to filter after clicking the filter icon.
 
You can view the list of last runs of build pipeline and can go into detail where it has an option to see how it has run, how much time it has taken to run code coverage, releases and changes.
 
Learning Azure Devops - Build And Release Pipeline 
 
You can go more in detail with steps to analyze what has been changed with each build.
 
Learning Azure Devops - Build And Release Pipeline 
 
Also, you can the open the drop location where artifacts have been placed and can check the list of files if any verification is required.
 
Learning Azure Devops - Build And Release Pipeline 
 
Release - CD Pipeline
 
When you click on the release pipeline from the menu, a release dashboard will appear if you have any pipeline configured. Here I have only one, webappDeploy-CD in the list which look likes it has list of releases with stage and the run status.
 
Learning Azure Devops - Build And Release Pipeline 
 
From the option you can create a new release for the existing pipeline and deploy to the stages you have defined, like Dev in my case.
 

Creating a new Release Pipeline

 
The below screen will appear after clicking New from the top left.There are two sections in the release pipeline, Artefacts and Stages.
 
In the  left you can see a list of templates which give a way to create pipeline and choose your application package which will get deployed to any server. You can start with an empty template also.
 
In my case I want to deploy the application to Azure cloud as an app service so choose Azure App Service Deployment template from the list.
 
Learning Azure Devops - Build And Release Pipeline 
 
After applying the template you can rename the environment, in my case I have given the name Dev.
 
Learning Azure Devops - Build And Release Pipeline 
 
Artifacts 
 
By default you will get multiple options from the list to choose source type for the artifacts. It will ask for the project and source for the build pipeline.
 
Learning Azure Devops - Build And Release Pipeline 
 
In my case I have two build pipelines in the list and I have chosen WebappBuild-CI
 
Learning Azure Devops - Build And Release Pipeline 
 
You can set up option of continuous deployment trigger which means enabling the trigger will create a new release every time a new build is available.
 
Learning Azure Devops - Build And Release Pipeline 
 
You can setup pre-deployment condition 
  1. After Release - Meaning whenever a new release is created it will deploy.
  2. Manual – You have to run this manually.
Learning Azure Devops - Build And Release Pipeline 
 
Another important pre deployment condition is pre-deployment approvals whre you can setup an approver or multiple or group like below
  1. Any order
  2. Sequece
  3. Any user
Learning Azure Devops - Build And Release Pipeline 
 
On clicking on the task from the stages below list of tasks will be open which has deploy Azure app service task.
 
Dev Task 
  1. Subscriptions- It will ask you to setup an active subscription and for the first time it needs to be authorized
  2. App type- web app on windows.
  3. App service name- you can elect app service from Azure where you want to deploy.
Learning Azure Devops - Build And Release Pipeline 
 
Run on Agent
 
Here we have the option to select the agent pool and agent specifications on which deployment will happen.
 
Learning Azure Devops - Build And Release Pipeline 
 

Deploy Azure App service

 
This step will deploy package to app service in azure.
 
Learning Azure Devops - Build And Release Pipeline 
 
You can create a new release by clicking on the create release option and deploy to any environment of your choice.
 
Learning Azure Devops - Build And Release Pipeline 
 
You can login to your azureportal and see the app service deoloyed with the latest changes.
 
Learning Azure Devops - Build And Release Pipeline 
 
Url - https://testapprnd.azurewebsites.net/
 
Learning Azure Devops - Build And Release Pipeline 
 

Conclusion

 
Hope this article will help you understand the CI CD basic concept with Azure devops.You can play around with it and learn more. In the next lab, I will explain Azure variables, variable groups, and Azure boards.Until then,  stay safe.
 
Keep learning and keep smiling.
 
Resources and Useful Links
 
Thanks to the authors of the below links,
  • https://azure.microsoft.com/en-us/pricing/details/devops/azure-devops-services/
  • https://azuredevopslabs.com/
  • https://azure.microsoft.com/en-in/services/devops/pipelines/