Shiju Samuel
Shiju Samuel

Reputation: 1591

All build definition for a repository

Is there a way to find all build definitions on Azure DevOps for a repository? I need to move a repo to another project and need to make sure I will change the repo path on all build definition.

Upvotes: 0

Views: 459

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18978

All build definition for a repository

You can use this Rest API to filter all builds which source repository is what you concerned.

https://dev.azure.com/{org name}/{project name}/_apis/build/definitions?repositoryId={repos id}&repositoryType=TfsGit&api-version=5.1

Just specify the repos id and the repos type, then it could filter the satisfied builds.

To get the repository id, just use this API.


I wrote a simple sample can for you check:

$token = "{PAT token}"

$url ="https://dev.azure.com/{org name}/{project name}/_apis/build/definitions?repositoryId={repos id}&repositoryType=TfsGit&api-version=5.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get

Write-Host "results = $($response.value._links.web.href | ConvertTo-Json -Depth 100)"

Since your next step is change the repo path of these satisfied build definition, I think the best and quick way is let you directly know these Builds URL.

At the last line of my script, I write-host these Builds link. After get these links from above script, you can directly put them into the browser and go the corresponding pipeline location. This can help you reduce the time of pipeline found.

enter image description here

enter image description here

Upvotes: 1

Related Questions