mcpField
A
azure-devops-cli

azure-devops-cli

github.com/rysweet云与 DevOps7683 次安装22 周前更新
代码仓库

关于 azure-devops-cli

azure-devops-cli 是通过 Azure CLI 管理 Azure DevOps 的技能,适用于开发与运维工作流。内容涵盖项目、流水线、工作项、代码库和制品,并提供自动化与查询示例。

主要功能

  1. 01管理组织和项目
  2. 02列出并运行流水线
  3. 03查询和更新工作项
  4. 04管理代码库和拉取请求
  5. 05使用制品源和软件包
  6. 06调用 REST API 并使用 JMESPath 查询

适用场景

  1. 01运行并监控 CI/CD 流水线
  2. 02审查和更新拉取请求
  3. 03查询冲刺工作项
  4. 04导出项目和团队数据

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/rysweet/amplihack --skill azure-devops-cli

安装后在 Claude Code 中输入/azure-devops-cli确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

README.md
examples/
artifacts-reference.md
boards-reference.md
pipelines-reference.md
repos-reference.md
examples/workflows/
ci-cd-automation.md
release-management.md
team-collaboration.md
tests/
test-scenarios.md

详细介绍

Azure DevOps CLI 技能

快速入门

安装与身份验证
# Install Azure DevOps CLI extension
az extension add --name azure-devops

# Authenticate (choose one method)
az login                                    # Interactive browser login
az devops login --organization https://dev.azure.com/YOUR_ORG  # PAT token login

# Configure defaults (recommended)
az devops configure --defaults organization=https://dev.azure.com/YOUR_ORG project=YOUR_PROJECT

# Verify setup
az devops project list
配置模式
# Set defaults to avoid repeating --organization and --project
az devops configure --defaults organization=https://dev.azure.com/myorg project=myproject

# List current configuration
az devops configure --list

# Use Git aliases for common commands
az devops configure --defaults use-git-aliases=true

# Common output formats
--output table    # Human-readable tables (default)
--output json     # JSON for scripting
--output tsv      # Tab-separated values

按类别划分的基本命令

1. DevOps(组织与项目)
# List projects
az devops project list --organization https://dev.azure.com/myorg

# Create project
az devops project create --name "MyProject" --visibility private

# Show project details
az devops project show --project MyProject

# Delete project
az devops project delete --id PROJECT_ID --yes

# Manage users/teams
az devops user list
az devops team list --project MyProject
2. Pipelines(构建与发布)
# List pipelines
az pipelines list --project MyProject

# Run a pipeline
az pipelines run --name "MyPipeline" --branch main

# Show pipeline runs
az pipelines runs list --pipeline-ids 123

# Show run details
az pipelines runs show --id RUN_ID

# Create pipeline from YAML
az pipelines create --name "NewPipeline" --repository myrepo --branch main --yml-path azure-pipelines.yml
3. Boards(工作项与冲刺)
# List work items
az boards query --wiql "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.State] = 'Active'"

# Create work item
az boards work-item create --type "User Story" --title "New Feature" --assigned-to [email protected]

# Update work item
az boards work-item update --id 123 --state "In Progress"

# Show work item
az boards work-item show --id 123

# List iterations/sprints
az boards iteration project list
4. Repos(Git 存储库)
# List repositories
az repos list --project MyProject

# Create repository
az repos create --name "myrepo" --project MyProject

# List pull requests
az repos pr list --repository myrepo --status active

# Create pull request
az repos pr create --repository myrepo --source-branch feature/new --target-branch main --title "New Feature"

# Show PR details
az repos pr show --id PR_ID
5. Artifacts(包管理)
# List feeds
az artifacts feed list

# Create feed
az artifacts feed create --name "myfeed" --project MyProject

# List packages
az artifacts universal list --feed myfeed --project MyProject

# Publish package
az artifacts universal publish --feed myfeed --name mypackage --version 1.0.0 --path ./dist

# Download package
az artifacts universal download --feed myfeed --name mypackage --version 1.0.0 --path ./download

常见工作流

