azure-devops-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAzure DevOps CLI Skill
Azure DevOps CLI 技能指南
Quick Start
快速开始
Installation & Authentication
安装与认证
bash
undefinedbash
undefinedInstall Azure DevOps CLI extension
Install Azure DevOps CLI extension
az extension add --name azure-devops
az extension add --name azure-devops
Authenticate (choose one method)
Authenticate (choose one method)
az login # Interactive browser login
az devops login --organization https://dev.azure.com/YOUR_ORG # PAT token login
az login # Interactive browser login
az devops login --organization https://dev.azure.com/YOUR_ORG # PAT token login
Configure defaults (recommended)
Configure defaults (recommended)
az devops configure --defaults organization=https://dev.azure.com/YOUR_ORG project=YOUR_PROJECT
az devops configure --defaults organization=https://dev.azure.com/YOUR_ORG project=YOUR_PROJECT
Verify setup
Verify setup
az devops project list
undefinedaz devops project list
undefinedConfiguration Patterns
配置模式
bash
undefinedbash
undefinedSet defaults to avoid repeating --organization and --project
Set defaults to avoid repeating --organization and --project
az devops configure --defaults organization=https://dev.azure.com/myorg project=myproject
az devops configure --defaults organization=https://dev.azure.com/myorg project=myproject
List current configuration
List current configuration
az devops configure --list
az devops configure --list
Use Git aliases for common commands
Use Git aliases for common commands
az devops configure --defaults use-git-aliases=true
az devops configure --defaults use-git-aliases=true
Common output formats
Common output formats
--output table # Human-readable tables (default)
--output json # JSON for scripting
--output tsv # Tab-separated values
undefined--output table # Human-readable tables (default)
--output json # JSON for scripting
--output tsv # Tab-separated values
undefinedEssential Commands by Group
按分组的核心命令
1. DevOps (Organization & Projects)
1. DevOps(组织与项目)
bash
undefinedbash
undefinedList projects
List projects
az devops project list --organization https://dev.azure.com/myorg
az devops project list --organization https://dev.azure.com/myorg
Create project
Create project
az devops project create --name "MyProject" --visibility private
az devops project create --name "MyProject" --visibility private
Show project details
Show project details
az devops project show --project MyProject
az devops project show --project MyProject
Delete project
Delete project
az devops project delete --id PROJECT_ID --yes
az devops project delete --id PROJECT_ID --yes
Manage users/teams
Manage users/teams
az devops user list
az devops team list --project MyProject
undefinedaz devops user list
az devops team list --project MyProject
undefined2. Pipelines (Build & Release)
2. Pipelines(构建与发布)
bash
undefinedbash
undefinedList pipelines
List pipelines
az pipelines list --project MyProject
az pipelines list --project MyProject
Run a pipeline
Run a pipeline
az pipelines run --name "MyPipeline" --branch main
az pipelines run --name "MyPipeline" --branch main
Show pipeline runs
Show pipeline runs
az pipelines runs list --pipeline-ids 123
az pipelines runs list --pipeline-ids 123
Show run details
Show run details
az pipelines runs show --id RUN_ID
az pipelines runs show --id RUN_ID
Create pipeline from YAML
Create pipeline from YAML
az pipelines create --name "NewPipeline" --repository myrepo --branch main --yml-path azure-pipelines.yml
undefinedaz pipelines create --name "NewPipeline" --repository myrepo --branch main --yml-path azure-pipelines.yml
undefined3. Boards (Work Items & Sprints)
3. Boards(工作项与迭代)
bash
undefinedbash
undefinedList work items
List work items
az boards query --wiql "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.State] = 'Active'"
az boards query --wiql "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.State] = 'Active'"
Create work item
Create work item
az boards work-item create --type "User Story" --title "New Feature" --assigned-to me@example.com
az boards work-item create --type "User Story" --title "New Feature" --assigned-to me@example.com
Update work item
Update work item
az boards work-item update --id 123 --state "In Progress"
az boards work-item update --id 123 --state "In Progress"
Show work item
Show work item
az boards work-item show --id 123
az boards work-item show --id 123
List iterations/sprints
List iterations/sprints
az boards iteration project list
undefinedaz boards iteration project list
undefined4. Repos (Git Repositories)
4. Repos(Git 代码仓库)
bash
undefinedbash
undefinedList repositories
List repositories
az repos list --project MyProject
az repos list --project MyProject
Create repository
Create repository
az repos create --name "myrepo" --project MyProject
az repos create --name "myrepo" --project MyProject
List pull requests
List pull requests
az repos pr list --repository myrepo --status active
az repos pr list --repository myrepo --status active
Create pull request
Create pull request
az repos pr create --repository myrepo --source-branch feature/new --target-branch main --title "New Feature"
az repos pr create --repository myrepo --source-branch feature/new --target-branch main --title "New Feature"
Show PR details
Show PR details
az repos pr show --id PR_ID
undefinedaz repos pr show --id PR_ID
undefined5. Artifacts (Package Management)
5. Artifacts(包管理)
bash
undefinedbash
undefinedList feeds
List feeds
az artifacts feed list
az artifacts feed list
Create feed
Create feed
az artifacts feed create --name "myfeed" --project MyProject
az artifacts feed create --name "myfeed" --project MyProject
List packages
List packages
az artifacts universal list --feed myfeed --project MyProject
az artifacts universal list --feed myfeed --project MyProject
Publish package
Publish package
az artifacts universal publish --feed myfeed --name mypackage --version 1.0.0 --path ./dist
az artifacts universal publish --feed myfeed --name mypackage --version 1.0.0 --path ./dist
Download package
Download package
az artifacts universal download --feed myfeed --name mypackage --version 1.0.0 --path ./download
undefinedaz artifacts universal download --feed myfeed --name mypackage --version 1.0.0 --path ./download
undefinedCommon Workflows
常用工作流
Workflow 1: CI/CD Pipeline Automation
工作流1:CI/CD 流水线自动化
bash
undefinedbash
undefinedCreate pipeline, run it, and monitor
Create pipeline, run it, and monitor
az pipelines create --name "API-Build" --repository myrepo --yml-path ci/azure-pipelines.yml
az pipelines run --name "API-Build" --branch main
az pipelines runs show --id RUN_ID --open # Opens in browser
undefinedaz pipelines create --name "API-Build" --repository myrepo --yml-path ci/azure-pipelines.yml
az pipelines run --name "API-Build" --branch main
az pipelines runs show --id RUN_ID --open # Opens in browser
undefinedWorkflow 2: Pull Request Review Automation
工作流2:Pull Request 审核自动化
bash
undefinedbash
undefinedList active PRs, show details, add comment
List active PRs, show details, add comment
az repos pr list --repository myrepo --status active --output table
az repos pr show --id 456 --open
az repos pr update --id 456 --status approved
undefinedaz repos pr list --repository myrepo --status active --output table
az repos pr show --id 456 --open
az repos pr update --id 456 --status approved
undefinedWorkflow 3: Work Item Batch Creation
工作流3:工作项批量创建
bash
undefinedbash
undefinedCreate multiple work items from template
Create multiple work items from template
for title in "Feature A" "Feature B" "Feature C"; do
az boards work-item create --type "User Story" --title "$title" --assigned-to team@example.com
done
undefinedfor title in "Feature A" "Feature B" "Feature C"; do
az boards work-item create --type "User Story" --title "$title" --assigned-to team@example.com
done
undefinedWorkflow 4: Pipeline Status Dashboard
工作流4:流水线状态看板
bash
undefinedbash
undefinedGet recent pipeline runs with status
Get recent pipeline runs with status
az pipelines runs list --top 10 --query "[].{Name:pipeline.name, Status:status, Result:result, Started:startTime}" --output table
undefinedaz pipelines runs list --top 10 --query "[].{Name:pipeline.name, Status:status, Result:result, Started:startTime}" --output table
undefinedWorkflow 5: Repository Clone Automation
工作流5:代码仓库克隆自动化
bash
undefinedbash
undefinedList all repos and clone them
List all repos and clone them
az repos list --query "[].{Name:name, URL:remoteUrl}" --output tsv | while IFS=$'\t' read -r name url; do
git clone "$url" "./$name"
done
undefinedaz repos list --query "[].{Name:name, URL:remoteUrl}" --output tsv | while IFS=$'\t' read -r name url; do
git clone "$url" "./$name"
done
undefinedWorkflow 6: Sprint Planning Helper
工作流6:迭代规划助手
bash
undefinedbash
undefinedList current sprint work items
List current sprint work items
az boards query --wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.IterationPath] = @CurrentIteration" --output table
undefinedaz boards query --wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.IterationPath] = @CurrentIteration" --output table
undefinedWorkflow 7: Release Gate Checking
工作流7:发布门禁检查
bash
undefinedbash
undefinedCheck if all PRs are approved before release
Check if all PRs are approved before release
PENDING=$(az repos pr list --status active --query "length([?status!='approved'])")
if [ "$PENDING" -eq 0 ]; then
az pipelines run --name "Release-Pipeline"
fi
undefinedPENDING=$(az repos pr list --status active --query "length([?status!='approved'])")
if [ "$PENDING" -eq 0 ]; then
az pipelines run --name "Release-Pipeline"
fi
undefinedWorkflow 8: Artifact Versioning
工作流8:制品版本管理
bash
undefinedbash
undefinedPublish versioned artifact with timestamp
Publish versioned artifact with timestamp
VERSION="1.0.$(date +%Y%m%d%H%M%S)"
az artifacts universal publish --feed myfeed --name myapp --version "$VERSION" --path ./build
undefinedVERSION="1.0.$(date +%Y%m%d%H%M%S)"
az artifacts universal publish --feed myfeed --name myapp --version "$VERSION" --path ./build
undefinedWorkflow 9: Team Dashboard Data
工作流9:团队看板数据导出
bash
undefinedbash
undefinedExport team metrics to JSON
Export team metrics to JSON
az devops project show --project MyProject > project.json
az pipelines runs list --top 50 > recent-runs.json
az repos pr list --status all > all-prs.json
undefinedaz devops project show --project MyProject > project.json
az pipelines runs list --top 50 > recent-runs.json
az repos pr list --status all > all-prs.json
undefinedWorkflow 10: Environment Sync
工作流10:环境配置同步
bash
undefinedbash
undefinedCopy pipeline variables across environments
Copy pipeline variables across environments
az pipelines variable list --pipeline-name "MyPipeline" --output json > vars.json
az pipelines variable list --pipeline-name "MyPipeline" --output json > vars.json
Edit vars.json as needed
Edit vars.json as needed
az pipelines variable-group create --name "Production" --variables @vars.json
undefinedaz pipelines variable-group create --name "Production" --variables @vars.json
undefinedTroubleshooting
故障排查
Common Issues
常见问题
Authentication Failures:
bash
undefined认证失败:
bash
undefinedClear cached credentials
Clear cached credentials
az account clear
az login
az account clear
az login
Use PAT token directly
Use PAT token directly
export AZURE_DEVOPS_EXT_PAT=your_personal_access_token
az devops login
**Default Configuration:**
```bashexport AZURE_DEVOPS_EXT_PAT=your_personal_access_token
az devops login
**默认配置问题:**
```bashReset defaults if commands fail
Reset defaults if commands fail
az devops configure --defaults organization="" project=""
az devops configure --defaults organization="" project=""
Then set explicitly in each command
Then set explicitly in each command
az pipelines list --organization https://dev.azure.com/myorg --project MyProject
**Extension Issues:**
```bashaz pipelines list --organization https://dev.azure.com/myorg --project MyProject
**扩展问题:**
```bashUpdate Azure DevOps extension
Update Azure DevOps extension
az extension update --name azure-devops
az extension update --name azure-devops
Check extension version
Check extension version
az extension show --name azure-devops
**Query Syntax:**
```bashaz extension show --name azure-devops
**查询语法问题:**
```bashWIQL queries require proper escaping
WIQL queries require proper escaping
az boards query --wiql "SELECT [System.Id] FROM WorkItems WHERE [System.State] = 'Active' AND [System.AssignedTo] = 'me@example.com'"
undefinedaz boards query --wiql "SELECT [System.Id] FROM WorkItems WHERE [System.State] = 'Active' AND [System.AssignedTo] = 'me@example.com'"
undefinedAdvanced Patterns
高级模式
REST API Access
REST API 访问
bash
undefinedbash
undefinedDirect REST API calls for unsupported operations
Direct REST API calls for unsupported operations
az devops invoke --area build --resource builds --route-parameters project=MyProject --api-version 6.0 --http-method GET
az devops invoke --area build --resource builds --route-parameters project=MyProject --api-version 6.0 --http-method GET
POST with JSON body
POST with JSON body
az devops invoke --area git --resource repositories --route-parameters project=MyProject --http-method POST --in-file payload.json
undefinedaz devops invoke --area git --resource repositories --route-parameters project=MyProject --http-method POST --in-file payload.json
undefinedScripting with JMESPath
使用JMESPath编写脚本
bash
undefinedbash
undefinedComplex queries using JMESPath
Complex queries using JMESPath
az pipelines runs list --query "[?result=='failed'].{Pipeline:pipeline.name, Branch:sourceBranch, Time:finishedDate}" --output table
az pipelines runs list --query "[?result=='failed'].{Pipeline:pipeline.name, Branch:sourceBranch, Time:finishedDate}" --output table
Filter and transform data
Filter and transform data
az repos pr list --query "[?targetRefName=='refs/heads/main' && status=='active'].{ID:pullRequestId, Title:title, Author:createdBy.displayName}"
undefinedaz repos pr list --query "[?targetRefName=='refs/heads/main' && status=='active'].{ID:pullRequestId, Title:title, Author:createdBy.displayName}"
undefinedAliases and Functions
别名与函数
bash
undefinedbash
undefinedCreate shell aliases for common commands
Create shell aliases for common commands
alias azdo-pipelines="az pipelines list --output table"
alias azdo-prs="az repos pr list --status active --output table"
alias azdo-builds="az pipelines runs list --top 20 --output table"
alias azdo-pipelines="az pipelines list --output table"
alias azdo-prs="az repos pr list --status active --output table"
alias azdo-builds="az pipelines runs list --top 20 --output table"
Function for quick PR creation
Function for quick PR creation
azdo-pr() {
az repos pr create --source-branch "$(git branch --show-current)" --target-branch main --title "$1" --open
}
undefinedazdo-pr() {
az repos pr create --source-branch "$(git branch --show-current)" --target-branch main --title "$1" --open
}
undefinedExtended Content
扩展内容
For comprehensive command references and advanced workflows, see:
- Complete Command References: ,
examples/pipelines-reference.md,examples/boards-reference.md,examples/repos-reference.mdexamples/artifacts-reference.md - Advanced Workflows: ,
examples/workflows/ci-cd-automation.md,examples/workflows/release-management.mdexamples/workflows/team-collaboration.md - Testing Scenarios:
tests/test-scenarios.md
如需完整的命令参考和高级工作流,请查看:
- 完整命令参考:、
examples/pipelines-reference.md、examples/boards-reference.md、examples/repos-reference.mdexamples/artifacts-reference.md - 高级工作流:、
examples/workflows/ci-cd-automation.md、examples/workflows/release-management.mdexamples/workflows/team-collaboration.md - 测试场景:
tests/test-scenarios.md
References
参考资料
- Azure DevOps CLI Documentation: https://learn.microsoft.com/en-us/cli/azure/devops
- WIQL Syntax: https://learn.microsoft.com/en-us/azure/devops/boards/queries/wiql-syntax
- REST API: https://learn.microsoft.com/en-us/rest/api/azure/devops