In Azure Dev Ops, given a branch name, how I do I get the corresponding Pull Request (if one exists).
I have a local branch named FooBranch
which I’ve pushed to the remote repo BarRepo
which lives in Azure DevOps. I created a Pull Request in the BarRepo
repo from the branch FooBranch
.
The is the branch’s Url
https://{org}.visualstudio.com/{project}/_git/BarRepo?version=GBFooBranch
The PR url looks like this
https://{org}.visualstudio.com/{project}/_git/BarRepo/pullrequest/{prID}
where {prID}
is an 8-digit number.
Given the branch BarRepo
how do I determine {prID}
? I would like to do this in a PowerShell script if possible. Maybe thru the Azure CLI
. Or via an HTTP req.
I know not all branches will have an associated PR. Can a branch be in several PRs?
2
Answers
You can use the az repos pr list command to list pull requests and filter results by both source and target branch (among others), if needed:
Sample YAML pipeline:
Sample response:
Correspondent property in the above response is
pullRequestId
.Yes, a branch can be linked to multiple PRs if it’s used as the source for different target branches or if multiple PRs are created from it. For example, a
feature
branch might have PRs for both thedevelopment
andrelease
branches, each with a different PR ID but sharing the same source branch.Test result:
Test result: