az repos pr: Azure DevOps pull requests from the command line
The Azure DevOps extension for the Azure CLI adds az repos pr, which creates, lists, votes on and completes pull requests in Azure Repos. It works only with Azure DevOps Services: Microsoft says the extension does not support Azure DevOps Server. From Microsoft's az repos pr reference, Get started with Azure DevOps CLI and Sign in with a personal access token.
Set it up
- Install: install the Azure CLI, then
az extension add --name azure-devops(az extension update --name azure-devopsto update it). - Sign in:
az login(Microsoft Entra, which Microsoft recommends over personal access tokens); oraz devops login --organization https://dev.azure.com/contosoand paste a personal access token at the prompt (also piped from stdin, in a non-interactive shell); or setAZURE_DEVOPS_EXT_PAT, which the commands use when you have not signed in either way. Guest users can only useaz devops login. - Defaults:
az devops configure --defaults organization=https://dev.azure.com/contoso project=ContosoWebApp. Without defaults, give--organd--project, or run the command in a clone so they are picked up from git config (--detect).--repositorynames the repository.
Create a pull request
az repos pr create --source-branch feature/login --target-branch main --title "Add login" --description "First line" "Second line"
- Without
--target-branch, the repository's default branch. Each value given to--descriptionbecomes a line; Markdown works. --reviewers(or--optional-reviewers) and--required-reviewersadd people or groups, separated by spaces;--work-itemslinks work items by ID;--labelsadds labels (tags).--draft truecreates a draft;--auto-complete truesets auto-complete at once, with--squash,--delete-source-branch,--merge-commit-messageand--transition-work-itemsfor when it completes;--openopens it in the browser.
Find and read pull requests
az repos pr listlists pull requests;--statustakesactive,completed,abandonedorall.--creator,--reviewer,--source-branchand--target-branchfilter;--topand--skippage. For exampleaz repos pr list --reviewer me@contoso.com --output table.az repos pr show --id 21gives the details;az repos pr checkout --id 21checks out the source branch, if you have no local changes (--remote-name,originby default).az repos pr reviewer list|add|remove --id 21andaz repos pr work-item list|add|remove --id 21manage reviewers and linked work items.az repos pr policy list --id 21lists the branch policies with their state, andaz repos pr policy queue --id 21 --evaluation-id …runs one again, such as an expired build.
Vote and complete
az repos pr set-vote --id 21 --vote approve; the values areapprove,approve-with-suggestions,wait-for-author,rejectandreset(what each vote means).az repos pr update --id 21 --status completedcompletes it, with--squash,--delete-source-branch,--merge-commit-messageand--transition-work-items;--status abandonedabandons it and--status activesets it active again.az repos pr update --id 21 --auto-complete truesets auto-complete; set this way it can wait on optional policies too (auto-complete and optional policies).--draft falsepublishes a draft, and--titleand--descriptionchange the text.--bypass-policy true --bypass-policy-reason "…"completes past required policies, for people allowed to override them.
Pull requests in IntelliJ IDEA
Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, lists the pull requests waiting for your vote in an IDE tool window, with their diffs, comments and branch policies, on Azure DevOps Services and on Azure DevOps Server, where the Azure CLI does not go. On Azure DevOps Services it can use your Azure CLI sign-in: with Use my Azure CLI sign-in (az login) instead of a token, it asks the Azure CLI for a short-lived Entra token and keeps it in memory only. Reading is free; voting, commenting, completing and creating pull requests are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Azure DevOps and Azure are trademarks of Microsoft Corporation; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.
More: auto-complete and optional policies · build validation and expired builds · global personal access tokens are retired · TF401179: an active pull request already exists · 日本語