How to Create and Configure Microsoft Azure DevOps CI/CD Pipeline Agent

What is CI / CD Pipeline in Azure DevOps?

In the process of learning Microsoft 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 tutorial will focus on them and explain how to choose the Azure DevOps CI Pipeline agent and how to configure it correctly.

CodingSight - How to Create and Configure Microsoft Azure DevOps CI/CD Pipeline Agent

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.

interrelations between 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.

Useful Note: Check out the tutorial on how to create Azure DevOps extension.

Self-hosted vs Microsoft-hosted Agent

Have a look at the below table describing the characteristics and differences of these two agents.

characteristics and differences of Microsoft-hosted agent and self-hosted agent.

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:

information about the 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:

part of the list of pre-installed programs 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:
Setting up the MS Azure agent
  • Select the virtual machine you work with from the Agent Specification drop-down list.
Setting up the MS Azure agent

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 Azure DevOps pipeline agent from GitHub.

Another way is to use the Agent pools section in the MS Azure organization. There, click New Agent.

Setting up the self-hosted agent

Select your OS and click Download.

Setting up the self-hosted agent

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:

Setting up the self-hosted agent

Run the config.cmd file (as Administrator).

Setting up the self-hosted agent

It will ask you to enter the server URL 

The URL should be the following: https://dev.azure.com/{yourOrganizationName}.

Setting up the self-hosted agent

The next step, press ENTER for the request of your authentication type:

press ENTER for the request of your authentication type

On the next request to enter your token, paste it (see the screenshots below):

Enter your token and paste it
Enter authentication type

Enter agent pool – press Enter for using the default pool.

Enter agent pool

Enter agent name – enter the name of the chosen agent. In our case, it is vmagentvm.

Enter the name of the chosen agent

Enter work folder – press Enter and specify the name is needed.

Enter work folder

Enter run agent as service? (Y/N) – press Y.

Enter run agent as service?

Enter User account to use for the service* – press Enter.

The configuration process is complete:

The configuration process of Pipeline is complete

Your agent will appear in the Agents section on the Default page too:

Project Settings

By selecting the Default pool option, you will set the pipeline to run on that machine with the installed agent.

Demo Pipeline Settings

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 tutorial does not explore the Azure DevOps 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.

Vitalii Zaichenko

Vitalii Zaichenko

Vitalii Zaichenko is a software developer at Devart. He has extensive .NET and SQL Server and Azure database knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *