Automating Searchable Branch Configuration in Azure DevOps Repos via REST API
🎯 TL;DR: Bulk Configure Searchable Branches in Azure DevOps via Hidden Policy API
Azure DevOps code search only indexes the default branch (master/main) by default, causing issues when teams use
develop
branches for JFrog Artifactory detection scripts. Problem: No documented API exists for bulk updating searchable branches across thousands of repositories. Solution: Use the undocumented Policy Configuration API with policy type0517f88d-4ec5-4343-9d26-9930ebd53069
to programmatically add branches to the searchable list. This approach leverages the same API calls the Azure DevOps UI uses internally, enabling automation of what would otherwise require manual configuration across massive repository collections.
Recently, I encountered an interesting challenge while working on a JFrog Artifactory adoption tracking project across a large Azure DevOps organization. The requirement was to scan repositories for JFrog URL references to determine which teams had successfully onboarded to their new artifact management system. The problem? Some development teams exclusively work in develop
branches instead of master
or main
, and Azure DevOps code search only indexes the default branch by default.
This seemingly simple requirement - adding develop
to the searchable branches for thousands of repositories - turned into a fascinating exploration of Azure DevOps’ undocumented APIs. While there’s no official documentation for bulk updating searchable branches, I discovered that the Azure DevOps UI uses a specific Policy Configuration API under the hood that we can leverage for automation.
This blog post shares a practical approach to programmatically configure searchable branches across large Azure DevOps organizations using REST APIs that Microsoft doesn’t officially document but absolutely supports.
The Challenge: Azure DevOps Code Search Limitations
Azure DevOps code search is a powerful feature, but it comes with a significant limitation that affects many organizations: by default, only the repository’s default branch (typically master
or main
) is indexed for search operations.
This creates problems in several scenarios:
JFrog Adoption Tracking: Organizations implementing JFrog Artifactory need to scan all repositories for configuration files and dependency references, but teams using feature branches or develop
as their primary branch won’t be detected.
Multi-Branch Development: Teams practicing GitFlow or similar branching strategies may have critical code in develop
, release/*
, or feature branches that needs to be searchable.
Compliance and Security Scanning: Security tools and compliance scripts that rely on code search may miss important files if they’re not in the default branch.