基于Build ID通过VSTS API获取变更集及关联项目的技术问询
Great question! While the TFVC Changesets Get API doesn’t let you filter directly by Build ID, you can absolutely pull changesets linked to a specific build and get their associated projects—you just need to use the right Azure DevOps (formerly VSTS) APIs for the job. Here’s how to handle both of your requirements:
1. Retrieve Changesets by Build ID
The Build Changes API is purpose-built for this scenario. For VSTS 2018 (which uses API version 4.1), your request would look like this:
GET https://{your-account}.visualstudio.com/{your-project}/_apis/build/builds/{buildId}/changes?api-version=4.1
This endpoint returns a list of all changes (both TFVC changesets and Git commits) tied to the specified build. Each entry will include the changesetId for TFVC items, plus basic metadata like the author, commit message, and timestamp.
2. Get the Project Associated with Each Changeset
You don’t need a separate API call for this—the Build Changes API response already includes project details for every change. Here’s a sample snippet of what you’ll see for a TFVC changeset:
{ "count": 1, "value": [ { "id": "12345", "author": { "displayName": "Jane Smith", "uniqueName": "jane.smith@example.com" }, "message": "Updated checkout flow", "changesetId": 12345, "project": { "id": "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6", "name": "ECommerceProject", "url": "https://your-account.visualstudio.com/_apis/projects/a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6" }, "date": "2018-09-15T09:45:00Z" } ] }
The project field gives you the project’s name and ID directly. If you need more details about the project (like its description or visibility), you can use the Projects Get API with the project ID from this response.
Why the TFVC Changesets Get API Isn’t the Right Fit
The TFVC Changesets Get endpoint (/tfvc/changesets/{changesetId}) is designed to fetch full details for a single changeset when you already know its ID—it doesn’t support filtering or querying by build association. That’s why starting with the Build Changes API is the correct approach here.
- If you need to pull full details for a specific changeset (like all modified files), take the
changesetIdfrom the Build Changes response and call the TFVC Changesets Get API, specifying the project ID from the same entry:GET https://{your-account}.visualstudio.com/{projectId}/_apis/tfvc/changesets/{changesetId}?api-version=4.1 - Ensure you have the necessary permissions (e.g., Build Read and TFVC Read) to access these endpoints.
内容的提问来源于stack exchange,提问作者doorman