工作流 1:CI/CD 管道自动化
# Create pipeline, run it, and monitor
az pipelines create --name "API-Build" --repository myrepo --yml-path ci/azure-pipelines.yml
az pipelines run --name "API-Build" --branch main
az pipelines runs show --id RUN_ID --open  # Opens in browser
工作流 2:拉取请求审查自动化
# List active PRs, show details, add comment
az repos pr list --repository myrepo --status active --output table
az repos pr show --id 456 --open
az repos pr update --id 456 --status approved
工作流 3:批量创建工作项
# Create multiple work items from template
for title in "Feature A" "Feature B" "Feature C"; do
  az boards work-item create --type "User Story" --title "$title" --assigned-to [email protected]
done
工作流 4:管道状态仪表板
# Get recent pipeline runs with status
az pipelines runs list --top 10 --query "[].{Name:pipeline.name, Status:status, Result:result, Started:startTime}" --output table
工作流 5:存储库克隆自动化
# List all repos and clone them
az repos list --query "[].{Name:name, URL:remoteUrl}" --output tsv | while IFS=$'\t' read -r name url; do
  git clone "$url" "./$name"
done
工作流 6:冲刺规划助手
# List current sprint work items
az boards query --wiql "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.IterationPath] = @CurrentIteration" --output table
工作流 7:发布门禁检查
# Check if all PRs are approved before release
PENDING=$(az repos pr list --status active --query "length([?status!='approved'])")
if [ "$PENDING" -eq 0 ]; then
  az pipelines run --name "Release-Pipeline"
fi
工作流 8:制品版本管理
# Publish versioned artifact with timestamp
VERSION="1.0.$(date +%Y%m%d%H%M%S)"
az artifacts universal publish --feed myfeed --name myapp --version "$VERSION" --path ./build
工作流 9:团队仪表板数据
# Export team metrics to JSON
az devops project show --project MyProject > project.json
az pipelines runs list --top 50 > recent-runs.json
az repos pr list --status all > all-prs.json
工作流 10:环境同步
# Copy pipeline variables across environments
az pipelines variable list --pipeline-name "MyPipeline" --output json > vars.json
# Edit vars.json as needed
az pipelines variable-group create --name "Production" --variables @vars.json

故障排除

常见问题

身份验证失败:

# Clear cached credentials
az account clear
az login

# Use PAT token directly
export AZURE_DEVOPS_EXT_PAT=your_personal_access_token
az devops login

默认配置:

# Reset defaults if commands fail
az devops configure --defaults organization="" project=""
# Then set explicitly in each command
az pipelines list --organization https://dev.azure.com/myorg --project MyProject

扩展问题:

# Update Azure DevOps extension
az extension update --name azure-devops

# Check extension version
az extension show --name azure-devops

查询语法:

# WIQL queries require proper escaping
az boards query --wiql "SELECT [System.Id] FROM WorkItems WHERE [System.State] = 'Active' AND [System.AssignedTo] = '[email protected]'"

高级模式

REST API 访问
# Direct REST API calls for unsupported operations
az devops invoke --area build --resource builds --route-parameters project=MyProject --api-version 6.0 --http-method GET

# POST with JSON body
az devops invoke --area git --resource repositories --route-parameters project=MyProject --http-method POST --in-file payload.json
使用 JMESPath 编写脚本
# Complex queries using JMESPath
az pipelines runs list --query "[?result=='failed'].{Pipeline:pipeline.name, Branch:sourceBranch, Time:finishedDate}" --output table

# Filter and transform data
az repos pr list --query "[?targetRefName=='refs/heads/main' && status=='active'].{ID:pullRequestId, Title:title, Author:createdBy.displayName}"
别名与函数
# Create shell aliases for common commands
alias azdo-pipelines="az pipelines list --output table"
alias azdo-prs="az repos pr list --status active --output table"
alias azdo-builds="az pipelines runs list --top 20 --output table"

# Function for quick PR creation
azdo-pr() {
  az repos pr create --source-branch "$(git branch --show-current)" --target-branch main --title "$1" --open
}

扩展内容

如需完整的命令参考和高级工作流,请参阅:

  • 完整命令参考:examples/pipelines-reference.md、examples/boards-reference.md、examples/repos-reference.md、examples/artifacts-reference.md
  • 高级工作流:examples/workflows/ci-cd-automation.md、examples/workflows/release-management.md、examples/workflows/team-collaboration.md
  • 测试场景:tests/test-scenarios.md

参考资料

评论

支持 Markdown