What is CI / CD Pipeline in Azure DevOps?
In the process of learning Azure DevOps, you’ll face numerous challenges, but the most sophisticated of them is setting up the CI Pipeline to work appropriately.
The pivotal point is the Azure Pipelines Agent that establishes and monitors connection with the machine running the DevOps CI Pipeline. Though it is a regular practice, the procedure has its peculiarities. The current article will focus on them and explain how to choose the CI Pipeline agent and how to configure it correctly.
Have a look at the figure below. It demonstrates the interrelations between the Azure CI Pipeline workflow, the Microsoft-hosted agent, and a self-hosted agent.
You need to set up the pipeline to work in an operating environment, where the Microsoft-hosted agent and a self-hosted agent manage the execution of the tasks.
Note that the operating environment differs depending on the agent you use.
- The MS-Agent executes in the ready-made operating environments available in Azure Windows, Ubuntu, and macOS. They are provided as SaaS, and you can deploy these environments to Azure easily. Each time you run a pipeline you have a virtual machine in the cloud.
- A self-hosted agent executes in the on-premise environment (your machine or a virtual machine).
These are the most significant differences, but there are more of them. Let’s consider the distinction features more precisely.
Self-hosted vs Microsoft-hosted Agent
Have a look at the below table describing the characteristics and differences of these two agents.
If you are using the MS-agent, you can clarify which software and hardware you have pre-installed using PowerShell. Execute the following script:
"Shows details of currently running PC"
$computerSystem = Get-CimInstance CIM_ComputerSystem
$computerBIOS = Get-CimInstance CIM_BIOSElement
$computerOS = Get-CimInstance CIM_OperatingSystem
$computerCPU = Get-CimInstance CIM_Processor
$computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
Clear-Host
Write-Host "System Information for: " $computerSystem.Name
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"HDD Capacity: " + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
"HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerSystem.UserName
The following figure provides the information about your virtual machine:
To determine the programs are pre-installed for a Windows-2019 image, execute the following script in PowerShell:
"Get a list of installed programs:"Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize
The query returns the list of pre-installed programs. Note that the screenshot displays a part of that list due to its overall length:
Use cases for MS-agents and self-hosted agents
The choice of this or that agent depends on the project you work with.
- The Microsoft-hosted agent is perfect for small projects that won’t require much time to download, build the project, and run the unit tests. When the pipeline is executed, the virtual machine does not impact the further pipelines.
- The self-hosted agent is the best choice if your project faces any issues of performance, security, accessibility, etc. The disadvantage is that you have to monitor the OS and all the software installed on your physical or virtual machine yourself and ensure they all have the latest updates.
How to create CI/CD Pipeline in Azure MS-Agent
The configuring process for the Microsoft-hosted agent is straightforward:
- Navigate to the Agent pool section and select Azure Pipelines:
- Select the virtual machine you work with from the Agent Specification drop-down list.
How to Setup Pipeline in Azure Devops Self-hosted Agent
The self-hosted agent establishes the connection with that machine running the DevOps CI pipeline. Thus, first of all, you have to install the self-hosted agent itself on that machine (your physical computer or a virtual machine).
Download the self-hosted agent. You can follow the below link and select and download the agent you need from there.
Another way is to use the Agent pools section in the Azure organization. There, click New Agent.
Select your OS and click Download.
Extract the ZIP file. In our case, we have created the dedicated vstsAgent folder, you can have your destination for the file. Have a look at the following screenshot:
Run the config.cmd file (as Administrator).
It will ask you to enter the server URL
The URL should be the following: https://dev.azure.com/{yourOrganizationName}.
The next step, press ENTER for the request of your authentication type:
On the next request to enter your token, paste it (see the screenshots below):
Enter agent pool – press Enter for using the default pool.
Enter agent name – enter the name of the chosen agent. In our case, it is vmagentvm.
Enter work folder – press Enter and specify the name is needed.
Enter run agent as service? (Y/N) – press Y.
Enter User account to use for the service* – press Enter.
The configuration process is complete:
Your agent will appear in the Agents section on the Default page too:
By selecting the Default pool option, you will set the pipeline to run on that machine with the installed agent.
While configuring the CI process, you might use additional software solutions. We’d recommend using the dbForge DevOps Automation Azure DevOps plugin for SQL Server. It includes the steps for creating, testing, and deploying the artifact objects. Refer to the guideline on using this plugin efficiently.
Conclusion
In configuring the CI processes, you might use either an MS-agent or a self-hosted agent. The choice depends on the particular case, and now you know for sure when this or that solution is appropriate.
Though this article does not explore the Azure Pipelines Agent operating in-depth, we hope that it provided you with the basic information on choosing and configuring the right agent for the Azure Pipelines CI.
Tags: azure, devops, Microsoft Azure Last modified: November 03, 2022