Blog Post

Apps on Azure Blog
2 MIN READ

Azure DevOps - Agent pool report and replace.

owaino's avatar
owaino
Icon for Microsoft rankMicrosoft
Jan 20, 2025

Recently with the introduction of Managed DevOps Pools many customers have been asking how they can gain the visibility of the agent pools being used across their DevOps organisations and automate the replacement of these pools. In this blog post we look at a new tool to do just that.

Problem Domain

As usage of Azure DevOps organisations grow so do the number of projects, repositories, pipelines and agent pools used. With new services available such as Managed DevOps Pools it can appear a mammoth task for central IT function to manually trawl through every pipeline noting down each agentpool being used. Replacing these values potentially even more complicated after creating the new agent pools and mapping them with potential for human error.

Solution

As there is no built in reporting for this at the moment I have built a bespoke bash script that can be ran to generate a report and optionally replace the values in each pipeline for a new agentpool.

 

The tool is in this repository: https://github.com/owainow/azure_devops_agentpool_report_and_replace

Getting Started

The only prerequisite for this repository is a PAT with permissions to view (or modify) projects, repositories and pipelines. For the --dry-run mode read access is required. For replacement read & write access is required. 

Please make a note of your PAT once you create it as it will not be shared again and is required for each run of the tool. (You can change this by running the auth lines locally first and removing them from the script). 

The tool is written as a bash script which looks for particular agent pools within YAML files in repos and cross-references their values with the agent pool values defined in the agent pool map:

This agent pool can be used to map self-hosted agent pools found under pool: name: or under pool: vm Image:.

This currently replaces vm Image with name for self-hosted pools/mdp. If you want to use this tool to change self-hosted pools to hosted DevOps runners the script can be easily augmented to replace name with vm Image for the agent pool map. 

``` # Define the mapping of old agent pool names to new agent pool names declare -A AGENT_POOL_MAP=( ["Azure Pipelines"]="test" ["default"]="test" ) ```


The following argument is available:

  •  --dry-run - Generate CSV report but do not make changes to the pipeline files.


As the tool requires evaluating the pipeline YAML files itself all repositories are cloned onto the machine running the tool and removed after the report is generated. For larger organisations this can take some time to complete.

1. Clone the repository
2. Update the ORG_URL variable with your organisation url e.g. ORG_URL="https://dev.azure.com/owainow"
3. Run

. Agentpool_report_and_change.sh --dry-run

4. Authenticate with either PAT or Interactive Login
5. Review CSV output

If you are happy with the changes then you can rerun the tool without the dry run option.

5. (Optional for live changes) - Run

. Agentpool_report_and_change.sh

 Output

Example Terminal Output:

 

Example CSV Output:

 

Contributing

Feel free to fork and create pull requests with any improvements or features you have added. Please ensure any feature additions are used through an argument e.g. --dry-run. 

Published Jan 20, 2025
Version 1.0
No CommentsBe the first to comment