Introduction
In the world of software development, Continuous Integration (CI) and Continuous Deployment (CD) practices are crucial for automating the testing and deployment of code. Azure DevOps provides a powerful platform for implementing CI/CD pipelines. While Azure DevOps offers hosted agents for running pipelines, there are scenarios where you might need to deploy your own agents in Azure. These scenarios can range from requiring a specific environment setup to needing to run pipelines on-premises or in a private network. This blog post guides you through the process of deploying your own agents in Azure to work with Azure DevOps CI/CD pipelines.
Why Deploy Your Own Agents?
- Customization: You can customize your agents to have any software and configuration you need.
- Performance: You can choose the size and performance characteristics of the VMs that host your agents.
- Control: You have more control over the environment and can implement stricter security measures.
Step 1: Prepare Your Azure Environment
Before you start, ensure you have an Azure account and a subscription. If you don’t, sign up for a free account. Once ready, follow these steps:
-
Create a Virtual Machine (VM): In the Azure portal, create a new VM that will act as your agent. You can choose an image that matches the OS requirements of your projects. Make sure the VM has internet access and can reach Azure DevOps services.
-
Network Security: Ensure your network security group (NSG) rules allow outbound traffic to Azure DevOps services .
Step 2: Register the Agent with Azure DevOps
-
Create a Personal Access Token (PAT): In Azure DevOps, go to User Settings > Personal Access Tokens > New Token. Give it the appropriate permissions, such as Agent Pools (read, manage) and ensure it has an appropriate expiration.
-
Download and Configure the Agent: Access your VM, then navigate to your Azure DevOps organization and go to Project Settings > Agent Pools. Create a new agent pool (if needed) and select it. Click on "New agent" and follow the instructions to download and configure the agent on your VM.
Step 3: Install and Configure the Agent
On your VM:
-
Extract the Agent Package: Use the command line to navigate to the directory where you downloaded the agent. Extract the package.
-
Run the Configuration Script: Execute the configuration script (
./config.shfor Linux/macOS or.\config.cmdfor Windows). When prompted, enter the URL of your Azure DevOps organization and the PAT you created earlier.My Demo Org URL : https://dev.azure.com/GetPracticalDemo/
PAT used for this demo: “jq2nfn4aevchitfzzj57zwmtjnw5iju3zz456oz4a6uearly4dha” -
Start the Agent: Once configured, start the agent. On Linux/macOS, use
./svc.sh installand then./svc.sh start. On Windows, run.\svc installfollowed by.\svc start.
Step 4: Use the Self-hosted Agent in Your Pipelines
Now that your agent is set up and running, you can start using it in your CI/CD pipelines. When defining or editing a pipeline, you can specify the agent pool where your new self-hosted agent resides.
Best Practices
- Security: Regularly update the software on your agents and monitor for any security vulnerabilities.
- Maintenance: Periodically check the health and performance of your agents. Consider automating the provisioning and de-provisioning of agents based on the demand.
- Scalability: Leverage Azure VM scale sets if you need to scale out your agents dynamically based on the workload.
Conclusion
Deploying your own agents in Azure for Azure DevOps CI/CD pipelines offers greater flexibility, control, and customization of your build and deployment environments. By following the steps outlined above, you can set up your self-hosted agents and integrate them into your development workflow, ensuring that your team can build, test, and deploy applications more efficiently and securely.
Happy coding!
Joao Paulo Costa

