Cross Search in all repositories and branches in Azure Devops Repos

278 Views Asked by At

Azure has very nice function to facilitate cross search through all repositories:

enter image description here

I have noticed that after I did search for a keyword which was in one of the branches it was not found. How can I cross search also through all the branches from all repositories?

3

There are 3 best solutions below

3
Scott Richards On

When searching for code in Azure DevOps, it is possible to search fast because the default branch of each repository has been indexed.

You can extend which branches are indexed, and therefore will be included in the search by navigating to Settings -> Repositories -> {{ choose repository }} -> Searchable branches, allowing you add a maximum of 5 more searchable branches per repository. It may take several hours your your newly added branches to become searchable however, as the indexing may take some time. See docs here.

enter image description here

However, it appears you can still only choose one branch to search at a time. If this doesn't meet your needs, I would recommend searching for help on "how to search for code across all git branches", and use a method outside of what Azure DevOps offers. Here is an example stack overflow thread that may be closer to what you are looking for.

5
Ziyang Liu-MSFT On

You can run the following PowerShell scripts to update the searchable branches via REST API.

$token = "{PAT}"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url="https://dev.azure.com/{Org name}/{Project name}/_apis/policy/Configurations/{Configuration ID}?api-version=7.1-preview.1"
$body = @'
{
    "type": {
        "id": "0517f88d-4ec5-4343-9d26-9930ebd53069"
    },
    "isBlocking": false,
    "isEnabled": false,
    "settings": {
        "scope": [
            {
                "repositoryId": "{Your repo ID}"
            }
        ],
        "searchBranches": [
            "refs/heads/Branch1",
            "refs/heads/branch2",
            "refs/heads/Branch3"
        ]
    }
}
'@
$head = @{ Authorization =" Basic $token" }
Invoke-RestMethod -Uri $url -Method PUT -Headers $head -Body $body -ContentType application/json

  • PAT: Personal access token
  • Org name: Your organization name
  • Project name: Your project name
  • Configuration ID: The configuration ID. You can get it by running REST API Configurations - List or check the network trace when editing the searchable branch from UI.
  • repositoryId: The ID of your repo. You can get it when you run REST API Configurations - List. Or you can see it from the URL when you edit searchable branches from UI.
  • searchBranches: The branches you want to search. Set it as [ ] if you want to remove all branches except the default beanch.
0
fascynacja On

I have created a feature request to enable cross search through all branches: https://developercommunity.visualstudio.com/t/Cross-Search-in-all-repositories-and-bra/10573114