Home > OS >  Get all Tests ran in Azure Build Pipeline through REST API
Get all Tests ran in Azure Build Pipeline through REST API

Time:07-01

I'm trying to get a list of all tests ran from a Azure Pipeline build through the Azure REST API. I'm trying to use this API call but get an empty list every time:

GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?buildUri={buildUri}&$top={$top}&api-version=6.0

where I'm using the BuildID as the buildUri. Should I be using something else as the buildUri? I only want the top test runs from one build pipeline, not from all pipelines in the project. Even better if I could only get all the tests from one run of the pipeline.

Currently, the only way I've found to solve this is by using the above call to get all runs (none of them have a Build property with data), so I can then use the ids from that call to make the following API call to get which build it is, and filter it manually from there. However, this is way more API calls and data downloaded than I wanted. I want a simple way to get all test runs from a build id.

GET https://dev.azure.com/{organization}/{project}/_apis/test/runs/{runId}?api-version=6.0

CodePudding user response:

I want a simple way to get all test runs from a build id.

As suggested by Xue Meng:

To get the results of each test run:

GET https://vstmr.dev.azure.com/{Orginazation name}/{Project name}/_apis/testresults/resultsbypipeline?pipelineId={buildID}&$top=20000?api-version=5.2-preview.1

To get the total number of passed tests:

GET https://vstmr.dev.azure.com/{Orginazation name}/{Project name}/_apis/testresults/resultdetailsbybuild?buildId={buildID}&publishContext=CI&groupBy=TestRun&$filter=Outcome eq Failed&$orderby=&shouldIncludeResults=true&queryRunSummaryForInProgress=false?api-version=5.2-preview.1

According to Chubsdad, this seems to be working to get the test result by buildID:

GET https://vstmr.dev.azure.com{org}/{proj}/_apis/testresults/resultdetailsbybuild?buildId={id}&groupBy=TestRun
  • Related