I'm trying to get all test results of a certain build with the Resultsbypipeline API. This works fine for the first 10,000 test results, but requires the use of a continuationToken for the remaining data.
According to the documentation I should set the continuationToken
header on the request, but even when doing so I still get the same first x results again and again in an endless loop:
$BuildId = 1234 # id of valid build
function InvokeDevOpsApi($ContinuationToken) {
# set to $top = 10 for testing purposes, but shouldn't matter..
$url = "=$buildId&`$top=10&api-version=7.1-preview.1"
$headers = @{}
if ($ContinuationToken) {
$headers['continuationToken'] = $ContinuationToken
}
$response = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials -Headers $headers
$continuationToken = $response.Headers['x-ms-continuationtoken']
$res = $response.Content | ConvertFrom-Json -Depth 100
[PSCustomObject]@{
ContinuationToken = $continuationToken
Tests = $res.value
}
}
$tests = New-Object -TypeName System.Collections.ArrayList
$ContinuationToken = $null
do {
$result = InvokeDevOpsApi $ContinuationToken
$tests.AddRange($result.Tests) > $null
$ContinuationToken = $result.ContinuationToken
} while ($ContinuationToken)
The response header always contains the x-ms-continuationtoken
header with the same value, so that's working.
I also tried:
- Passing it as a query parameter
continuationToken
as that seems to be done with some other APIs - Using
x-ms-continuationtoken
as the header name
I'm trying to get all test results of a certain build with the Resultsbypipeline API. This works fine for the first 10,000 test results, but requires the use of a continuationToken for the remaining data.
According to the documentation I should set the continuationToken
header on the request, but even when doing so I still get the same first x results again and again in an endless loop:
$BuildId = 1234 # id of valid build
function InvokeDevOpsApi($ContinuationToken) {
# set to $top = 10 for testing purposes, but shouldn't matter..
$url = "https://custom.tfs.instance/tfs/Org/Project/_apis/testresults/resultsbypipeline?pipelineId=$buildId&`$top=10&api-version=7.1-preview.1"
$headers = @{}
if ($ContinuationToken) {
$headers['continuationToken'] = $ContinuationToken
}
$response = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials -Headers $headers
$continuationToken = $response.Headers['x-ms-continuationtoken']
$res = $response.Content | ConvertFrom-Json -Depth 100
[PSCustomObject]@{
ContinuationToken = $continuationToken
Tests = $res.value
}
}
$tests = New-Object -TypeName System.Collections.ArrayList
$ContinuationToken = $null
do {
$result = InvokeDevOpsApi $ContinuationToken
$tests.AddRange($result.Tests) > $null
$ContinuationToken = $result.ContinuationToken
} while ($ContinuationToken)
The response header always contains the x-ms-continuationtoken
header with the same value, so that's working.
I also tried:
- Passing it as a query parameter
continuationToken
as that seems to be done with some other APIs - Using
x-ms-continuationtoken
as the header name
1 Answer
Reset to default 0You can try the API "Resultsbybuild - List" which has the same functional to list test results for a specified build.
This API can allow you to set the continuationToken
as a parameter to the request URI. When you call this API, if the current call does not return the last page of data, a continuationToken
is returned in the content of response, and then you can start a new API call with the returned continuationToken
to get the next page of data.
In addition, the API "Resultsbypipeline - List" and "Resultsbybuild - List" are new API added started from Azure DevOps REST API v7.1 and still in preview
version currently. Some functions on the preview
version API might be still in development, so, there might be some defects.
continuationToken
as an URL parameter as in this answer: stackoverflow/a/57982008/7571258 – zett42 Commented Mar 21 at 12:151699083_100002
so this shouldn't require url encoding. – Voo Commented Mar 21 at 12:33