TFS 2018/2019是否支持主构建汇总多触发构建的测试结果?
Great question! TFS 2018 and 2019 do offer practical ways to aggregate test results from dependent/triggered builds into your main build's summary. Here are the most reliable approaches:
1. Use the Test Results Aggregator Task (Marketplace Extension)
This is the simplest no-code solution. You can install the Test Results Aggregator extension directly from your TFS instance's Marketplace. Once added to your pipeline:
- Add the task to your main build definition, making sure it runs after your triggered test builds have completed.
- Configure it to target the specific triggered builds (you can reference their build IDs via pipeline variables if you captured those IDs when triggering the builds initially).
- The task will automatically pull all test results from the specified builds, calculate total passed/failed/unrun counts, and publish a clean aggregated summary to your main build's dashboard.
2. Custom PowerShell Script with TFS REST API
If you need more control over the aggregation logic, you can build a custom solution using TFS's REST API and a PowerShell script:
- Capture triggered build IDs: When triggering your parallel/non-parallel test builds from the main build, store their
Build.BuildIdvalues in pipeline variables (most trigger tasks expose this output). - Fetch test results: Use the REST endpoint
GET https://<your-tfs-server>/<collection>/<project>/_apis/test/runs?buildId=<triggered-build-id>&api-version=5.0to retrieve all test runs for each triggered build. - Aggregate metrics: Loop through each returned test run, summing up the passed, failed, and unrun test counts across all runs.
- Publish results: Use the built-in
Publish Test Resultstask to push the aggregated counts as a new test run, or write a formatted markdown summary directly to the build logs withWrite-Hostfor quick visibility.
3. Link Test Runs via Summary Extensions
Several TFS Marketplace extensions specialize in linking test runs from related builds and displaying combined statistics in the main build summary. Look for extensions tagged with "test aggregation" or "build summary"—many will automatically detect dependent builds and show aggregated pass/fail rates without requiring manual configuration.
Key Considerations
- Ensure your main build service account has read access to the test results of the triggered builds.
- If your test builds run asynchronously, add a wait step in the main build (like the
Wait for Buildtask or a custom status-check script) to ensure they finish before aggregation starts. - For custom scripts, handle edge cases (e.g., builds with no test results or failed test runs) to avoid errors in your aggregation logic.
内容的提问来源于stack exchange,提问作者Noa Sasson

