Reputation: 25477
As part of my scheduled builds, I run and publish multiple tests which are having different test run titles.
My scenario is that during the release pipeline, I want to fetch the test summary for each of the test run titles that were published for the build from which release is being created.
Which Azure DevOps API or combination of APIs can be used to achieve this?
Thanks, Anubhav.
Upvotes: 4
Views: 2663
Reputation: 1638
You can do this in C# using the Microsoft.TeamFoundationServer.Client nuget package with this code:
int buildId = <buildId>;
var baseUri = new Uri("https://dev.azure.com/<your org>");
string project = "<your project>";
var credential = new VssBasicCredential(string.Empty, "<your PAT>");
var buildClient = new BuildHttpClient(baseUri, credential);
var build = await buildClient.GetBuildAsync(project, buildId);
var testManagementClient = new TestManagementHttpClient(baseUri, credential);
var testRuns = await testManagementClient.GetTestRunsAsync(project, build.Uri.AbsoluteUri);
Upvotes: 0
Reputation: 11
Having BuildId,
step1: use this api https://dev.azure.com/{organization}/{project}/_apis/test/ResultDetailsByBuild?buildId={buildId} , get run id through this api rather than from URL.
step2: GET https://dev.azure.com/{organization}/{project}/_apis/test/runs/{runId}?api-version=6.0 to get Test run results in detail.
for reference
hope it would be helpful :)
Upvotes: 1
Reputation: 1214
The test result of the build is stored in test runs, so you need the test runs if you want the test results.
Use GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/report?api-version=5.1-preview.2
from Report - Get to get the test runs.
Then use GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?api-version=5.1
from Results - List to get the test results.
Or you can use GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?api-version=5.1
from Runs - List directly get the test runs.
Upvotes: 0