Azure DevOps REST API スキル
作業項目、パイプライン、リポジトリ、テスト計画、Wiki、検索機能など、Azure DevOps REST API v7.2 の操作に関する包括的なガイドです。
クイックリファレンス
| 領域 | ベース URL | MCP ツールのプレフィックス |
|---|
| コア | dev.azure.com/{org}/_apis/ | mcp__ado__core_* |
| 作業項目 | dev.azure.com/{org}/{project}/_apis/wit/ | mcp__ado__wit_* |
| パイプライン | dev.azure.com/{org}/{project}/_apis/pipelines/ | mcp__ado__pipelines_* |
| Git/リポジトリ | dev.azure.com/{org}/{project}/_apis/git/ | mcp__ado__repo_* |
| テスト計画 | dev.azure.com/{org}/{project}/_apis/testplan/ | mcp__ado__testplan_* |
| Wiki | dev.azure.com/{org}/{project}/_apis/wiki/ | mcp__ado__wiki_* |
| 検索 | almsearch.dev.azure.com/{org}/_apis/search/ | mcp__ado__search_* |
認証方法
個人用アクセストークン(PAT)
# Base64 encode empty username with PAT
AUTH=$(echo -n ":${PAT}" | base64)
curl -H "Authorization: Basic ${AUTH}" https://dev.azure.com/{org}/_apis/projects
OAuth 2.0 スコープ
| スコープ | アクセスレベル |
|---|
vso.work | 作業項目の読み取り |
vso.work_write | 作業項目の作成/更新 |
vso.code | ソースコードの読み取り |
vso.code_write | ブランチ、PR の作成 |
vso.build_execute | パイプラインの実行 |
vso.test | テスト計画の読み取り |
vso.wiki | Wiki の読み取り |
API のバージョン管理
形式:{major}.{minor}[-{stage}[.{resource-version}]]
- 現在のバージョン:
7.2-preview.3
- 例:
api-version=7.2-preview.3
1. 作業項目の操作
利用可能な MCP ツール
mcp__ado__wit_get_work_item - Get single work item
mcp__ado__wit_get_work_items_batch_by_ids - Get multiple work items
mcp__ado__wit_my_work_items - Get items assigned to me
mcp__ado__wit_create_work_item - Create new work item
mcp__ado__wit_update_work_item - Update work item fields
mcp__ado__wit_update_work_items_batch - Bulk update work items
mcp__ado__wit_add_work_item_comment - Add comment to work item
mcp__ado__wit_list_work_item_comments - List work item comments
mcp__ado__wit_add_child_work_items - Create child work items
mcp__ado__wit_work_items_link - Link work items together
mcp__ado__wit_work_item_unlink - Remove work item links
mcp__ado__wit_link_work_item_to_pull_request - Link to PR
mcp__ado__wit_add_artifact_link - Add artifact links (branch, commit, build)
mcp__ado__wit_get_work_item_type - Get work item type definition
mcp__ado__wit_list_backlogs - List team backlogs
mcp__ado__wit_list_backlog_work_items - Get backlog items
mcp__ado__wit_get_work_items_for_iteration - Get sprint items
mcp__ado__wit_get_query - Get saved query
mcp__ado__wit_get_query_results_by_id - Execute saved query
WIQL クエリ構文
基本構造
SELECT [Fields]
FROM workitems
WHERE [Conditions]
ORDER BY [Fields]
ASOF [DateTime]
よく使われるマクロ
| マクロ | 説明 |
|---|
@Me | 現在のユーザー |
@project | 現在のプロジェクト |
@Today | 今日の日付 |
@Today - N | N 日前 |
@CurrentIteration | 現在のスプリント |
@StartOfMonth | 月の初日 |
クエリの例
-- Active tasks assigned to me
SELECT [System.Id], [System.Title], [System.State]
FROM workitems
WHERE [System.TeamProject] = @project
AND [System.WorkItemType] = 'Task'
AND [System.State] = 'Active'
AND [System.AssignedTo] = @Me
ORDER BY [System.Priority] ASC
-- Bugs created in last 30 days
SELECT [System.Id], [System.Title], [System.CreatedDate]
FROM workitems
WHERE [System.TeamProject] = @project
AND [System.WorkItemType] = 'Bug'
AND [System.CreatedDate] >= @Today - 30
-- Parent-child hierarchy
SELECT [Source].[System.Id], [Target].[System.Id]
FROM workitemLinks
WHERE [Source].[System.TeamProject] = @project
AND [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward'
MODE (Recursive)
JSON Patch 操作
[
{"op": "add", "path": "/fields/System.Title", "value": "New Title"},
{"op": "replace", "path": "/fields/System.State", "value": "Active"},
{"op": "add", "path": "/relations/-", "value": {
"rel": "System.LinkTypes.Related",
"url": "https://dev.azure.com/{org}/_apis/wit/workItems/{id}"
}}
]
リンクタイプのリファレンス
| タイプ | Rel 名 |
|---|
| 親 | System.LinkTypes.Hierarchy-Reverse |
| 子 | System.LinkTypes.Hierarchy-Forward |
| 関連 | System.LinkTypes.Related |
| 先行 | System.LinkTypes.Dependency-Reverse |
| 後続 | System.LinkTypes.Dependency-Forward |
2. パイプラインの操作
利用可能な MCP ツール
mcp__ado__pipelines_get_build_definitions - List pipeline definitions
mcp__ado__pipelines_get_build_definition_revisions - Get definition history
mcp__ado__pipelines_get_builds - List builds
mcp__ado__pipelines_get_build_status - Get build status
mcp__ado__pipelines_get_build_log - Get build logs
mcp__ado__pipelines_get_build_log_by_id - Get specific log
mcp__ado__pipelines_get_build_changes - Get commits in build
mcp__ado__pipelines_run_pipeline - Trigger pipeline run
mcp__ado__pipelines_get_run - Get pipeline run details
mcp__ado__pipelines_list_runs - List pipeline runs
mcp__ado__pipelines_update_build_stage - Retry/cancel stage
パイプラインのトリガー例
{
"resources": {
"repositories": {
"self": {"refName": "refs/heads/feature-branch"}
}
},
"templateParameters": {
"environment": "staging"
},
"variables": {
"customVar": {"value": "custom-value", "isSecret": false}
}
}
ビルドのステータス値
| ステータス | 説明 |
|---|
none | 未開始 |
inProgress | 実行中 |
completed | 完了 |
cancelling | キャンセル中 |
postponed | 延期 |
notStarted | キューに登録済み |
ビルド結果の値
| 結果 | 説明 |
|---|
succeeded | すべてのタスクが成功 |
partiallySucceeded | 一部のタスクが失敗 |
failed | ビルドに失敗 |
canceled | ユーザーがキャンセル |
3. リポジトリの操作
利用可能な MCP ツール
mcp__ado__repo_list_repos_by_project - List repositories
mcp__ado__repo_get_repo_by_name_or_id - Get repository details
mcp__ado__repo_list_branches_by_repo - List branches
mcp__ado__repo_list_my_branches_by_repo - List my branches
mcp__ado__repo_get_branch_by_name - Get branch details
mcp__ado__repo_create_branch - Create new branch
mcp__ado__repo_search_commits - Search commit history
mcp__ado__repo_list_pull_requests_by_repo_or_project - List PRs
mcp__ado__repo_get_pull_request_by_id - Get PR details
mcp__ado__repo_create_pull_request - Create PR
mcp__ado__repo_update_pull_request - Update PR (autocomplete, status)
mcp__ado__repo_update_pull_request_reviewers - Add/remove reviewers
mcp__ado__repo_list_pull_request_threads - List PR comments
mcp__ado__repo_list_pull_request_thread_comments - Get thread comments
mcp__ado__repo_create_pull_request_thread - Create comment thread
mcp__ado__repo_reply_to_comment - Reply to comment
mcp__ado__repo_resolve_comment - Resolve thread
mcp__ado__repo_list_pull_requests_by_commits - Find PR by commit
PR のステータス値
| ステータス | 説明 |
|---|
active | レビュー待ち |
abandoned | マージせずにクローズ |
completed | マージ済み |
マージ戦略
| 戦略 | 説明 |
|---|
noFastForward | マージコミット(デフォルト) |
squash | コミットをスカッシュ |
rebase | リベースしてファストフォワード |
rebaseMerge | リベースしてマージコミットを作成 |
4. テスト計画の操作
利用可能な MCP ツール
mcp__ado__testplan_list_test_plans - List test plans
mcp__ado__testplan_create_test_plan - Create test plan
mcp__ado__testplan_create_test_suite - Create test suite
mcp__ado__testplan_list_test_cases - List test cases in suite
mcp__ado__testplan_create_test_case - Create test case
mcp__ado__testplan_update_test_case_steps - Update test steps
mcp__ado__testplan_add_test_cases_to_suite - Add cases to suite
mcp__ado__testplan_show_test_results_from_build_id - Get test results
テストケースのステップ形式
1. Navigate to login page|Login page displayed
2. Enter username|Username field populated
3. Enter password|Password field populated
4. Click login button|User is logged in successfully
テストスイートのタイプ
| タイプ | 説明 |
|---|
staticTestSuite | 手動で構成する階層 |
dynamicTestSuite | クエリベース |
requirementTestSuite | 要件にリンク |
テスト結果の値
| 結果 | 説明 |
|---|
Passed | テストに合格 |
Failed | テストに失敗 |
Blocked | 実行できない |
NotExecuted | 未実行 |
Inconclusive | 明確な結果なし |
5. Wiki の操作
利用可能な MCP ツール
mcp__ado__wiki_list_wikis - List wikis
mcp__ado__wiki_get_wiki - Get wiki details
mcp__ado__wiki_list_pages - List wiki pages
mcp__ado__wiki_get_page - Get page metadata
mcp__ado__wiki_get_page_content - Get page content
mcp__ado__wiki_create_or_update_page - Create/update page
Wiki のタイプ
| タイプ | 説明 |
|---|
projectWiki | プロジェクトスコープの Wiki |
codeWiki | Git 管理の Wiki |
ページパスの形式
- ルート:
/
- サブページ:
/Parent/Child
- スペース:
/My%20Page
6. 検索操作
利用可能な MCP ツール
mcp__ado__search_code - Search source code
mcp__ado__search_workitem - Search work items
mcp__ado__search_wiki - Search wiki pages
コード検索フィルター
{
"Project": ["project-name"],
"Repository": ["repo-name"],
"Path": ["/src"],
"Branch": ["main"],
"CodeElement": ["class", "def", "function"]
}
###作業項目検索フィルター
{
"System.TeamProject": ["project-name"],
"System.WorkItemType": ["Bug", "Task"],
"System.State": ["Active", "New"],
"System.AssignedTo": ["[email protected]"]
}
7. コア操作
利用可能な MCP ツール
mcp__ado__core_list_projects - List projects
mcp__ado__core_list_project_teams - List teams
mcp__ado__core_get_identity_ids - Get user identity
mcp__ado__work_list_team_iterations - List iterations
mcp__ado__work_list_iterations - List all iterations
mcp__ado__work_create_iterations - Create iterations
mcp__ado__work_assign_iterations - Assign to team
mcp__ado__work_get_team_capacity - Get team capacity
mcp__ado__work_update_team_capacity - Update capacity
mcp__ado__work_get_iteration_capacities - Get iteration capacity
8. 高度なセキュリティ操作
利用可能な MCP ツール
mcp__ado__advsec_get_alerts - Get security alerts
mcp__ado__advsec_get_alert_details - Get alert details
アラートの種類
| 種類 | 説明 |
|---|
Dependency | 脆弱な依存関係 |
Secret | 漏えいしたシークレット |
Code | コードの脆弱性 |
レート制限
TSTU(スループット単位)の上限
- 匿名:200 TSTU/分
- 認証済み:1200 TSTU/分
レスポンスヘッダー
X-RateLimit-Resource: core
X-RateLimit-Delay: 500
X-RateLimit-Limit: 1200
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1609459200
Retry-After: 30
レート制限への対処
import time
import requests
def api_call_with_retry(url, headers, max_retries=3):
for attempt in range(max_retries):
response = requests.get(url, headers=headers)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 30))
time.sleep(retry_after)
continue
return response
raise Exception("Rate limit exceeded after retries")
エラー処理
HTTP ステータスコード
| コード | 意味 |
|---|
| 200 | 成功 |
| 201 | 作成済み |
| 204 | コンテンツなし(DELETE) |
| 400 | 不正なリクエスト |
| 401 | 認証されていません |
| 403 | 禁止されています |
| 404 | 見つかりません |
| 409 | 競合(バージョン) |
| 429 | レート制限 |
| 500 | サーバーエラー |
エラーレスポンスの形式
{
"$id": "1",
"innerException": null,
"message": "Error description",
"typeName": "Microsoft.VisualStudio.Services.WebApi.VssServiceException",
"typeKey": "VssServiceException",
"errorCode": 0
}
共通フィールドのリファレンス
システムフィールド
| フィールド | 参照名 |
|---|
| ID | System.Id |
| タイトル | System.Title |
| 状態 | System.State |
| 担当者 | System.AssignedTo |
| エリアパス | System.AreaPath |
| イテレーションパス | System.IterationPath |
| 作業項目の種類 | System.WorkItemType |
| 作成日 | System.CreatedDate |
| 変更日 | System.ChangedDate |
| タグ | System.Tags |
| 説明 | System.Description |
スケジュールフィールド
| フィールド | 参照名 |
|---|
| ストーリーポイント | Microsoft.VSTS.Scheduling.Effort |
| 残作業 | Microsoft.VSTS.Scheduling.RemainingWork |
| 当初の見積もり | Microsoft.VSTS.Scheduling.OriginalEstimate |
| 完了した作業 | Microsoft.VSTS.Scheduling.CompletedWork |
複数リポジトリでの作業項目の分離
1 つの Azure DevOps プロジェクトに複数のリポジトリが含まれている場合は、主な分離に エリアパス を使用し、リポジトリ単位のスプリント/エピックの追跡には 階層型イテレーションパス を使用します。
目標の構造
Area Paths: Iteration Paths:
project\ project\Iteration\
├── repo-a (per-repo) ├── Sprint 1 (shared across repos)
├── repo-b (per-repo) ├── Sprint 2 (shared across repos)
└── repo-c (per-repo) ├── repo-a\ (repo-scoped container)
│ ├── epic-1-... (auto-created by sync)
│ └── epic-2-...
└── repo-b\ (repo-scoped container)
パス形式の違い(重要)
Azure DevOps では、イテレーションに 異なる 2 種類のパス形式が使用されます。
| 操作 | 形式 | 例 |
|---|
az boards iteration project create --path | \Project\Iteration\Parent(「Iteration」セグメントが文字どおり必要) | \devops-team\Iteration\azure-quota-automation |
az boards work-item update --iteration | Project\Parent\Child(「Iteration」セグメントなし、先頭の \ なし) | devops-team\azure-quota-automation\epic-1-slug |
新しいリポジトリのセットアップコマンド
# 1. Create area path (if not exists)
az boards area project create --name "<repo-name>" --path "\<project>"
# 2. Create iteration container
az boards iteration project create --name "<repo-name>" --path "\<project>\Iteration"
# 3. Configure BMAD sync (devops-sync-config.yaml)
# areaPath: "<project>\\<repo-name>"
# iterationRootPath: "<repo-name>"
イテレーションの移動(ネイティブの移動機能なし)
Azure DevOps CLI には、イテレーションを移動する move コマンドがありません。再構成するには、次の手順を実行します。
- 作業項目が割り当てられていないことを確認します:
az boards query --wiql "... WHERE [System.IterationPath] = '...'"
- 削除します:
az boards iteration project delete --path "\project\Iteration\old-path" --yes
- 新しい親の下に再作成します:
az boards iteration project create --name "name" --path "\project\Iteration\new-parent"
- 状態ファイルを新しいイテレーション ID で更新します
よくあるエラー:TF401347
TF401347: The iteration path does not exist — 誤ったパス形式を使用した場合に発生します。次を確認してください。
- 作業項目の
--iteration では Project\Parent\Child を使用します(「Iteration」セグメントなし)
- イテレーション作成の
--path では \Project\Iteration\Parent を使用します(「Iteration」セグメントあり)
ベストプラクティス
1. バッチ操作を使用する
- 複数の単一呼び出しではなく、
mcp__ado__wit_get_work_items_batch_by_ids を使用します
- 1 回のバッチリクエストで指定できる項目は最大 200 件です
2. フィールド選択を最小限にする
- 必要なフィールドのみをリクエストします:
fields=System.Id,System.Title,System.State
- レスポンスサイズと API 負荷を軽減できます
3. ページネーションを処理する
- 大きな結果セットには
$top と $skip を使用します
- 継続トークンが提供された場合は、それに従います
4. バージョン管理
- 楽観的同時実行制御には、JSON Patch の
test 操作を使用します
- 更新する前に、必ず
rev フィールドを確認します
5. エラー復旧
- レート制限に対して指数バックオフを実装します
- レスポンスヘッダーの相関 ID をログに記録します
参考資料