azure-devops-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAzure DevOps CLI
Azure DevOps CLI
This Skill helps manage Azure DevOps resources using the Azure CLI with Azure DevOps extension.
CLI Version: 2.81.0 (current as of 2025)
本指南帮助你使用带有Azure DevOps扩展的Azure CLI来管理Azure DevOps资源。
CLI版本: 2.81.0(截至2025年为当前版本)
Prerequisites
前提条件
Install Azure CLI and Azure DevOps extension:
bash
undefined安装Azure CLI和Azure DevOps扩展:
bash
undefinedInstall Azure CLI
Install Azure CLI
brew install azure-cli # macOS
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # Linux
pip install azure-cli # via pip
brew install azure-cli # macOS
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # Linux
pip install azure-cli # via pip
Verify installation
Verify installation
az --version
az --version
Install Azure DevOps extension
Install Azure DevOps extension
az extension add --name azure-devops
az extension show --name azure-devops
undefinedaz extension add --name azure-devops
az extension show --name azure-devops
undefinedCLI Structure
CLI结构
az devops # Main DevOps commands
├── admin # Administration (banner)
├── extension # Extension management
├── project # Team projects
├── security # Security operations
│ ├── group # Security groups
│ └── permission # Security permissions
├── service-endpoint # Service connections
├── team # Teams
├── user # Users
├── wiki # Wikis
├── configure # Set defaults
├── invoke # Invoke REST API
├── login # Authenticate
└── logout # Clear credentials
az pipelines # Azure Pipelines
├── agent # Agents
├── build # Builds
├── folder # Pipeline folders
├── pool # Agent pools
├── queue # Agent queues
├── release # Releases
├── runs # Pipeline runs
├── variable # Pipeline variables
└── variable-group # Variable groups
az boards # Azure Boards
├── area # Area paths
├── iteration # Iterations
└── work-item # Work items
az repos # Azure Repos
├── import # Git imports
├── policy # Branch policies
├── pr # Pull requests
└── ref # Git references
az artifacts # Azure Artifacts
└── universal # Universal Packages
├── download # Download packages
└── publish # Publish packagesaz devops # 主DevOps命令
├── admin # 管理功能(横幅)
├── extension # 扩展管理
├── project # 团队项目
├── security # 安全操作
│ ├── group # 安全组
│ └── permission # 安全权限
├── service-endpoint # 服务连接
├── team # 团队
├── user # 用户
├── wiki # 维基
├── configure # 设置默认值
├── invoke # 调用REST API
├── login # 身份验证
└── logout # 清除凭据
az pipelines # Azure流水线
├── agent # 代理
├── build # 构建
├── folder # 流水线文件夹
├── pool # 代理池
├── queue # 代理队列
├── release # 发布
├── runs # 流水线运行
├── variable # 流水线变量
└── variable-group # 变量组
az boards # Azure Boards
├── area # 区域路径
├── iteration # 迭代
└── work-item # 工作项
az repos # Azure代码库
├── import # Git导入
├── policy # 分支策略
├── pr # 拉取请求
└── ref # Git引用
az artifacts # Azure制品
└── universal # 通用包
├── download # 下载包
└── publish # 发布包Authentication
身份验证
Login to Azure DevOps
登录Azure DevOps
bash
undefinedbash
undefinedInteractive login (prompts for PAT)
交互式登录(提示输入PAT)
az devops login --organization https://dev.azure.com/{org}
az devops login --organization https://dev.azure.com/{org}
Login with PAT token
使用PAT令牌登录
az devops login --organization https://dev.azure.com/{org} --token YOUR_PAT_TOKEN
az devops login --organization https://dev.azure.com/{org} --token YOUR_PAT_TOKEN
Logout
登出
az devops logout --organization https://dev.azure.com/{org}
undefinedaz devops logout --organization https://dev.azure.com/{org}
undefinedConfigure Defaults
配置默认值
bash
undefinedbash
undefinedSet default organization and project
设置默认组织和项目
az devops configure --defaults organization=https://dev.azure.com/{org} project={project}
az devops configure --defaults organization=https://dev.azure.com/{org} project={project}
List current configuration
列出当前配置
az devops configure --list
az devops configure --list
Enable Git aliases
启用Git别名
az devops configure --use-git-aliases true
undefinedaz devops configure --use-git-aliases true
undefinedExtension Management
扩展管理
List Extensions
列出扩展
bash
undefinedbash
undefinedList available extensions
列出可用扩展
az extension list-available --output table
az extension list-available --output table
List installed extensions
列出已安装扩展
az extension list --output table
undefinedaz extension list --output table
undefinedManage Azure DevOps Extension
管理Azure DevOps扩展
bash
undefinedbash
undefinedInstall Azure DevOps extension
安装Azure DevOps扩展
az extension add --name azure-devops
az extension add --name azure-devops
Update Azure DevOps extension
更新Azure DevOps扩展
az extension update --name azure-devops
az extension update --name azure-devops
Remove extension
移除扩展
az extension remove --name azure-devops
az extension remove --name azure-devops
Install from local path
从本地路径安装
az extension add --source ~/extensions/azure-devops.whl
undefinedaz extension add --source ~/extensions/azure-devops.whl
undefinedProjects
项目
List Projects
列出项目
bash
az devops project list --organization https://dev.azure.com/{org}
az devops project list --top 10 --output tablebash
az devops project list --organization https://dev.azure.com/{org}
az devops project list --top 10 --output tableCreate Project
创建项目
bash
az devops project create \
--name myNewProject \
--organization https://dev.azure.com/{org} \
--description "My new DevOps project" \
--source-control git \
--visibility privatebash
az devops project create \
--name myNewProject \
--organization https://dev.azure.com/{org} \
--description "My new DevOps project" \
--source-control git \
--visibility privateShow Project Details
查看项目详情
bash
az devops project show --project {project-name} --org https://dev.azure.com/{org}bash
az devops project show --project {project-name} --org https://dev.azure.com/{org}Delete Project
删除项目
bash
az devops project delete --id {project-id} --org https://dev.azure.com/{org} --yesbash
az devops project delete --id {project-id} --org https://dev.azure.com/{org} --yesRepositories
代码库
List Repositories
列出代码库
bash
az repos list --org https://dev.azure.com/{org} --project {project}
az repos list --output tablebash
az repos list --org https://dev.azure.com/{org} --project {project}
az repos list --output tableShow Repository Details
查看代码库详情
bash
az repos show --repository {repo-name} --project {project}bash
az repos show --repository {repo-name} --project {project}Create Repository
创建代码库
bash
az repos create --name {repo-name} --project {project}bash
az repos create --name {repo-name} --project {project}Delete Repository
删除代码库
bash
az repos delete --id {repo-id} --project {project} --yesbash
az repos delete --id {repo-id} --project {project} --yesUpdate Repository
更新代码库
bash
az repos update --id {repo-id} --name {new-name} --project {project}bash
az repos update --id {repo-id} --name {new-name} --project {project}Repository Import
代码库导入
Import Git Repository
导入Git代码库
bash
undefinedbash
undefinedImport from public Git repository
从公共Git代码库导入
Import with authentication
带身份验证的导入
az repos import create
--git-source-url https://github.com/user/private-repo
--repository {repo-name}
--user {username}
--password {password-or-pat}
--git-source-url https://github.com/user/private-repo
--repository {repo-name}
--user {username}
--password {password-or-pat}
undefinedaz repos import create
--git-source-url https://github.com/user/private-repo
--repository {repo-name}
--user {username}
--password {password-or-pat}
--git-source-url https://github.com/user/private-repo
--repository {repo-name}
--user {username}
--password {password-or-pat}
undefinedPull Requests
拉取请求
Create Pull Request
创建拉取请求
bash
undefinedbash
undefinedBasic PR creation
基础PR创建
az repos pr create
--repository {repo}
--source-branch {source-branch}
--target-branch {target-branch}
--title "PR Title"
--description "PR description"
--open
--repository {repo}
--source-branch {source-branch}
--target-branch {target-branch}
--title "PR Title"
--description "PR description"
--open
az repos pr create
--repository {repo}
--source-branch {source-branch}
--target-branch {target-branch}
--title "PR Title"
--description "PR description"
--open
--repository {repo}
--source-branch {source-branch}
--target-branch {target-branch}
--title "PR Title"
--description "PR description"
--open
PR with work items
关联工作项的PR
az repos pr create
--repository {repo}
--source-branch {source-branch}
--work-items 63 64
--repository {repo}
--source-branch {source-branch}
--work-items 63 64
az repos pr create
--repository {repo}
--source-branch {source-branch}
--work-items 63 64
--repository {repo}
--source-branch {source-branch}
--work-items 63 64
Draft PR with reviewers
带审阅者的草稿PR
az repos pr create
--repository {repo}
--source-branch feature/new-feature
--target-branch main
--title "Feature: New functionality"
--draft true
--reviewers user1@example.com user2@example.com
--required-reviewers lead@example.com
--labels "enhancement" "backlog"
--repository {repo}
--source-branch feature/new-feature
--target-branch main
--title "Feature: New functionality"
--draft true
--reviewers user1@example.com user2@example.com
--required-reviewers lead@example.com
--labels "enhancement" "backlog"
undefinedaz repos pr create
--repository {repo}
--source-branch feature/new-feature
--target-branch main
--title "Feature: New functionality"
--draft true
--reviewers user1@example.com user2@example.com
--required-reviewers lead@example.com
--labels "enhancement" "backlog"
--repository {repo}
--source-branch feature/new-feature
--target-branch main
--title "Feature: New functionality"
--draft true
--reviewers user1@example.com user2@example.com
--required-reviewers lead@example.com
--labels "enhancement" "backlog"
undefinedList Pull Requests
列出拉取请求
bash
undefinedbash
undefinedAll PRs
所有PR
az repos pr list --repository {repo}
az repos pr list --repository {repo}
Filter by status
按状态筛选
az repos pr list --repository {repo} --status active
az repos pr list --repository {repo} --status active
Filter by creator
按创建者筛选
az repos pr list --repository {repo} --creator {email}
az repos pr list --repository {repo} --creator {email}
Output as table
表格格式输出
az repos pr list --repository {repo} --output table
undefinedaz repos pr list --repository {repo} --output table
undefinedShow PR Details
查看PR详情
bash
az repos pr show --id {pr-id}
az repos pr show --id {pr-id} --open # Open in browserbash
az repos pr show --id {pr-id}
az repos pr show --id {pr-id} --open # 在浏览器中打开Update PR (Complete/Abandon/Draft)
更新PR(完成/放弃/草稿)
bash
undefinedbash
undefinedComplete PR
完成PR
az repos pr update --id {pr-id} --status completed
az repos pr update --id {pr-id} --status completed
Abandon PR
放弃PR
az repos pr update --id {pr-id} --status abandoned
az repos pr update --id {pr-id} --status abandoned
Set to draft
设置为草稿
az repos pr update --id {pr-id} --draft true
az repos pr update --id {pr-id} --draft true
Publish draft PR
发布草稿PR
az repos pr update --id {pr-id} --draft false
az repos pr update --id {pr-id} --draft false
Auto-complete when policies pass
策略通过后自动完成
az repos pr update --id {pr-id} --auto-complete true
az repos pr update --id {pr-id} --auto-complete true
Set title and description
设置标题和描述
az repos pr update --id {pr-id} --title "New title" --description "New description"
undefinedaz repos pr update --id {pr-id} --title "New title" --description "New description"
undefinedCheckout PR Locally
本地检出PR
bash
undefinedbash
undefinedCheckout PR branch
检出PR分支
az repos pr checkout --id {pr-id}
az repos pr checkout --id {pr-id}
Checkout with specific remote
使用特定远程检出
az repos pr checkout --id {pr-id} --remote-name upstream
undefinedaz repos pr checkout --id {pr-id} --remote-name upstream
undefinedVote on PR
对PR投票
bash
az repos pr set-vote --id {pr-id} --vote approve
az repos pr set-vote --id {pr-id} --vote approve-with-suggestions
az repos pr set-vote --id {pr-id} --vote reject
az repos pr set-vote --id {pr-id} --vote wait-for-author
az repos pr set-vote --id {pr-id} --vote resetbash
az repos pr set-vote --id {pr-id} --vote approve
az repos pr set-vote --id {pr-id} --vote approve-with-suggestions
az repos pr set-vote --id {pr-id} --vote reject
az repos pr set-vote --id {pr-id} --vote wait-for-author
az repos pr set-vote --id {pr-id} --vote resetPR Reviewers
PR审阅者
bash
undefinedbash
undefinedAdd reviewers
添加审阅者
az repos pr reviewer add --id {pr-id} --reviewers user1@example.com user2@example.com
az repos pr reviewer add --id {pr-id} --reviewers user1@example.com user2@example.com
List reviewers
列出审阅者
az repos pr reviewer list --id {pr-id}
az repos pr reviewer list --id {pr-id}
Remove reviewers
移除审阅者
az repos pr reviewer remove --id {pr-id} --reviewers user1@example.com
undefinedaz repos pr reviewer remove --id {pr-id} --reviewers user1@example.com
undefinedPR Work Items
PR工作项
bash
undefinedbash
undefinedAdd work items to PR
为PR添加工作项
az repos pr work-item add --id {pr-id} --work-items {id1} {id2}
az repos pr work-item add --id {pr-id} --work-items {id1} {id2}
List PR work items
列出PR关联的工作项
az repos pr work-item list --id {pr-id}
az repos pr work-item list --id {pr-id}
Remove work items from PR
从PR中移除工作项
az repos pr work-item remove --id {pr-id} --work-items {id1}
undefinedaz repos pr work-item remove --id {pr-id} --work-items {id1}
undefinedPR Policies
PR策略
bash
undefinedbash
undefinedList policies for a PR
列出PR的策略
az repos pr policy list --id {pr-id}
az repos pr policy list --id {pr-id}
Queue policy evaluation for a PR
为PR排队策略评估
az repos pr policy queue --id {pr-id} --evaluation-id {evaluation-id}
undefinedaz repos pr policy queue --id {pr-id} --evaluation-id {evaluation-id}
undefinedPipelines
流水线
List Pipelines
列出流水线
bash
az pipelines list --output table
az pipelines list --query "[?name=='myPipeline']"
az pipelines list --folder-path 'folder/subfolder'bash
az pipelines list --output table
az pipelines list --query "[?name=='myPipeline']"
az pipelines list --folder-path 'folder/subfolder'Create Pipeline
创建流水线
bash
undefinedbash
undefinedFrom local repository context (auto-detects settings)
从本地代码库上下文创建(自动检测设置)
az pipelines create --name 'ContosoBuild' --description 'Pipeline for contoso project'
az pipelines create --name 'ContosoBuild' --description 'Pipeline for contoso project'
With specific branch and YAML path
指定分支和YAML路径创建
az pipelines create
--name {pipeline-name}
--repository {repo}
--branch main
--yaml-path azure-pipelines.yml
--description "My CI/CD pipeline"
--name {pipeline-name}
--repository {repo}
--branch main
--yaml-path azure-pipelines.yml
--description "My CI/CD pipeline"
az pipelines create
--name {pipeline-name}
--repository {repo}
--branch main
--yaml-path azure-pipelines.yml
--description "My CI/CD pipeline"
--name {pipeline-name}
--repository {repo}
--branch main
--yaml-path azure-pipelines.yml
--description "My CI/CD pipeline"
For GitHub repository
为GitHub代码库创建
az pipelines create
--name 'GitHubPipeline'
--repository https://github.com/Org/Repo
--branch main
--repository-type github
--name 'GitHubPipeline'
--repository https://github.com/Org/Repo
--branch main
--repository-type github
az pipelines create
--name 'GitHubPipeline'
--repository https://github.com/Org/Repo
--branch main
--repository-type github
--name 'GitHubPipeline'
--repository https://github.com/Org/Repo
--branch main
--repository-type github
Skip first run
跳过首次运行
az pipelines create --name 'MyPipeline' --skip-run true
undefinedaz pipelines create --name 'MyPipeline' --skip-run true
undefinedShow Pipeline
查看流水线
bash
az pipelines show --id {pipeline-id}
az pipelines show --name {pipeline-name}bash
az pipelines show --id {pipeline-id}
az pipelines show --name {pipeline-name}Update Pipeline
更新流水线
bash
az pipelines update --id {pipeline-id} --name "New name" --description "Updated description"bash
az pipelines update --id {pipeline-id} --name "New name" --description "Updated description"Delete Pipeline
删除流水线
bash
az pipelines delete --id {pipeline-id} --yesbash
az pipelines delete --id {pipeline-id} --yesRun Pipeline
运行流水线
bash
undefinedbash
undefinedRun by name
按名称运行
az pipelines run --name {pipeline-name} --branch main
az pipelines run --name {pipeline-name} --branch main
Run by ID
按ID运行
az pipelines run --id {pipeline-id} --branch refs/heads/main
az pipelines run --id {pipeline-id} --branch refs/heads/main
With parameters
带参数运行
az pipelines run --name {pipeline-name} --parameters version=1.0.0 environment=prod
az pipelines run --name {pipeline-name} --parameters version=1.0.0 environment=prod
With variables
带变量运行
az pipelines run --name {pipeline-name} --variables buildId=123 configuration=release
az pipelines run --name {pipeline-name} --variables buildId=123 configuration=release
Open results in browser
在浏览器中打开结果
az pipelines run --name {pipeline-name} --open
undefinedaz pipelines run --name {pipeline-name} --open
undefinedPipeline Runs
流水线运行
List Runs
列出运行记录
bash
az pipelines runs list --pipeline {pipeline-id}
az pipelines runs list --name {pipeline-name} --top 10
az pipelines runs list --branch main --status completedbash
az pipelines runs list --pipeline {pipeline-id}
az pipelines runs list --name {pipeline-name} --top 10
az pipelines runs list --branch main --status completedShow Run Details
查看运行详情
bash
az pipelines runs show --run-id {run-id}
az pipelines runs show --run-id {run-id} --openbash
az pipelines runs show --run-id {run-id}
az pipelines runs show --run-id {run-id} --openPipeline Artifacts
流水线制品
bash
undefinedbash
undefinedList artifacts for a run
列出某次运行的制品
az pipelines runs artifact list --run-id {run-id}
az pipelines runs artifact list --run-id {run-id}
Download artifact
下载制品
az pipelines runs artifact download
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
az pipelines runs artifact download
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
Upload artifact
上传制品
az pipelines runs artifact upload
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
undefinedaz pipelines runs artifact upload
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
--artifact-name '{artifact-name}'
--path {local-path}
--run-id {run-id}
undefinedPipeline Run Tags
流水线运行标签
bash
undefinedbash
undefinedAdd tag to run
为运行添加标签
az pipelines runs tag add --run-id {run-id} --tags production v1.0
az pipelines runs tag add --run-id {run-id} --tags production v1.0
List run tags
列出运行标签
az pipelines runs tag list --run-id {run-id} --output table
undefinedaz pipelines runs tag list --run-id {run-id} --output table
undefinedBuilds
构建
List Builds
列出构建
bash
az pipelines build list
az pipelines build list --definition {build-definition-id}
az pipelines build list --status completed --result succeededbash
az pipelines build list
az pipelines build list --definition {build-definition-id}
az pipelines build list --status completed --result succeededQueue Build
排队构建
bash
az pipelines build queue --definition {build-definition-id} --branch main
az pipelines build queue --definition {build-definition-id} --parameters version=1.0.0bash
az pipelines build queue --definition {build-definition-id} --branch main
az pipelines build queue --definition {build-definition-id} --parameters version=1.0.0Show Build Details
查看构建详情
bash
az pipelines build show --id {build-id}bash
az pipelines build show --id {build-id}Cancel Build
取消构建
bash
az pipelines build cancel --id {build-id}bash
az pipelines build cancel --id {build-id}Build Tags
构建标签
bash
undefinedbash
undefinedAdd tag to build
为构建添加标签
az pipelines build tag add --build-id {build-id} --tags prod release
az pipelines build tag add --build-id {build-id} --tags prod release
Delete tag from build
从构建中删除标签
az pipelines build tag delete --build-id {build-id} --tag prod
undefinedaz pipelines build tag delete --build-id {build-id} --tag prod
undefinedBuild Definitions
构建定义
List Build Definitions
列出构建定义
bash
az pipelines build definition list
az pipelines build definition list --name {definition-name}bash
az pipelines build definition list
az pipelines build definition list --name {definition-name}Show Build Definition
查看构建定义
bash
az pipelines build definition show --id {definition-id}bash
az pipelines build definition show --id {definition-id}Releases
发布
List Releases
列出发布
bash
az pipelines release list
az pipelines release list --definition {release-definition-id}bash
az pipelines release list
az pipelines release list --definition {release-definition-id}Create Release
创建发布
bash
az pipelines release create --definition {release-definition-id}
az pipelines release create --definition {release-definition-id} --description "Release v1.0"bash
az pipelines release create --definition {release-definition-id}
az pipelines release create --definition {release-definition-id} --description "Release v1.0"Show Release
查看发布
bash
az pipelines release show --id {release-id}bash
az pipelines release show --id {release-id}Release Definitions
发布定义
List Release Definitions
列出发布定义
bash
az pipelines release definition listbash
az pipelines release definition listShow Release Definition
查看发布定义
bash
az pipelines release definition show --id {definition-id}bash
az pipelines release definition show --id {definition-id}Pipeline Variables
流水线变量
List Variables
列出变量
bash
az pipelines variable list --pipeline-id {pipeline-id}bash
az pipelines variable list --pipeline-id {pipeline-id}Create Variable
创建变量
bash
undefinedbash
undefinedNon-secret variable
非机密变量
az pipelines variable create
--name {var-name}
--value {var-value}
--pipeline-id {pipeline-id}
--name {var-name}
--value {var-value}
--pipeline-id {pipeline-id}
az pipelines variable create
--name {var-name}
--value {var-value}
--pipeline-id {pipeline-id}
--name {var-name}
--value {var-value}
--pipeline-id {pipeline-id}
Secret variable
机密变量
az pipelines variable create
--name {var-name}
--secret true
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--pipeline-id {pipeline-id}
az pipelines variable create
--name {var-name}
--secret true
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--pipeline-id {pipeline-id}
Secret with prompt
带提示的机密变量
az pipelines variable create
--name {var-name}
--secret true
--prompt true
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--prompt true
--pipeline-id {pipeline-id}
undefinedaz pipelines variable create
--name {var-name}
--secret true
--prompt true
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--prompt true
--pipeline-id {pipeline-id}
undefinedUpdate Variable
更新变量
bash
az pipelines variable update \
--name {var-name} \
--value {new-value} \
--pipeline-id {pipeline-id}bash
az pipelines variable update \
--name {var-name} \
--value {new-value} \
--pipeline-id {pipeline-id}Update secret variable
更新机密变量
az pipelines variable update
--name {var-name}
--secret true
--value "{new-secret-value}"
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--value "{new-secret-value}"
--pipeline-id {pipeline-id}
undefinedaz pipelines variable update
--name {var-name}
--secret true
--value "{new-secret-value}"
--pipeline-id {pipeline-id}
--name {var-name}
--secret true
--value "{new-secret-value}"
--pipeline-id {pipeline-id}
undefinedDelete Variable
删除变量
bash
az pipelines variable delete --name {var-name} --pipeline-id {pipeline-id} --yesbash
az pipelines variable delete --name {var-name} --pipeline-id {pipeline-id} --yesVariable Groups
变量组
List Variable Groups
列出变量组
bash
az pipelines variable-group list
az pipelines variable-group list --output tablebash
az pipelines variable-group list
az pipelines variable-group list --output tableShow Variable Group
查看变量组
bash
az pipelines variable-group show --id {group-id}bash
az pipelines variable-group show --id {group-id}Create Variable Group
创建变量组
bash
az pipelines variable-group create \
--name {group-name} \
--variables key1=value1 key2=value2 \
--authorize truebash
az pipelines variable-group create \
--name {group-name} \
--variables key1=value1 key2=value2 \
--authorize trueUpdate Variable Group
更新变量组
bash
az pipelines variable-group update \
--id {group-id} \
--name {new-name} \
--description "Updated description"bash
az pipelines variable-group update \
--id {group-id} \
--name {new-name} \
--description "Updated description"Delete Variable Group
删除变量组
bash
az pipelines variable-group delete --id {group-id} --yesbash
az pipelines variable-group delete --id {group-id} --yesVariable Group Variables
变量组变量
List Variables
列出变量
bash
az pipelines variable-group variable list --group-id {group-id}bash
az pipelines variable-group variable list --group-id {group-id}Create Variable
创建变量
bash
undefinedbash
undefinedNon-secret variable
非机密变量
az pipelines variable-group variable create
--group-id {group-id}
--name {var-name}
--value {var-value}
--group-id {group-id}
--name {var-name}
--value {var-value}
az pipelines variable-group variable create
--group-id {group-id}
--name {var-name}
--value {var-value}
--group-id {group-id}
--name {var-name}
--value {var-value}
Secret variable (will prompt for value if not provided)
机密变量(如果未提供值会提示输入)
az pipelines variable-group variable create
--group-id {group-id}
--name {var-name}
--secret true
--group-id {group-id}
--name {var-name}
--secret true
az pipelines variable-group variable create
--group-id {group-id}
--name {var-name}
--secret true
--group-id {group-id}
--name {var-name}
--secret true
Secret with environment variable
使用环境变量的机密变量
export AZURE_DEVOPS_EXT_PIPELINE_VAR_MySecret=secretvalue
az pipelines variable-group variable create
--group-id {group-id}
--name MySecret
--secret true
--group-id {group-id}
--name MySecret
--secret true
undefinedexport AZURE_DEVOPS_EXT_PIPELINE_VAR_MySecret=secretvalue
az pipelines variable-group variable create
--group-id {group-id}
--name MySecret
--secret true
--group-id {group-id}
--name MySecret
--secret true
undefinedUpdate Variable
更新变量
bash
az pipelines variable-group variable update \
--group-id {group-id} \
--name {var-name} \
--value {new-value} \
--secret falsebash
az pipelines variable-group variable update \
--group-id {group-id} \
--name {var-name} \
--value {new-value} \
--secret falseDelete Variable
删除变量
bash
az pipelines variable-group variable delete \
--group-id {group-id} \
--name {var-name}bash
az pipelines variable-group variable delete \
--group-id {group-id} \
--name {var-name}Pipeline Folders
流水线文件夹
List Folders
列出文件夹
bash
az pipelines folder listbash
az pipelines folder listCreate Folder
创建文件夹
bash
az pipelines folder create --path 'folder/subfolder' --description "My folder"bash
az pipelines folder create --path 'folder/subfolder' --description "My folder"Delete Folder
删除文件夹
bash
az pipelines folder delete --path 'folder/subfolder'bash
az pipelines folder delete --path 'folder/subfolder'Update Folder
更新文件夹
bash
az pipelines folder update --path 'old-folder' --new-path 'new-folder'bash
az pipelines folder update --path 'old-folder' --new-path 'new-folder'Agent Pools
代理池
List Agent Pools
列出代理池
bash
az pipelines pool list
az pipelines pool list --pool-type automation
az pipelines pool list --pool-type deploymentbash
az pipelines pool list
az pipelines pool list --pool-type automation
az pipelines pool list --pool-type deploymentShow Agent Pool
查看代理池
bash
az pipelines pool show --pool-id {pool-id}bash
az pipelines pool show --pool-id {pool-id}Agent Queues
代理队列
List Agent Queues
列出代理队列
bash
az pipelines queue list
az pipelines queue list --pool-name {pool-name}bash
az pipelines queue list
az pipelines queue list --pool-name {pool-name}Show Agent Queue
查看代理队列
bash
az pipelines queue show --id {queue-id}bash
az pipelines queue show --id {queue-id}Work Items (Boards)
工作项(Boards)
Query Work Items
查询工作项
bash
undefinedbash
undefinedWIQL query
WIQL查询
az boards query
--wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.AssignedTo] = @Me AND [System.State] = 'Active'"
--wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.AssignedTo] = @Me AND [System.State] = 'Active'"
az boards query
--wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.AssignedTo] = @Me AND [System.State] = 'Active'"
--wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.AssignedTo] = @Me AND [System.State] = 'Active'"
Query with output format
指定输出格式的查询
az boards query --wiql "SELECT * FROM WorkItems" --output table
undefinedaz boards query --wiql "SELECT * FROM WorkItems" --output table
undefinedShow Work Item
查看工作项
bash
az boards work-item show --id {work-item-id}
az boards work-item show --id {work-item-id} --openbash
az boards work-item show --id {work-item-id}
az boards work-item show --id {work-item-id} --openCreate Work Item
创建工作项
bash
undefinedbash
undefinedBasic work item
基础工作项
az boards work-item create
--title "Fix login bug"
--type Bug
--assigned-to user@example.com
--description "Users cannot login with SSO"
--title "Fix login bug"
--type Bug
--assigned-to user@example.com
--description "Users cannot login with SSO"
az boards work-item create
--title "Fix login bug"
--type Bug
--assigned-to user@example.com
--description "Users cannot login with SSO"
--title "Fix login bug"
--type Bug
--assigned-to user@example.com
--description "Users cannot login with SSO"
With area and iteration
带区域和迭代的工作项
az boards work-item create
--title "New feature"
--type "User Story"
--area "Project\Area1"
--iteration "Project\Sprint 1"
--title "New feature"
--type "User Story"
--area "Project\Area1"
--iteration "Project\Sprint 1"
az boards work-item create
--title "New feature"
--type "User Story"
--area "Project\Area1"
--iteration "Project\Sprint 1"
--title "New feature"
--type "User Story"
--area "Project\Area1"
--iteration "Project\Sprint 1"
With custom fields
带自定义字段的工作项
az boards work-item create
--title "Task"
--type Task
--fields "Priority=1" "Severity=2"
--title "Task"
--type Task
--fields "Priority=1" "Severity=2"
az boards work-item create
--title "Task"
--type Task
--fields "Priority=1" "Severity=2"
--title "Task"
--type Task
--fields "Priority=1" "Severity=2"
With discussion comment
带讨论评论的工作项
az boards work-item create
--title "Issue"
--type Bug
--discussion "Initial investigation completed"
--title "Issue"
--type Bug
--discussion "Initial investigation completed"
az boards work-item create
--title "Issue"
--type Bug
--discussion "Initial investigation completed"
--title "Issue"
--type Bug
--discussion "Initial investigation completed"
Open in browser after creation
创建后在浏览器中打开
az boards work-item create --title "Bug" --type Bug --open
undefinedaz boards work-item create --title "Bug" --type Bug --open
undefinedUpdate Work Item
更新工作项
bash
undefinedbash
undefinedUpdate state, title, and assignee
更新状态、标题和经办人
az boards work-item update
--id {work-item-id}
--state "Active"
--title "Updated title"
--assigned-to user@example.com
--id {work-item-id}
--state "Active"
--title "Updated title"
--assigned-to user@example.com
az boards work-item update
--id {work-item-id}
--state "Active"
--title "Updated title"
--assigned-to user@example.com
--id {work-item-id}
--state "Active"
--title "Updated title"
--assigned-to user@example.com
Move to different area
移动到不同区域
az boards work-item update
--id {work-item-id}
--area "{ProjectName}\{Team}\{Area}"
--id {work-item-id}
--area "{ProjectName}\{Team}\{Area}"
az boards work-item update
--id {work-item-id}
--area "{ProjectName}\{Team}\{Area}"
--id {work-item-id}
--area "{ProjectName}\{Team}\{Area}"
Change iteration
更改迭代
az boards work-item update
--id {work-item-id}
--iteration "{ProjectName}\Sprint 5"
--id {work-item-id}
--iteration "{ProjectName}\Sprint 5"
az boards work-item update
--id {work-item-id}
--iteration "{ProjectName}\Sprint 5"
--id {work-item-id}
--iteration "{ProjectName}\Sprint 5"
Add comment/discussion
添加评论/讨论
az boards work-item update
--id {work-item-id}
--discussion "Work in progress"
--id {work-item-id}
--discussion "Work in progress"
az boards work-item update
--id {work-item-id}
--discussion "Work in progress"
--id {work-item-id}
--discussion "Work in progress"
Update with custom fields
更新自定义字段
az boards work-item update
--id {work-item-id}
--fields "Priority=1" "StoryPoints=5"
--id {work-item-id}
--fields "Priority=1" "StoryPoints=5"
undefinedaz boards work-item update
--id {work-item-id}
--fields "Priority=1" "StoryPoints=5"
--id {work-item-id}
--fields "Priority=1" "StoryPoints=5"
undefinedDelete Work Item
删除工作项
bash
undefinedbash
undefinedSoft delete (can be restored)
软删除(可恢复)
az boards work-item delete --id {work-item-id} --yes
az boards work-item delete --id {work-item-id} --yes
Permanent delete
永久删除
az boards work-item delete --id {work-item-id} --destroy --yes
undefinedaz boards work-item delete --id {work-item-id} --destroy --yes
undefinedWork Item Relations
工作项关联
bash
undefinedbash
undefinedList relations
列出关联
az boards work-item relation list --id {work-item-id}
az boards work-item relation list --id {work-item-id}
List supported relation types
列出支持的关联类型
az boards work-item relation list-type
az boards work-item relation list-type
Add relation
添加关联
az boards work-item relation add --id {work-item-id} --relation-type parent --target-id {parent-id}
az boards work-item relation add --id {work-item-id} --relation-type parent --target-id {parent-id}
Remove relation
移除关联
az boards work-item relation remove --id {work-item-id} --relation-id {relation-id}
undefinedaz boards work-item relation remove --id {work-item-id} --relation-id {relation-id}
undefinedArea Paths
区域路径
List Areas for Project
列出项目的区域
bash
az boards area project list --project {project}
az boards area project show --path "Project\\Area1" --project {project}bash
az boards area project list --project {project}
az boards area project show --path "Project\\Area1" --project {project}Create Area
创建区域
bash
az boards area project create --path "Project\\NewArea" --project {project}bash
az boards area project create --path "Project\\NewArea" --project {project}Update Area
更新区域
bash
az boards area project update \
--path "Project\\OldArea" \
--new-path "Project\\UpdatedArea" \
--project {project}bash
az boards area project update \
--path "Project\\OldArea" \
--new-path "Project\\UpdatedArea" \
--project {project}Delete Area
删除区域
bash
az boards area project delete --path "Project\\AreaToDelete" --project {project} --yesbash
az boards area project delete --path "Project\\AreaToDelete" --project {project} --yesArea Team Management
区域团队管理
bash
undefinedbash
undefinedList areas for team
列出团队的区域
az boards area team list --team {team-name} --project {project}
az boards area team list --team {team-name} --project {project}
Add area to team
为团队添加区域
az boards area team add
--team {team-name}
--path "Project\NewArea"
--project {project}
--team {team-name}
--path "Project\NewArea"
--project {project}
az boards area team add
--team {team-name}
--path "Project\NewArea"
--project {project}
--team {team-name}
--path "Project\NewArea"
--project {project}
Remove area from team
从团队中移除区域
az boards area team remove
--team {team-name}
--path "Project\AreaToRemove"
--project {project}
--team {team-name}
--path "Project\AreaToRemove"
--project {project}
az boards area team remove
--team {team-name}
--path "Project\AreaToRemove"
--project {project}
--team {team-name}
--path "Project\AreaToRemove"
--project {project}
Update team area
更新团队区域
az boards area team update
--team {team-name}
--path "Project\Area"
--project {project}
--include-sub-areas true
--team {team-name}
--path "Project\Area"
--project {project}
--include-sub-areas true
undefinedaz boards area team update
--team {team-name}
--path "Project\Area"
--project {project}
--include-sub-areas true
--team {team-name}
--path "Project\Area"
--project {project}
--include-sub-areas true
undefinedIterations
迭代
List Iterations for Project
列出项目的迭代
bash
az boards iteration project list --project {project}
az boards iteration project show --path "Project\\Sprint 1" --project {project}bash
az boards iteration project list --project {project}
az boards iteration project show --path "Project\\Sprint 1" --project {project}Create Iteration
创建迭代
bash
az boards iteration project create --path "Project\\Sprint 1" --project {project}bash
az boards iteration project create --path "Project\\Sprint 1" --project {project}Update Iteration
更新迭代
bash
az boards iteration project update \
--path "Project\\OldSprint" \
--new-path "Project\\NewSprint" \
--project {project}bash
az boards iteration project update \
--path "Project\\OldSprint" \
--new-path "Project\\NewSprint" \
--project {project}Delete Iteration
删除迭代
bash
az boards iteration project delete --path "Project\\OldSprint" --project {project} --yesbash
az boards iteration project delete --path "Project\\OldSprint" --project {project} --yesList Iterations for Team
列出团队的迭代
bash
az boards iteration team list --team {team-name} --project {project}bash
az boards iteration team list --team {team-name} --project {project}Add Iteration to Team
为团队添加迭代
bash
az boards iteration team add \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}bash
az boards iteration team add \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}Remove Iteration from Team
从团队中移除迭代
bash
az boards iteration team remove \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}bash
az boards iteration team remove \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}List Work Items in Iteration
列出迭代中的工作项
bash
az boards iteration team list-work-items \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}bash
az boards iteration team list-work-items \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}Set Default Iteration for Team
设置团队的默认迭代
bash
az boards iteration team set-default-iteration \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}bash
az boards iteration team set-default-iteration \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}Show Default Iteration
查看默认迭代
bash
az boards iteration team show-default-iteration \
--team {team-name} \
--project {project}bash
az boards iteration team show-default-iteration \
--team {team-name} \
--project {project}Set Backlog Iteration for Team
设置团队的待办事项迭代
bash
az boards iteration team set-backlog-iteration \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}bash
az boards iteration team set-backlog-iteration \
--team {team-name} \
--path "Project\\Sprint 1" \
--project {project}Show Backlog Iteration
查看待办事项迭代
bash
az boards iteration team show-backlog-iteration \
--team {team-name} \
--project {project}bash
az boards iteration team show-backlog-iteration \
--team {team-name} \
--project {project}Show Current Iteration
查看当前迭代
bash
az boards iteration team show --team {team-name} --project {project} --timeframe currentbash
az boards iteration team show --team {team-name} --project {project} --timeframe currentGit References
Git引用
List References (Branches)
列出引用(分支)
bash
az repos ref list --repository {repo}
az repos ref list --repository {repo} --query "[?name=='refs/heads/main']"bash
az repos ref list --repository {repo}
az repos ref list --repository {repo} --query "[?name=='refs/heads/main']"Create Reference (Branch)
创建引用(分支)
bash
az repos ref create --name refs/heads/new-branch --object-type commit --object {commit-sha}bash
az repos ref create --name refs/heads/new-branch --object-type commit --object {commit-sha}Delete Reference (Branch)
删除引用(分支)
bash
az repos ref delete --name refs/heads/old-branch --repository {repo} --project {project}bash
az repos ref delete --name refs/heads/old-branch --repository {repo} --project {project}Lock Branch
锁定分支
bash
az repos ref lock --name refs/heads/main --repository {repo} --project {project}bash
az repos ref lock --name refs/heads/main --repository {repo} --project {project}Unlock Branch
解锁分支
bash
az repos ref unlock --name refs/heads/main --repository {repo} --project {project}bash
az repos ref unlock --name refs/heads/main --repository {repo} --project {project}Repository Policies
代码库策略
List All Policies
列出所有策略
bash
az repos policy list --repository {repo-id} --branch mainbash
az repos policy list --repository {repo-id} --branch mainCreate Policy Using Configuration File
使用配置文件创建策略
bash
az repos policy create --config policy.jsonbash
az repos policy create --config policy.jsonUpdate/Delete Policy
更新/删除策略
bash
undefinedbash
undefinedUpdate
更新
az repos policy update --id {policy-id} --config updated-policy.json
az repos policy update --id {policy-id} --config updated-policy.json
Delete
删除
az repos policy delete --id {policy-id} --yes
undefinedaz repos policy delete --id {policy-id} --yes
undefinedPolicy Types
策略类型
Approver Count Policy
审批者数量策略
bash
az repos policy approver-count create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--minimum-approver-count 2 \
--creator-vote-counts truebash
az repos policy approver-count create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--minimum-approver-count 2 \
--creator-vote-counts trueBuild Policy
构建策略
bash
az repos policy build create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--build-definition-id {definition-id} \
--queue-on-source-update-only true \
--valid-duration 720bash
az repos policy build create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--build-definition-id {definition-id} \
--queue-on-source-update-only true \
--valid-duration 720Work Item Linking Policy
工作项关联策略
bash
az repos policy work-item-linking create \
--blocking true \
--branch main \
--enabled true \
--repository-id {repo-id}bash
az repos policy work-item-linking create \
--blocking true \
--branch main \
--enabled true \
--repository-id {repo-id}Required Reviewer Policy
必填审阅者策略
bash
az repos policy required-reviewer create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--required-reviewers user@example.combash
az repos policy required-reviewer create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--required-reviewers user@example.comMerge Strategy Policy
合并策略
bash
az repos policy merge-strategy create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--allow-squash true \
--allow-rebase true \
--allow-no-fast-forward truebash
az repos policy merge-strategy create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--allow-squash true \
--allow-rebase true \
--allow-no-fast-forward trueCase Enforcement Policy
大小写强制策略
bash
az repos policy case-enforcement create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id}bash
az repos policy case-enforcement create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id}Comment Required Policy
评论必填策略
bash
az repos policy comment-required create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id}bash
az repos policy comment-required create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id}File Size Policy
文件大小策略
bash
az repos policy file-size create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--maximum-file-size 10485760 # 10MB in bytesbash
az repos policy file-size create \
--blocking true \
--enabled true \
--branch main \
--repository-id {repo-id} \
--maximum-file-size 10485760 # 10MB in bytesService Endpoints
服务端点
List Service Endpoints
列出服务端点
bash
az devops service-endpoint list --project {project}
az devops service-endpoint list --project {project} --output tablebash
az devops service-endpoint list --project {project}
az devops service-endpoint list --project {project} --output tableShow Service Endpoint
查看服务端点
bash
az devops service-endpoint show --id {endpoint-id} --project {project}bash
az devops service-endpoint show --id {endpoint-id} --project {project}Create Service Endpoint
创建服务端点
bash
undefinedbash
undefinedUsing configuration file
使用配置文件
az devops service-endpoint create --service-endpoint-configuration endpoint.json --project {project}
undefinedaz devops service-endpoint create --service-endpoint-configuration endpoint.json --project {project}
undefinedDelete Service Endpoint
删除服务端点
bash
az devops service-endpoint delete --id {endpoint-id} --project {project} --yesbash
az devops service-endpoint delete --id {endpoint-id} --project {project} --yesTeams
团队
List Teams
列出团队
bash
az devops team list --project {project}bash
az devops team list --project {project}Show Team
查看团队
bash
az devops team show --team {team-name} --project {project}bash
az devops team show --team {team-name} --project {project}Create Team
创建团队
bash
az devops team create \
--name {team-name} \
--description "Team description" \
--project {project}bash
az devops team create \
--name {team-name} \
--description "Team description" \
--project {project}Update Team
更新团队
bash
az devops team update \
--team {team-name} \
--project {project} \
--name "{new-team-name}" \
--description "Updated description"bash
az devops team update \
--team {team-name} \
--project {project} \
--name "{new-team-name}" \
--description "Updated description"Delete Team
删除团队
bash
az devops team delete --team {team-name} --project {project} --yesbash
az devops team delete --team {team-name} --project {project} --yesShow Team Members
查看团队成员
bash
az devops team list-member --team {team-name} --project {project}bash
az devops team list-member --team {team-name} --project {project}Users
用户
List Users
列出用户
bash
az devops user list --org https://dev.azure.com/{org}
az devops user list --top 10 --output tablebash
az devops user list --org https://dev.azure.com/{org}
az devops user list --top 10 --output tableShow User
查看用户
bash
az devops user show --user {user-id-or-email} --org https://dev.azure.com/{org}bash
az devops user show --user {user-id-or-email} --org https://dev.azure.com/{org}Add User
添加用户
bash
az devops user add \
--email user@example.com \
--license-type express \
--org https://dev.azure.com/{org}bash
az devops user add \
--email user@example.com \
--license-type express \
--org https://dev.azure.com/{org}Update User
更新用户
bash
az devops user update \
--user {user-id-or-email} \
--license-type advanced \
--org https://dev.azure.com/{org}bash
az devops user update \
--user {user-id-or-email} \
--license-type advanced \
--org https://dev.azure.com/{org}Remove User
移除用户
bash
az devops user remove --user {user-id-or-email} --org https://dev.azure.com/{org} --yesbash
az devops user remove --user {user-id-or-email} --org https://dev.azure.com/{org} --yesSecurity Groups
安全组
List Groups
列出组
bash
undefinedbash
undefinedList all groups in project
列出项目中的所有组
az devops security group list --project {project}
az devops security group list --project {project}
List all groups in organization
列出组织中的所有组
az devops security group list --scope organization
az devops security group list --scope organization
List with filtering
带筛选的列出
az devops security group list --project {project} --subject-types vstsgroup
undefinedaz devops security group list --project {project} --subject-types vstsgroup
undefinedShow Group Details
查看组详情
bash
az devops security group show --group-id {group-id}bash
az devops security group show --group-id {group-id}Create Group
创建组
bash
az devops security group create \
--name {group-name} \
--description "Group description" \
--project {project}bash
az devops security group create \
--name {group-name} \
--description "Group description" \
--project {project}Update Group
更新组
bash
az devops security group update \
--group-id {group-id} \
--name "{new-group-name}" \
--description "Updated description"bash
az devops security group update \
--group-id {group-id} \
--name "{new-group-name}" \
--description "Updated description"Delete Group
删除组
bash
az devops security group delete --group-id {group-id} --yesbash
az devops security group delete --group-id {group-id} --yesGroup Memberships
组成员
bash
undefinedbash
undefinedList memberships
列出成员
az devops security group membership list --id {group-id}
az devops security group membership list --id {group-id}
Add member
添加成员
az devops security group membership add
--group-id {group-id}
--member-id {member-id}
--group-id {group-id}
--member-id {member-id}
az devops security group membership add
--group-id {group-id}
--member-id {member-id}
--group-id {group-id}
--member-id {member-id}
Remove member
移除成员
az devops security group membership remove
--group-id {group-id}
--member-id {member-id} --yes
--group-id {group-id}
--member-id {member-id} --yes
undefinedaz devops security group membership remove
--group-id {group-id}
--member-id {member-id} --yes
--group-id {group-id}
--member-id {member-id} --yes
undefinedSecurity Permissions
安全权限
List Namespaces
列出命名空间
bash
az devops security permission namespace listbash
az devops security permission namespace listShow Namespace Details
查看命名空间详情
bash
undefinedbash
undefinedShow permissions available in a namespace
查看命名空间中可用的权限
az devops security permission namespace show --namespace "GitRepositories"
undefinedaz devops security permission namespace show --namespace "GitRepositories"
undefinedList Permissions
列出权限
bash
undefinedbash
undefinedList permissions for user/group and namespace
列出用户/组和命名空间的权限
az devops security permission list
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
az devops security permission list
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
List for specific token (repository)
列出特定令牌(代码库)的权限
az devops security permission list
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
undefinedaz devops security permission list
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
undefinedShow Permissions
查看权限
bash
az devops security permission show \
--id {user-or-group-id} \
--namespace "GitRepositories" \
--project {project} \
--token "repoV2/{project}/{repository-id}"bash
az devops security permission show \
--id {user-or-group-id} \
--namespace "GitRepositories" \
--project {project} \
--token "repoV2/{project}/{repository-id}"Update Permissions
更新权限
bash
undefinedbash
undefinedGrant permission
授予权限
az devops security permission update
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
az devops security permission update
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
Deny permission
拒绝权限
az devops security permission update
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask 0
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask 0
undefinedaz devops security permission update
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask 0
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask 0
undefinedReset Permissions
重置权限
bash
undefinedbash
undefinedReset specific permission bits
重置特定权限位
az devops security permission reset
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
az devops security permission reset
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}"
--permission-mask "Pull,Contribute"
Reset all permissions
重置所有权限
az devops security permission reset-all
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}" --yes
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}" --yes
undefinedaz devops security permission reset-all
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}" --yes
--id {user-or-group-id}
--namespace "GitRepositories"
--project {project}
--token "repoV2/{project}/{repository-id}" --yes
undefinedWikis
维基
List Wikis
列出维基
bash
undefinedbash
undefinedList all wikis in project
列出项目中的所有维基
az devops wiki list --project {project}
az devops wiki list --project {project}
List all wikis in organization
列出组织中的所有维基
az devops wiki list
undefinedaz devops wiki list
undefinedShow Wiki
查看维基
bash
az devops wiki show --wiki {wiki-name} --project {project}
az devops wiki show --wiki {wiki-name} --project {project} --openbash
az devops wiki show --wiki {wiki-name} --project {project}
az devops wiki show --wiki {wiki-name} --project {project} --openCreate Wiki
创建维基
bash
undefinedbash
undefinedCreate project wiki
创建项目维基
az devops wiki create
--name {wiki-name}
--project {project}
--type projectWiki
--name {wiki-name}
--project {project}
--type projectWiki
az devops wiki create
--name {wiki-name}
--project {project}
--type projectWiki
--name {wiki-name}
--project {project}
--type projectWiki
Create code wiki from repository
从代码库创建代码维基
az devops wiki create
--name {wiki-name}
--project {project}
--type codeWiki
--repository {repo-name}
--mapped-path /wiki
--name {wiki-name}
--project {project}
--type codeWiki
--repository {repo-name}
--mapped-path /wiki
undefinedaz devops wiki create
--name {wiki-name}
--project {project}
--type codeWiki
--repository {repo-name}
--mapped-path /wiki
--name {wiki-name}
--project {project}
--type codeWiki
--repository {repo-name}
--mapped-path /wiki
undefinedDelete Wiki
删除维基
bash
az devops wiki delete --wiki {wiki-id} --project {project} --yesbash
az devops wiki delete --wiki {wiki-id} --project {project} --yesWiki Pages
维基页面
bash
undefinedbash
undefinedList pages
列出页面
az devops wiki page list --wiki {wiki-name} --project {project}
az devops wiki page list --wiki {wiki-name} --project {project}
Show page
查看页面
az devops wiki page show
--wiki {wiki-name}
--path "/page-name"
--project {project}
--wiki {wiki-name}
--path "/page-name"
--project {project}
az devops wiki page show
--wiki {wiki-name}
--path "/page-name"
--project {project}
--wiki {wiki-name}
--path "/page-name"
--project {project}
Create page
创建页面
az devops wiki page create
--wiki {wiki-name}
--path "/new-page"
--content "# New Page\n\nPage content here..."
--project {project}
--wiki {wiki-name}
--path "/new-page"
--content "# New Page\n\nPage content here..."
--project {project}
az devops wiki page create
--wiki {wiki-name}
--path "/new-page"
--content "# New Page\n\nPage content here..."
--project {project}
--wiki {wiki-name}
--path "/new-page"
--content "# New Page\n\nPage content here..."
--project {project}
Update page
更新页面
az devops wiki page update
--wiki {wiki-name}
--path "/existing-page"
--content "# Updated Page\n\nNew content..."
--project {project}
--wiki {wiki-name}
--path "/existing-page"
--content "# Updated Page\n\nNew content..."
--project {project}
az devops wiki page update
--wiki {wiki-name}
--path "/existing-page"
--content "# Updated Page\n\nNew content..."
--project {project}
--wiki {wiki-name}
--path "/existing-page"
--content "# Updated Page\n\nNew content..."
--project {project}
Delete page
删除页面
az devops wiki page delete
--wiki {wiki-name}
--path "/old-page"
--project {project} --yes
--wiki {wiki-name}
--path "/old-page"
--project {project} --yes
undefinedaz devops wiki page delete
--wiki {wiki-name}
--path "/old-page"
--project {project} --yes
--wiki {wiki-name}
--path "/old-page"
--project {project} --yes
undefinedAdministration
管理功能
Banner Management
横幅管理
bash
undefinedbash
undefinedList banners
列出横幅
az devops admin banner list
az devops admin banner list
Show banner details
查看横幅详情
az devops admin banner show --id {banner-id}
az devops admin banner show --id {banner-id}
Add new banner
添加新横幅
az devops admin banner add
--message "System maintenance scheduled"
--level info # info, warning, error
--message "System maintenance scheduled"
--level info # info, warning, error
az devops admin banner add
--message "System maintenance scheduled"
--level info # info, warning, error
--message "System maintenance scheduled"
--level info # info, warning, error
Update banner
更新横幅
az devops admin banner update
--id {banner-id}
--message "Updated message"
--level warning
--expiration-date "2025-12-31T23:59:59Z"
--id {banner-id}
--message "Updated message"
--level warning
--expiration-date "2025-12-31T23:59:59Z"
az devops admin banner update
--id {banner-id}
--message "Updated message"
--level warning
--expiration-date "2025-12-31T23:59:59Z"
--id {banner-id}
--message "Updated message"
--level warning
--expiration-date "2025-12-31T23:59:59Z"
Remove banner
移除横幅
az devops admin banner remove --id {banner-id}
undefinedaz devops admin banner remove --id {banner-id}
undefinedDevOps Extensions
DevOps扩展
Manage extensions installed in an Azure DevOps organization (different from CLI extensions).
bash
undefined管理Azure DevOps组织中安装的扩展(与CLI扩展不同)。
bash
undefinedList installed extensions
列出已安装的扩展
az devops extension list --org https://dev.azure.com/{org}
az devops extension list --org https://dev.azure.com/{org}
Search marketplace extensions
搜索市场扩展
az devops extension search --search-query "docker"
az devops extension search --search-query "docker"
Show extension details
查看扩展详情
az devops extension show --ext-id {extension-id} --org https://dev.azure.com/{org}
az devops extension show --ext-id {extension-id} --org https://dev.azure.com/{org}
Install extension
安装扩展
az devops extension install
--ext-id {extension-id}
--org https://dev.azure.com/{org}
--publisher {publisher-id}
--ext-id {extension-id}
--org https://dev.azure.com/{org}
--publisher {publisher-id}
az devops extension install
--ext-id {extension-id}
--org https://dev.azure.com/{org}
--publisher {publisher-id}
--ext-id {extension-id}
--org https://dev.azure.com/{org}
--publisher {publisher-id}
Enable extension
启用扩展
Disable extension
禁用扩展
Uninstall extension
卸载扩展
undefinedundefinedUniversal Packages
通用包
Publish Package
发布包
bash
az artifacts universal publish \
--feed {feed-name} \
--name {package-name} \
--version {version} \
--path {package-path} \
--project {project}bash
az artifacts universal publish \
--feed {feed-name} \
--name {package-name} \
--version {version} \
--path {package-path} \
--project {project}Download Package
下载包
bash
az artifacts universal download \
--feed {feed-name} \
--name {package-name} \
--version {version} \
--path {download-path} \
--project {project}bash
az artifacts universal download \
--feed {feed-name} \
--name {package-name} \
--version {version} \
--path {download-path} \
--project {project}Agents
代理
List Agents in Pool
列出池中的代理
bash
az pipelines agent list --pool-id {pool-id}bash
az pipelines agent list --pool-id {pool-id}Show Agent Details
查看代理详情
bash
az pipelines agent show --agent-id {agent-id} --pool-id {pool-id}bash
az pipelines agent show --agent-id {agent-id} --pool-id {pool-id}Git Aliases
Git别名
After enabling git aliases:
bash
undefined启用Git别名后:
bash
undefinedEnable Git aliases
启用Git别名
az devops configure --use-git-aliases true
az devops configure --use-git-aliases true
Use Git commands for DevOps operations
使用Git命令执行DevOps操作
git pr create --target-branch main
git pr list
git pr checkout 123
undefinedgit pr create --target-branch main
git pr list
git pr checkout 123
undefinedOutput Formats
输出格式
All commands support multiple output formats:
bash
undefined所有命令支持多种输出格式:
bash
undefinedTable format (human-readable)
表格格式(人类可读)
az pipelines list --output table
az pipelines list --output table
JSON format (default, machine-readable)
JSON格式(默认,机器可读)
az pipelines list --output json
az pipelines list --output json
JSONC (colored JSON)
JSONC(带颜色的JSON)
az pipelines list --output jsonc
az pipelines list --output jsonc
YAML format
YAML格式
az pipelines list --output yaml
az pipelines list --output yaml
YAMLC (colored YAML)
YAMLC(带颜色的YAML)
az pipelines list --output yamlc
az pipelines list --output yamlc
TSV format (tab-separated values)
TSV格式(制表符分隔值)
az pipelines list --output tsv
az pipelines list --output tsv
None (no output)
无输出
az pipelines list --output none
undefinedaz pipelines list --output none
undefinedJMESPath Queries
JMESPath查询
Filter and transform output:
bash
undefined筛选和转换输出:
bash
undefinedFilter by name
按名称筛选
az pipelines list --query "[?name=='myPipeline']"
az pipelines list --query "[?name=='myPipeline']"
Get specific fields
获取特定字段
az pipelines list --query "[].{Name:name, ID:id}"
az pipelines list --query "[].{Name:name, ID:id}"
Chain queries
链式查询
az pipelines list --query "[?name.contains('CI')].{Name:name, ID:id}" --output table
az pipelines list --query "[?name.contains('CI')].{Name:name, ID:id}" --output table
Get first result
获取第一个结果
az pipelines list --query "[0]"
az pipelines list --query "[0]"
Get top N
获取前N个结果
az pipelines list --query "[0:5]"
undefinedaz pipelines list --query "[0:5]"
undefinedGlobal Arguments
全局参数
Available on all commands:
- /
--help: Show help-h - /
--output: Output format (json, jsonc, none, table, tsv, yaml, yamlc)-o - : JMESPath query string
--query - : Increase logging verbosity
--verbose - : Show all debug logs
--debug - : Only show errors, suppress warnings
--only-show-errors - : Name or ID of subscription
--subscription
所有命令都支持:
- /
--help: 显示帮助-h - /
--output: 输出格式(json, jsonc, none, table, tsv, yaml, yamlc)-o - : JMESPath查询字符串
--query - : 增加日志详细程度
--verbose - : 显示所有调试日志
--debug - : 仅显示错误,抑制警告
--only-show-errors - : 订阅名称或ID
--subscription
Common Parameters
通用参数
| Parameter | Description |
|---|---|
| Azure DevOps organization URL (e.g., |
| Project name or ID |
| Auto-detect organization from git config |
| Skip confirmation prompts |
| Open in web browser |
| 参数 | 描述 |
|---|---|
| Azure DevOps组织URL(例如: |
| 项目名称或ID |
| 从git配置自动检测组织 |
| 跳过确认提示 |
| 在浏览器中打开 |
Common Workflows
常见工作流
Create PR from current branch
从当前分支创建PR
bash
CURRENT_BRANCH=$(git branch --show-current)
az repos pr create \
--source-branch $CURRENT_BRANCH \
--target-branch main \
--title "Feature: $(git log -1 --pretty=%B)" \
--openbash
CURRENT_BRANCH=$(git branch --show-current)
az repos pr create \
--source-branch $CURRENT_BRANCH \
--target-branch main \
--title "Feature: $(git log -1 --pretty=%B)" \
--openCreate work item on pipeline failure
流水线失败时创建工作项
bash
az boards work-item create \
--title "Build $BUILD_BUILDNUMBER failed" \
--type bug \
--org $SYSTEM_TEAMFOUNDATIONCOLLECTIONURI \
--project $SYSTEM_TEAMPROJECTbash
az boards work-item create \
--title "Build $BUILD_BUILDNUMBER failed" \
--type bug \
--org $SYSTEM_TEAMFOUNDATIONCOLLECTIONURI \
--project $SYSTEM_TEAMPROJECTDownload latest pipeline artifact
下载最新流水线制品
bash
RUN_ID=$(az pipelines runs list --pipeline {pipeline-id} --top 1 --query "[0].id" -o tsv)
az pipelines runs artifact download \
--artifact-name 'webapp' \
--path ./output \
--run-id $RUN_IDbash
RUN_ID=$(az pipelines runs list --pipeline {pipeline-id} --top 1 --query "[0].id" -o tsv)
az pipelines runs artifact download \
--artifact-name 'webapp' \
--path ./output \
--run-id $RUN_IDApprove and complete PR
批准并完成PR
bash
undefinedbash
undefinedVote approve
投票批准
az repos pr set-vote --id {pr-id} --vote approve
az repos pr set-vote --id {pr-id} --vote approve
Complete PR
完成PR
az repos pr update --id {pr-id} --status completed
undefinedaz repos pr update --id {pr-id} --status completed
undefinedCreate pipeline from local repo
从本地代码库创建流水线
bash
undefinedbash
undefinedFrom local git repository (auto-detects repo, branch, etc.)
从本地git代码库创建(自动检测代码库、分支等)
az pipelines create --name 'CI-Pipeline' --description 'Continuous Integration'
undefinedaz pipelines create --name 'CI-Pipeline' --description 'Continuous Integration'
undefinedBulk update work items
批量更新工作项
bash
undefinedbash
undefinedQuery items and update in loop
查询项目并循环更新
for id in $(az boards query --wiql "SELECT ID FROM WorkItems WHERE State='New'" -o tsv); do
az boards work-item update --id $id --state "Active"
done
undefinedfor id in $(az boards query --wiql "SELECT ID FROM WorkItems WHERE State='New'" -o tsv); do
az boards work-item update --id $id --state "Active"
done
undefinedBest Practices
最佳实践
Authentication and Security
身份验证和安全
bash
undefinedbash
undefinedUse PAT from environment variable (most secure)
使用环境变量中的PAT(最安全)
export AZURE_DEVOPS_EXT_PAT=$MY_PAT
az devops login --organization $ORG_URL
export AZURE_DEVOPS_EXT_PAT=$MY_PAT
az devops login --organization $ORG_URL
Pipe PAT securely (avoids shell history)
安全地传递PAT(避免出现在shell历史中)
echo $MY_PAT | az devops login --organization $ORG_URL
echo $MY_PAT | az devops login --organization $ORG_URL
Set defaults to avoid repetition
设置默认值以避免重复输入
az devops configure --defaults organization=$ORG_URL project=$PROJECT
az devops configure --defaults organization=$ORG_URL project=$PROJECT
Clear credentials after use
使用后清除凭据
az devops logout --organization $ORG_URL
undefinedaz devops logout --organization $ORG_URL
undefinedIdempotent Operations
幂等操作
bash
undefinedbash
undefinedAlways use --detect for auto-detection
始终使用--detect进行自动检测
az devops configure --defaults organization=$ORG_URL project=$PROJECT
az devops configure --defaults organization=$ORG_URL project=$PROJECT
Check existence before creation
创建前检查是否存在
if ! az pipelines show --id $PIPELINE_ID 2>/dev/null; then
az pipelines create --name "$PIPELINE_NAME" --yaml-path azure-pipelines.yml
fi
if ! az pipelines show --id $PIPELINE_ID 2>/dev/null; then
az pipelines create --name "$PIPELINE_NAME" --yaml-path azure-pipelines.yml
fi
Use --output tsv for shell parsing
使用--output tsv进行shell解析
PIPELINE_ID=$(az pipelines list --query "[?name=='MyPipeline'].id" --output tsv)
PIPELINE_ID=$(az pipelines list --query "[?name=='MyPipeline'].id" --output tsv)
Use --output json for programmatic access
使用--output json进行程序化访问
BUILD_STATUS=$(az pipelines build show --id $BUILD_ID --query "status" --output json)
undefinedBUILD_STATUS=$(az pipelines build show --id $BUILD_ID --query "status" --output json)
undefinedScript-Safe Output
脚本安全输出
bash
undefinedbash
undefinedSuppress warnings and errors
抑制警告和错误
az pipelines list --only-show-errors
az pipelines list --only-show-errors
No output (useful for commands that only need to execute)
无输出(适用于仅需执行的命令)
az pipelines run --name "$PIPELINE_NAME" --output none
az pipelines run --name "$PIPELINE_NAME" --output none
TSV format for shell scripts (clean, no formatting)
TSV格式(适用于shell脚本,无格式)
az repos pr list --output tsv --query "[].{ID:pullRequestId,Title:title}"
az repos pr list --output tsv --query "[].{ID:pullRequestId,Title:title}"
JSON with specific fields
带特定字段的JSON
az pipelines list --output json --query "[].{Name:name, ID:id, URL:url}"
undefinedaz pipelines list --output json --query "[].{Name:name, ID:id, URL:url}"
undefinedPipeline Orchestration
流水线编排
bash
undefinedbash
undefinedRun pipeline and wait for completion
运行流水线并等待完成
RUN_ID=$(az pipelines run --name "$PIPELINE_NAME" --query "id" -o tsv)
while true; do
STATUS=$(az pipelines runs show --run-id $RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" && "$STATUS" != "notStarted" ]]; then
break
fi
sleep 10
done
RUN_ID=$(az pipelines run --name "$PIPELINE_NAME" --query "id" -o tsv)
while true; do
STATUS=$(az pipelines runs show --run-id $RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" && "$STATUS" != "notStarted" ]]; then
break
fi
sleep 10
done
Check result
检查结果
RESULT=$(az pipelines runs show --run-id $RUN_ID --query "result" -o tsv)
if [[ "$RESULT" == "succeeded" ]]; then
echo "Pipeline succeeded"
else
echo "Pipeline failed with result: $RESULT"
exit 1
fi
undefinedRESULT=$(az pipelines runs show --run-id $RUN_ID --query "result" -o tsv)
if [[ "$RESULT" == "succeeded" ]]; then
echo "Pipeline succeeded"
else
echo "Pipeline failed with result: $RESULT"
exit 1
fi
undefinedVariable Group Management
变量组管理
bash
undefinedbash
undefinedCreate variable group idempotently
幂等创建变量组
VG_NAME="production-variables"
VG_ID=$(az pipelines variable-group list --query "[?name=='$VG_NAME'].id" -o tsv)
if [[ -z "$VG_ID" ]]; then
VG_ID=$(az pipelines variable-group create
--name "$VG_NAME"
--variables API_URL=$API_URL API_KEY=$API_KEY
--authorize true
--query "id" -o tsv) echo "Created variable group with ID: $VG_ID" else echo "Variable group already exists with ID: $VG_ID" fi
--name "$VG_NAME"
--variables API_URL=$API_URL API_KEY=$API_KEY
--authorize true
--query "id" -o tsv) echo "Created variable group with ID: $VG_ID" else echo "Variable group already exists with ID: $VG_ID" fi
undefinedVG_NAME="production-variables"
VG_ID=$(az pipelines variable-group list --query "[?name=='$VG_NAME'].id" -o tsv)
if [[ -z "$VG_ID" ]]; then
VG_ID=$(az pipelines variable-group create
--name "$VG_NAME"
--variables API_URL=$API_URL API_KEY=$API_KEY
--authorize true
--query "id" -o tsv) echo "Created variable group with ID: $VG_ID" else echo "Variable group already exists with ID: $VG_ID" fi
--name "$VG_NAME"
--variables API_URL=$API_URL API_KEY=$API_KEY
--authorize true
--query "id" -o tsv) echo "Created variable group with ID: $VG_ID" else echo "Variable group already exists with ID: $VG_ID" fi
undefinedService Connection Automation
服务连接自动化
bash
undefinedbash
undefinedCreate service connection using configuration file
使用配置文件创建服务连接
cat > service-connection.json <<'EOF'
{
"data": {
"subscriptionId": "$SUBSCRIPTION_ID",
"subscriptionName": "My Subscription",
"creationMode": "Manual",
"serviceEndpointId": "$SERVICE_ENDPOINT_ID"
},
"url": "https://management.azure.com/",
"authorization": {
"parameters": {
"tenantid": "$TENANT_ID",
"serviceprincipalid": "$SP_ID",
"authenticationType": "spnKey",
"serviceprincipalkey": "$SP_KEY"
},
"scheme": "ServicePrincipal"
},
"type": "azurerm",
"isShared": false,
"isReady": true
}
EOF
az devops service-endpoint create
--service-endpoint-configuration service-connection.json
--project "$PROJECT"
--service-endpoint-configuration service-connection.json
--project "$PROJECT"
undefinedcat > service-connection.json <<'EOF'
{
"data": {
"subscriptionId": "$SUBSCRIPTION_ID",
"subscriptionName": "My Subscription",
"creationMode": "Manual",
"serviceEndpointId": "$SERVICE_ENDPOINT_ID"
},
"url": "https://management.azure.com/",
"authorization": {
"parameters": {
"tenantid": "$TENANT_ID",
"serviceprincipalid": "$SP_ID",
"authenticationType": "spnKey",
"serviceprincipalkey": "$SP_KEY"
},
"scheme": "ServicePrincipal"
},
"type": "azurerm",
"isShared": false,
"isReady": true
}
EOF
az devops service-endpoint create
--service-endpoint-configuration service-connection.json
--project "$PROJECT"
--service-endpoint-configuration service-connection.json
--project "$PROJECT"
undefinedPull Request Automation
拉取请求自动化
bash
undefinedbash
undefinedCreate PR with work items and reviewers
创建关联工作项和审阅者的PR
PR_ID=$(az repos pr create
--repository "$REPO_NAME"
--source-branch "$FEATURE_BRANCH"
--target-branch main
--title "Feature: $(git log -1 --pretty=%B)"
--description "$(git log -1 --pretty=%B)"
--work-items $WORK_ITEM_1 $WORK_ITEM_2
--reviewers "$REVIEWER_1" "$REVIEWER_2"
--required-reviewers "$LEAD_EMAIL"
--labels "enhancement" "backlog"
--open
--query "pullRequestId" -o tsv)
--repository "$REPO_NAME"
--source-branch "$FEATURE_BRANCH"
--target-branch main
--title "Feature: $(git log -1 --pretty=%B)"
--description "$(git log -1 --pretty=%B)"
--work-items $WORK_ITEM_1 $WORK_ITEM_2
--reviewers "$REVIEWER_1" "$REVIEWER_2"
--required-reviewers "$LEAD_EMAIL"
--labels "enhancement" "backlog"
--open
--query "pullRequestId" -o tsv)
PR_ID=$(az repos pr create
--repository "$REPO_NAME"
--source-branch "$FEATURE_BRANCH"
--target-branch main
--title "Feature: $(git log -1 --pretty=%B)"
--description "$(git log -1 --pretty=%B)"
--work-items $WORK_ITEM_1 $WORK_ITEM_2
--reviewers "$REVIEWER_1" "$REVIEWER_2"
--required-reviewers "$LEAD_EMAIL"
--labels "enhancement" "backlog"
--open
--query "pullRequestId" -o tsv)
--repository "$REPO_NAME"
--source-branch "$FEATURE_BRANCH"
--target-branch main
--title "Feature: $(git log -1 --pretty=%B)"
--description "$(git log -1 --pretty=%B)"
--work-items $WORK_ITEM_1 $WORK_ITEM_2
--reviewers "$REVIEWER_1" "$REVIEWER_2"
--required-reviewers "$LEAD_EMAIL"
--labels "enhancement" "backlog"
--open
--query "pullRequestId" -o tsv)
Set auto-complete when policies pass
策略通过后自动完成
az repos pr update --id $PR_ID --auto-complete true
undefinedaz repos pr update --id $PR_ID --auto-complete true
undefinedError Handling and Retry Patterns
错误处理和重试模式
Retry Logic for Transient Failures
瞬时故障的重试逻辑
bash
undefinedbash
undefinedRetry function for network operations
网络操作的重试函数
retry_command() {
local max_attempts=3
local attempt=1
local delay=5
while [[ $attempt -le $max_attempts ]]; do
if "$@"; then
return 0
fi
echo "Attempt $attempt failed. Retrying in ${delay}s..."
sleep $delay
((attempt++))
delay=$((delay * 2))
done
echo "All $max_attempts attempts failed"
return 1
}
retry_command() {
local max_attempts=3
local attempt=1
local delay=5
while [[ $attempt -le $max_attempts ]]; do
if "$@"; then
return 0
fi
echo "Attempt $attempt failed. Retrying in ${delay}s..."
sleep $delay
((attempt++))
delay=$((delay * 2))
done
echo "All $max_attempts attempts failed"
return 1
}
Usage
使用示例
retry_command az pipelines run --name "$PIPELINE_NAME"
undefinedretry_command az pipelines run --name "$PIPELINE_NAME"
undefinedCheck and Handle Errors
检查并处理错误
bash
undefinedbash
undefinedCheck if pipeline exists before operations
操作前检查流水线是否存在
PIPELINE_ID=$(az pipelines list --query "[?name=='$PIPELINE_NAME'].id" -o tsv)
if [[ -z "$PIPELINE_ID" ]]; then
echo "Pipeline not found. Creating..."
az pipelines create --name "$PIPELINE_NAME" --yaml-path azure-pipelines.yml
else
echo "Pipeline exists with ID: $PIPELINE_ID"
fi
undefinedPIPELINE_ID=$(az pipelines list --query "[?name=='$PIPELINE_NAME'].id" -o tsv)
if [[ -z "$PIPELINE_ID" ]]; then
echo "Pipeline not found. Creating..."
az pipelines create --name "$PIPELINE_NAME" --yaml-path azure-pipelines.yml
else
echo "Pipeline exists with ID: $PIPELINE_ID"
fi
undefinedValidate Inputs
验证输入
bash
undefinedbash
undefinedValidate required parameters
验证必填参数
if [[ -z "$PROJECT" || -z "$REPO" ]]; then
echo "Error: PROJECT and REPO must be set"
exit 1
fi
if [[ -z "$PROJECT" || -z "$REPO" ]]; then
echo "Error: PROJECT and REPO must be set"
exit 1
fi
Check if branch exists
检查分支是否存在
if ! az repos ref list --repository "$REPO" --query "[?name=='refs/heads/$BRANCH']" -o tsv | grep -q .; then
echo "Error: Branch $BRANCH does not exist"
exit 1
fi
undefinedif ! az repos ref list --repository "$REPO" --query "[?name=='refs/heads/$BRANCH']" -o tsv | grep -q .; then
echo "Error: Branch $BRANCH does not exist"
exit 1
fi
undefinedHandle Permission Errors
处理权限错误
bash
undefinedbash
undefinedTry operation, handle permission errors
尝试操作,处理权限错误
if az devops security permission update
--id "$USER_ID"
--namespace "GitRepositories"
--project "$PROJECT"
--token "repoV2/$PROJECT/$REPO_ID"
--allow-bit 2
--deny-bit 0 2>&1 | grep -q "unauthorized"; then echo "Error: Insufficient permissions to update repository permissions" exit 1 fi
--id "$USER_ID"
--namespace "GitRepositories"
--project "$PROJECT"
--token "repoV2/$PROJECT/$REPO_ID"
--allow-bit 2
--deny-bit 0 2>&1 | grep -q "unauthorized"; then echo "Error: Insufficient permissions to update repository permissions" exit 1 fi
undefinedif az devops security permission update
--id "$USER_ID"
--namespace "GitRepositories"
--project "$PROJECT"
--token "repoV2/$PROJECT/$REPO_ID"
--allow-bit 2
--deny-bit 0 2>&1 | grep -q "unauthorized"; then echo "Error: Insufficient permissions to update repository permissions" exit 1 fi
--id "$USER_ID"
--namespace "GitRepositories"
--project "$PROJECT"
--token "repoV2/$PROJECT/$REPO_ID"
--allow-bit 2
--deny-bit 0 2>&1 | grep -q "unauthorized"; then echo "Error: Insufficient permissions to update repository permissions" exit 1 fi
undefinedPipeline Failure Notification
流水线失败通知
bash
undefinedbash
undefinedRun pipeline and check result
运行流水线并检查结果
RUN_ID=$(az pipelines run --name "$PIPELINE_NAME" --query "id" -o tsv)
RUN_ID=$(az pipelines run --name "$PIPELINE_NAME" --query "id" -o tsv)
Wait for completion
等待完成
while true; do
STATUS=$(az pipelines runs show --run-id $RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" && "$STATUS" != "notStarted" ]]; then
break
fi
sleep 10
done
while true; do
STATUS=$(az pipelines runs show --run-id $RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" && "$STATUS" != "notStarted" ]]; then
break
fi
sleep 10
done
Check result and create work item on failure
检查结果并在失败时创建工作项
RESULT=$(az pipelines runs show --run-id $RUN_ID --query "result" -o tsv)
if [[ "$RESULT" != "succeeded" ]]; then
BUILD_NUMBER=$(az pipelines runs show --run-id $RUN_ID --query "buildNumber" -o tsv)
az boards work-item create
--title "Build $BUILD_NUMBER failed"
--type Bug
--description "Pipeline run $RUN_ID failed with result: $RESULT\n\nURL: $ORG_URL/$PROJECT/_build/results?buildId=$RUN_ID" fi
--title "Build $BUILD_NUMBER failed"
--type Bug
--description "Pipeline run $RUN_ID failed with result: $RESULT\n\nURL: $ORG_URL/$PROJECT/_build/results?buildId=$RUN_ID" fi
undefinedRESULT=$(az pipelines runs show --run-id $RUN_ID --query "result" -o tsv)
if [[ "$RESULT" != "succeeded" ]]; then
BUILD_NUMBER=$(az pipelines runs show --run-id $RUN_ID --query "buildNumber" -o tsv)
az boards work-item create
--title "Build $BUILD_NUMBER failed"
--type Bug
--description "Pipeline run $RUN_ID failed with result: $RESULT\n\nURL: $ORG_URL/$PROJECT/_build/results?buildId=$RUN_ID" fi
--title "Build $BUILD_NUMBER failed"
--type Bug
--description "Pipeline run $RUN_ID failed with result: $RESULT\n\nURL: $ORG_URL/$PROJECT/_build/results?buildId=$RUN_ID" fi
undefinedGraceful Degradation
优雅降级
bash
undefinedbash
undefinedTry to download artifact, fallback to alternative source
尝试下载制品,失败时回退到备用源
if ! az pipelines runs artifact download
--artifact-name 'webapp'
--path ./output
--run-id $RUN_ID 2>/dev/null; then echo "Warning: Failed to download from pipeline run. Falling back to backup source..."
--artifact-name 'webapp'
--path ./output
--run-id $RUN_ID 2>/dev/null; then echo "Warning: Failed to download from pipeline run. Falling back to backup source..."
Alternative download method
curl -L "$BACKUP_URL" -o ./output/backup.zip
fi
undefinedif ! az pipelines runs artifact download
--artifact-name 'webapp'
--path ./output
--run-id $RUN_ID 2>/dev/null; then echo "Warning: Failed to download from pipeline run. Falling back to backup source..."
--artifact-name 'webapp'
--path ./output
--run-id $RUN_ID 2>/dev/null; then echo "Warning: Failed to download from pipeline run. Falling back to backup source..."
备用下载方法
curl -L "$BACKUP_URL" -o ./output/backup.zip
fi
undefinedAdvanced JMESPath Queries
高级JMESPath查询
Filtering and Sorting
筛选和排序
bash
undefinedbash
undefinedFilter by multiple conditions
多条件筛选
az pipelines list --query "[?name.contains('CI') && enabled==true]"
az pipelines list --query "[?name.contains('CI') && enabled==true]"
Filter by status and result
按状态和结果筛选
az pipelines runs list --query "[?status=='completed' && result=='succeeded']"
az pipelines runs list --query "[?status=='completed' && result=='succeeded']"
Sort by date (descending)
按日期排序(降序)
az pipelines runs list --query "sort_by([?status=='completed'], &finishTime | reverse(@))"
az pipelines runs list --query "sort_by([?status=='completed'], &finishTime | reverse(@))"
Get top N items after filtering
筛选后获取前N个项目
az pipelines runs list --query "[?result=='succeeded'] | [0:5]"
undefinedaz pipelines runs list --query "[?result=='succeeded'] | [0:5]"
undefinedNested Queries
嵌套查询
bash
undefinedbash
undefinedExtract nested properties
提取嵌套属性
az pipelines show --id $PIPELINE_ID --query "{Name:name, Repo:repository.{Name:name, Type:type}, Folder:folder}"
az pipelines show --id $PIPELINE_ID --query "{Name:name, Repo:repository.{Name:name, Type:type}, Folder:folder}"
Query build details
查询构建详情
az pipelines build show --id $BUILD_ID --query "{ID:id, Number:buildNumber, Status:status, Result:result, Requested:requestedFor.displayName}"
undefinedaz pipelines build show --id $BUILD_ID --query "{ID:id, Number:buildNumber, Status:status, Result:result, Requested:requestedFor.displayName}"
undefinedComplex Filtering
复杂筛选
bash
undefinedbash
undefinedFind pipelines with specific YAML path
查找具有特定YAML路径的流水线
az pipelines list --query "[?process.type.name=='yaml' && process.yamlFilename=='azure-pipelines.yml']"
az pipelines list --query "[?process.type.name=='yaml' && process.yamlFilename=='azure-pipelines.yml']"
Find PRs from specific reviewer
查找来自特定审阅者的PR
az repos pr list --query "[?contains(reviewers[?displayName=='John Doe'].displayName, 'John Doe')]"
az repos pr list --query "[?contains(reviewers[?displayName=='John Doe'].displayName, 'John Doe')]"
Find work items with specific iteration and state
查找具有特定迭代和状态的工作项
az boards work-item show --id $WI_ID --query "{Title:fields['System.Title'], State:fields['System.State'], Iteration:fields['System.IterationPath']}"
undefinedaz boards work-item show --id $WI_ID --query "{Title:fields['System.Title'], State:fields['System.State'], Iteration:fields['System.IterationPath']}"
undefinedAggregation
聚合
bash
undefinedbash
undefinedCount items by status
按状态统计项目数量
az pipelines runs list --query "groupBy([?status=='completed'], &[result]) | {Succeeded: [?key=='succeeded'][0].count, Failed: [?key=='failed'][0].count}"
az pipelines runs list --query "groupBy([?status=='completed'], &[result]) | {Succeeded: [?key=='succeeded'][0].count, Failed: [?key=='failed'][0].count}"
Get unique reviewers
获取唯一的审阅者
az repos pr list --query "unique_by(reviewers[], &displayName)"
az repos pr list --query "unique_by(reviewers[], &displayName)"
Sum values
求和
az pipelines runs list --query "[?result=='succeeded'] | [].{Duration:duration} | [0].Duration"
undefinedaz pipelines runs list --query "[?result=='succeeded'] | [].{Duration:duration} | [0].Duration"
undefinedConditional Transformation
条件转换
bash
undefinedbash
undefinedFormat dates
格式化日期
az pipelines runs list --query "[].{ID:id, Date:createdDate, Formatted:createdDate | format_datetime(@, 'yyyy-MM-dd HH:mm')}"
az pipelines runs list --query "[].{ID:id, Date:createdDate, Formatted:createdDate | format_datetime(@, 'yyyy-MM-dd HH:mm')}"
Conditional output
条件输出
az pipelines list --query "[].{Name:name, Status:(enabled ? 'Enabled' : 'Disabled')}"
az pipelines list --query "[].{Name:name, Status:(enabled ? 'Enabled' : 'Disabled')}"
Extract with defaults
提取并使用默认值
az pipelines show --id $PIPELINE_ID --query "{Name:name, Folder:folder || 'Root', Description:description || 'No description'}"
undefinedaz pipelines show --id $PIPELINE_ID --query "{Name:name, Folder:folder || 'Root', Description:description || 'No description'}"
undefinedComplex Workflows
复杂工作流
bash
undefinedbash
undefinedFind longest running builds
查找运行时间最长的构建
az pipelines build list --query "sort_by([?result=='succeeded'], &queueTime) | reverse(@) | [0:3].{ID:id, Number:buildNumber, Duration:duration}"
az pipelines build list --query "sort_by([?result=='succeeded'], &queueTime) | reverse(@) | [0:3].{ID:id, Number:buildNumber, Duration:duration}"
Get PR statistics per reviewer
获取每位审阅者的PR统计
az repos pr list --query "groupBy([], &reviewers[].displayName) | [].{Reviewer:@.key, Count:length(@)}"
az repos pr list --query "groupBy([], &reviewers[].displayName) | [].{Reviewer:@.key, Count:length(@)}"
Find work items with multiple child items
查找具有多个子项的工作项
az boards work-item relation list --id $PARENT_ID --query "[?rel=='System.LinkTypes.Hierarchy-Forward'] | [].{ChildID:url | split('/', @) | [-1]}"
undefinedaz boards work-item relation list --id $PARENT_ID --query "[?rel=='System.LinkTypes.Hierarchy-Forward'] | [].{ChildID:url | split('/', @) | [-1]}"
undefinedScripting Patterns for Idempotent Operations
幂等操作的脚本模式
Create or Update Pattern
创建或更新模式
bash
undefinedbash
undefinedEnsure pipeline exists, update if different
确保流水线存在,不同则更新
ensure_pipeline() {
local name=$1
local yaml_path=$2
PIPELINE=$(az pipelines list --query "[?name=='$name']" -o json)
if [[ -z "$PIPELINE" ]]; then
echo "Creating pipeline: $name"
az pipelines create --name "$name" --yaml-path "$yaml_path"
else
echo "Pipeline exists: $name"
fi
}
undefinedensure_pipeline() {
local name=$1
local yaml_path=$2
PIPELINE=$(az pipelines list --query "[?name=='$name']" -o json)
if [[ -z "$PIPELINE" ]]; then
echo "Creating pipeline: $name"
az pipelines create --name "$name" --yaml-path "$yaml_path"
else
echo "Pipeline exists: $name"
fi
}
undefinedEnsure Variable Group
确保变量组存在
bash
undefinedbash
undefinedCreate variable group with idempotent updates
幂等更新创建变量组
ensure_variable_group() {
local vg_name=$1
shift
local variables=("$@")
VG_ID=$(az pipelines variable-group list --query "[?name=='$vg_name'].id" -o tsv)
if [[ -z "$VG_ID" ]]; then
echo "Creating variable group: $vg_name"
VG_ID=$(az pipelines variable-group create
--name "$vg_name"
--variables "${variables[@]}"
--authorize true
--query "id" -o tsv) else echo "Variable group exists: $vg_name (ID: $VG_ID)" fi
--name "$vg_name"
--variables "${variables[@]}"
--authorize true
--query "id" -o tsv) else echo "Variable group exists: $vg_name (ID: $VG_ID)" fi
echo "$VG_ID"
}
undefinedensure_variable_group() {
local vg_name=$1
shift
local variables=("$@")
VG_ID=$(az pipelines variable-group list --query "[?name=='$vg_name'].id" -o tsv)
if [[ -z "$VG_ID" ]]; then
echo "Creating variable group: $vg_name"
VG_ID=$(az pipelines variable-group create
--name "$vg_name"
--variables "${variables[@]}"
--authorize true
--query "id" -o tsv) else echo "Variable group exists: $vg_name (ID: $VG_ID)" fi
--name "$vg_name"
--variables "${variables[@]}"
--authorize true
--query "id" -o tsv) else echo "Variable group exists: $vg_name (ID: $VG_ID)" fi
echo "$VG_ID"
}
undefinedEnsure Service Connection
确保服务连接存在
bash
undefinedbash
undefinedCheck if service connection exists, create if not
检查服务连接是否存在,不存在则创建
ensure_service_connection() {
local name=$1
local project=$2
SC_ID=$(az devops service-endpoint list
--project "$project"
--query "[?name=='$name'].id"
-o tsv)
--project "$project"
--query "[?name=='$name'].id"
-o tsv)
if [[ -z "$SC_ID" ]]; then
echo "Service connection not found. Creating..."
# Create logic here
else
echo "Service connection exists: $name"
echo "$SC_ID"
fi
}
undefinedensure_service_connection() {
local name=$1
local project=$2
SC_ID=$(az devops service-endpoint list
--project "$project"
--query "[?name=='$name'].id"
-o tsv)
--project "$project"
--query "[?name=='$name'].id"
-o tsv)
if [[ -z "$SC_ID" ]]; then
echo "Service connection not found. Creating..."
# 此处添加创建逻辑
else
echo "Service connection exists: $name"
echo "$SC_ID"
fi
}
undefinedIdempotent Work Item Creation
幂等创建工作项
bash
undefinedbash
undefinedCreate work item only if doesn't exist with same title
仅当不存在相同标题的工作项时创建
create_work_item_if_new() {
local title=$1
local type=$2
WI_ID=$(az boards query
--wiql "SELECT ID FROM WorkItems WHERE [System.WorkItemType]='$type' AND [System.Title]='$title'"
--query "[0].id" -o tsv)
--wiql "SELECT ID FROM WorkItems WHERE [System.WorkItemType]='$type' AND [System.Title]='$title'"
--query "[0].id" -o tsv)
if [[ -z "$WI_ID" ]]; then
echo "Creating work item: $title"
WI_ID=$(az boards work-item create --title "$title" --type "$type" --query "id" -o tsv)
else
echo "Work item exists: $title (ID: $WI_ID)"
fi
echo "$WI_ID"
}
undefinedcreate_work_item_if_new() {
local title=$1
local type=$2
WI_ID=$(az boards query
--wiql "SELECT ID FROM WorkItems WHERE [System.WorkItemType]='$type' AND [System.Title]='$title'"
--query "[0].id" -o tsv)
--wiql "SELECT ID FROM WorkItems WHERE [System.WorkItemType]='$type' AND [System.Title]='$title'"
--query "[0].id" -o tsv)
if [[ -z "$WI_ID" ]]; then
echo "Creating work item: $title"
WI_ID=$(az boards work-item create --title "$title" --type "$type" --query "id" -o tsv)
else
echo "Work item exists: $title (ID: $WI_ID)"
fi
echo "$WI_ID"
}
undefinedBulk Idempotent Operations
批量幂等操作
bash
undefinedbash
undefinedEnsure multiple pipelines exist
确保多个流水线存在
declare -a PIPELINES=(
"ci-pipeline:azure-pipelines.yml"
"deploy-pipeline:deploy.yml"
"test-pipeline:test.yml"
)
for pipeline in "${PIPELINES[@]}"; do
IFS=':' read -r name yaml <<< "$pipeline"
ensure_pipeline "$name" "$yaml"
done
undefineddeclare -a PIPELINES=(
"ci-pipeline:azure-pipelines.yml"
"deploy-pipeline:deploy.yml"
"test-pipeline:test.yml"
)
for pipeline in "${PIPELINES[@]}"; do
IFS=':' read -r name yaml <<< "$pipeline"
ensure_pipeline "$name" "$yaml"
done
undefinedConfiguration Synchronization
配置同步
bash
undefinedbash
undefinedSync variable groups from config file
从配置文件同步变量组
sync_variable_groups() {
local config_file=$1
while IFS=',' read -r vg_name variables; do
ensure_variable_group "$vg_name" "$variables"
done < "$config_file"
}
sync_variable_groups() {
local config_file=$1
while IFS=',' read -r vg_name variables; do
ensure_variable_group "$vg_name" "$variables"
done < "$config_file"
}
config.csv format:
config.csv格式:
prod-vars,API_URL=prod.com,API_KEY=secret123
prod-vars,API_URL=prod.com,API_KEY=secret123
dev-vars,API_URL=dev.com,API_KEY=secret456
dev-vars,API_URL=dev.com,API_KEY=secret456
undefinedundefinedReal-World Workflows
实际工作流
CI/CD Pipeline Setup
CI/CD流水线设置
bash
undefinedbash
undefinedSetup complete CI/CD pipeline
设置完整的CI/CD流水线
setup_cicd_pipeline() {
local project=$1
local repo=$2
local branch=$3
Create variable groups
VG_DEV=$(ensure_variable_group "dev-vars" "ENV=dev API_URL=api-dev.com")
VG_PROD=$(ensure_variable_group "prod-vars" "ENV=prod API_URL=api-prod.com")
Create CI pipeline
az pipelines create
--name "$repo-CI"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/ci.yml
--skip-run true
--name "$repo-CI"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/ci.yml
--skip-run true
Create CD pipeline
az pipelines create
--name "$repo-CD"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/cd.yml
--skip-run true
--name "$repo-CD"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/cd.yml
--skip-run true
echo "CI/CD pipeline setup complete"
}
undefinedsetup_cicd_pipeline() {
local project=$1
local repo=$2
local branch=$3
创建变量组
VG_DEV=$(ensure_variable_group "dev-vars" "ENV=dev API_URL=api-dev.com")
VG_PROD=$(ensure_variable_group "prod-vars" "ENV=prod API_URL=api-prod.com")
创建CI流水线
az pipelines create
--name "$repo-CI"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/ci.yml
--skip-run true
--name "$repo-CI"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/ci.yml
--skip-run true
创建CD流水线
az pipelines create
--name "$repo-CD"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/cd.yml
--skip-run true
--name "$repo-CD"
--repository "$repo"
--branch "$branch"
--yaml-path .azure/pipelines/cd.yml
--skip-run true
echo "CI/CD pipeline setup complete"
}
undefinedAutomated PR Creation
自动化PR创建
bash
undefinedbash
undefinedCreate PR from feature branch with automation
从功能分支自动化创建PR
create_automated_pr() {
local branch=$1
local title=$2
Get branch info
LAST_COMMIT=$(git log -1 --pretty=%B "$branch")
COMMIT_SHA=$(git rev-parse "$branch")
Find related work items
WORK_ITEMS=$(az boards query
--wiql "SELECT ID FROM WorkItems WHERE [System.ChangedBy] = @Me AND [System.State] = 'Active'"
--query "[].id" -o tsv)
--wiql "SELECT ID FROM WorkItems WHERE [System.ChangedBy] = @Me AND [System.State] = 'Active'"
--query "[].id" -o tsv)
Create PR
PR_ID=$(az repos pr create
--source-branch "$branch"
--target-branch main
--title "$title"
--description "$LAST_COMMIT"
--work-items $WORK_ITEMS
--auto-complete true
--query "pullRequestId" -o tsv)
--source-branch "$branch"
--target-branch main
--title "$title"
--description "$LAST_COMMIT"
--work-items $WORK_ITEMS
--auto-complete true
--query "pullRequestId" -o tsv)
Set required reviewers
az repos pr reviewer add
--id $PR_ID
--reviewers $(git log -1 --pretty=format:'%ae' "$branch")
--required true
--id $PR_ID
--reviewers $(git log -1 --pretty=format:'%ae' "$branch")
--required true
echo "Created PR #$PR_ID"
}
undefinedcreate_automated_pr() {
local branch=$1
local title=$2
获取分支信息
LAST_COMMIT=$(git log -1 --pretty=%B "$branch")
COMMIT_SHA=$(git rev-parse "$branch")
查找关联的工作项
WORK_ITEMS=$(az boards query
--wiql "SELECT ID FROM WorkItems WHERE [System.ChangedBy] = @Me AND [System.State] = 'Active'"
--query "[].id" -o tsv)
--wiql "SELECT ID FROM WorkItems WHERE [System.ChangedBy] = @Me AND [System.State] = 'Active'"
--query "[].id" -o tsv)
创建PR
PR_ID=$(az repos pr create
--source-branch "$branch"
--target-branch main
--title "$title"
--description "$LAST_COMMIT"
--work-items $WORK_ITEMS
--auto-complete true
--query "pullRequestId" -o tsv)
--source-branch "$branch"
--target-branch main
--title "$title"
--description "$LAST_COMMIT"
--work-items $WORK_ITEMS
--auto-complete true
--query "pullRequestId" -o tsv)
设置必填审阅者
az repos pr reviewer add
--id $PR_ID
--reviewers $(git log -1 --pretty=format:'%ae' "$branch")
--required true
--id $PR_ID
--reviewers $(git log -1 --pretty=format:'%ae' "$branch")
--required true
echo "Created PR #$PR_ID"
}
undefinedPipeline Monitoring and Alerting
流水线监控和告警
bash
undefinedbash
undefinedMonitor pipeline and alert on failure
监控流水线并在失败时告警
monitor_pipeline() {
local pipeline_name=$1
local slack_webhook=$2
while true; do
# Get latest run
RUN_ID=$(az pipelines list --query "[?name=='$pipeline_name'] | [0].id" -o tsv)
RUNS=$(az pipelines runs list --pipeline $RUN_ID --top 1)
LATEST_RUN_ID=$(echo "$RUNS" | jq -r '.[0].id')
RESULT=$(echo "$RUNS" | jq -r '.[0].result')
# Check if failed and not already processed
if [[ "$RESULT" == "failed" ]]; then
# Send Slack alert
curl -X POST "$slack_webhook" \
-H 'Content-Type: application/json' \
-d "{\"text\": \"Pipeline $pipeline_name failed! Run ID: $LATEST_RUN_ID\"}"
fi
sleep 300 # Check every 5 minutesdone
}
undefinedmonitor_pipeline() {
local pipeline_name=$1
local slack_webhook=$2
while true; do
# 获取最新运行记录
RUN_ID=$(az pipelines list --query "[?name=='$pipeline_name'] | [0].id" -o tsv)
RUNS=$(az pipelines runs list --pipeline $RUN_ID --top 1)
LATEST_RUN_ID=$(echo "$RUNS" | jq -r '.[0].id')
RESULT=$(echo "$RUNS" | jq -r '.[0].result')
# 检查是否失败且未处理
if [[ "$RESULT" == "failed" ]]; then
# 发送Slack告警
curl -X POST "$slack_webhook" \
-H 'Content-Type: application/json' \
-d "{\"text\": \"Pipeline $pipeline_name failed! Run ID: $LATEST_RUN_ID\"}"
fi
sleep 300 # 每5分钟检查一次done
}
undefinedBulk Work Item Management
批量工作项管理
bash
undefinedbash
undefinedBulk update work items based on query
根据查询批量更新工作项
bulk_update_work_items() {
local wiql=$1
local updates=("$@")
Query work items
WI_IDS=$(az boards query --wiql "$wiql" --query "[].id" -o tsv)
Update each work item
for wi_id in $WI_IDS; do
az boards work-item update --id $wi_id "${updates[@]}"
echo "Updated work item: $wi_id"
done
}
bulk_update_work_items() {
local wiql=$1
shift
local updates=("$@")
查询工作项
WI_IDS=$(az boards query --wiql "$wiql" --query "[].id" -o tsv)
更新每个工作项
for wi_id in $WI_IDS; do
az boards work-item update --id $wi_id "${updates[@]}"
echo "Updated work item: $wi_id"
done
}
Usage: bulk_update_work_items "SELECT ID FROM WorkItems WHERE State='New'" --state "Active" --assigned-to "user@example.com"
使用示例: bulk_update_work_items "SELECT ID FROM WorkItems WHERE State='New'" --state "Active" --assigned-to "user@example.com"
undefinedundefinedBranch Policy Automation
分支策略自动化
bash
undefinedbash
undefinedApply branch policies to all repositories
为所有代码库应用分支策略
apply_branch_policies() {
local branch=$1
local project=$2
Get all repositories
REPOS=$(az repos list --project "$project" --query "[].id" -o tsv)
for repo_id in $REPOS; do
echo "Applying policies to repo: $repo_id"
# Require minimum approvers
az repos policy approver-count create \
--blocking true \
--enabled true \
--branch "$branch" \
--repository-id "$repo_id" \
--minimum-approver-count 2 \
--creator-vote-counts true
# Require work item linking
az repos policy work-item-linking create \
--blocking true \
--branch "$branch" \
--enabled true \
--repository-id "$repo_id"
# Require build validation
BUILD_ID=$(az pipelines list --query "[?name=='CI'].id" -o tsv | head -1)
az repos policy build create \
--blocking true \
--enabled true \
--branch "$branch" \
--repository-id "$repo_id" \
--build-definition-id "$BUILD_ID" \
--queue-on-source-update-only truedone
}
undefinedapply_branch_policies() {
local branch=$1
local project=$2
获取所有代码库
REPOS=$(az repos list --project "$project" --query "[].id" -o tsv)
for repo_id in $REPOS; do
echo "Applying policies to repo: $repo_id"
# 要求最少审批者数量
az repos policy approver-count create \
--blocking true \
--enabled true \
--branch "$branch" \
--repository-id "$repo_id" \
--minimum-approver-count 2 \
--creator-vote-counts true
# 要求工作项关联
az repos policy work-item-linking create \
--blocking true \
--branch "$branch" \
--enabled true \
--repository-id "$repo_id"
# 要求构建验证
BUILD_ID=$(az pipelines list --query "[?name=='CI'].id" -o tsv | head -1)
az repos policy build create \
--blocking true \
--enabled true \
--branch "$branch" \
--repository-id "$repo_id" \
--build-definition-id "$BUILD_ID" \
--queue-on-source-update-only truedone
}
undefinedMulti-Environment Deployment
多环境部署
bash
undefinedbash
undefinedDeploy across multiple environments
跨多环境部署
deploy_to_environments() {
local run_id=$1
shift
local environments=("$@")
Download artifacts
ARTIFACT_NAME=$(az pipelines runs artifact list --run-id $run_id --query "[0].name" -o tsv)
az pipelines runs artifact download
--artifact-name "$ARTIFACT_NAME"
--path ./artifacts
--run-id $run_id
--artifact-name "$ARTIFACT_NAME"
--path ./artifacts
--run-id $run_id
Deploy to each environment
for env in "${environments[@]}"; do
echo "Deploying to: $env"
# Get environment-specific variables
VG_ID=$(az pipelines variable-group list --query "[?name=='$env-vars'].id" -o tsv)
# Run deployment pipeline
DEPLOY_RUN_ID=$(az pipelines run \
--name "Deploy-$env" \
--variables ARTIFACT_PATH=./artifacts ENV="$env" \
--query "id" -o tsv)
# Wait for deployment
while true; do
STATUS=$(az pipelines runs show --run-id $DEPLOY_RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" ]]; then
break
fi
sleep 10
donedone
}
undefineddeploy_to_environments() {
local run_id=$1
shift
local environments=("$@")
下载制品
ARTIFACT_NAME=$(az pipelines runs artifact list --run-id $run_id --query "[0].name" -o tsv)
az pipelines runs artifact download
--artifact-name "$ARTIFACT_NAME"
--path ./artifacts
--run-id $run_id
--artifact-name "$ARTIFACT_NAME"
--path ./artifacts
--run-id $run_id
部署到每个环境
for env in "${environments[@]}"; do
echo "Deploying to: $env"
# 获取环境特定变量
VG_ID=$(az pipelines variable-group list --query "[?name=='$env-vars'].id" -o tsv)
# 运行部署流水线
DEPLOY_RUN_ID=$(az pipelines run \
--name "Deploy-$env" \
--variables ARTIFACT_PATH=./artifacts ENV="$env" \
--query "id" -o tsv)
# 等待部署完成
while true; do
STATUS=$(az pipelines runs show --run-id $DEPLOY_RUN_ID --query "status" -o tsv)
if [[ "$STATUS" != "inProgress" ]]; then
break
fi
sleep 10
donedone
}
undefinedEnhanced Global Arguments
增强的全局参数
| Parameter | Description |
|---|---|
| Show command help |
| Output format (json, jsonc, none, table, tsv, yaml, yamlc) |
| JMESPath query string for filtering output |
| Increase logging verbosity |
| Show all debug logs |
| Only show errors, suppress warnings |
| Name or ID of subscription |
| Skip confirmation prompts |
| 参数 | 描述 |
|---|---|
| 显示命令帮助 |
| 输出格式(json, jsonc, none, table, tsv, yaml, yamlc) |
| JMESPath查询字符串,用于筛选输出 |
| 增加日志详细程度 |
| 显示所有调试日志 |
| 仅显示错误,抑制警告 |
| 订阅名称或ID |
| 跳过确认提示 |
Enhanced Common Parameters
增强的通用参数
| Parameter | Description |
|---|---|
| Azure DevOps organization URL (e.g., |
| Project name or ID |
| Auto-detect organization from git config |
| Skip confirmation prompts |
| Open resource in web browser |
| Azure subscription (for Azure resources) |
| 参数 | 描述 |
|---|---|
| Azure DevOps组织URL(例如: |
| 项目名称或ID |
| 从git配置自动检测组织 |
| 跳过确认提示 |
| 在浏览器中打开资源 |
| Azure订阅(用于Azure资源) |
Getting Help
获取帮助
bash
undefinedbash
undefinedGeneral help
通用帮助
az devops --help
az devops --help
Help for specific command group
特定命令组的帮助
az pipelines --help
az repos pr --help
az pipelines --help
az repos pr --help
Help for specific command
特定命令的帮助
az repos pr create --help
az repos pr create --help
Search for examples
搜索示例
az find "az repos pr create"
undefinedaz find "az repos pr create"
undefined