如何通过VSTS查询或REST API获取两个版本间的工作项以生成发布说明?
Absolutely! You can absolutely pull work items between two versions (whether they’re releases or sprints) using either Azure DevOps’ built-in Query Editor or its REST API—both will let you build that Features > Stories > Tasks hierarchical list way faster than manual UI digging. Here’s how to tackle both approaches:
This is perfect if you need a quick, one-off list without writing any code:
- Head to Boards > Queries > New Query to create a new query.
- Select the Tree of Work Items query type—this is critical because it automatically displays work items in their natural parent-child hierarchy (Features → Stories → Tasks).
- Add filter clauses to target work items from your two versions:
- If you’re working with releases: Add a clause like
Fixed In ReleaseIn[Your Old Version], [Your Current Version]. UseWas Ever In Releaseinstead if you need to include items that were moved between the two versions. - If you’re using iterations (sprints): Use
Iteration PathIn[Old Iteration Name], [Current Iteration Name].
- If you’re working with releases: Add a clause like
- Narrow down the work item types to only what you need: Add a clause
Work Item TypeInFeature, User Story, Task. - Run the query—you’ll see the nested hierarchy exactly as you need it for release notes.
- Export the results as CSV/Excel, or just copy-paste the indented tree directly into your document (the UI preserves the hierarchy formatting).
If you want to automate this process (e.g., generate release notes programmatically), the REST API is the way to go:
Get your version IDs first:
- For releases: Call
GET https://dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1-preview.8to list all releases, then grab theidvalues for your target versions. - For iterations: Use
GET https://dev.azure.com/{organization}/{project}/_apis/work/teamsettings/iterations?api-version=7.1-preview.1to fetch iteration IDs.
- For releases: Call
Query work items with parent-child links:
- Use a WIQL (Work Item Query Language) query to pull relevant items. Example WIQL:
SELECT [System.Id], [System.Title], [System.WorkItemType], [System.Parent] FROM WorkItems WHERE [System.TeamProject] = @project AND [System.FixedInRelease] IN ('Release v1.0', 'Release v2.0') AND [System.WorkItemType] IN ('Feature', 'User Story', 'Task') - Send this query via the API:
POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=7.1-preview.2(pass the WIQL in the request body as JSON).
- Use a WIQL (Work Item Query Language) query to pull relevant items. Example WIQL:
Build the hierarchical structure:
- For each work item in the response, map it to its parent using the
System.Parentfield. - Write a simple script (Python, PowerShell, etc.) to group Tasks under their parent Stories, and Stories under their parent Features.
- Pro tip: Use the
$expand=relationsparameter in the work items get API to fetch parent details in a single call, saving you from extra requests.
- For each work item in the response, map it to its parent using the
Either method will eliminate that tedious manual association work you’re dealing with now. Pick the one that fits your workflow best!
内容的提问来源于stack exchange,提问作者Ralf de Kleine

