最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powershell - Continuation Token with Azure Devops Resultsbypipeline - Stack Overflow

programmeradmin8浏览0评论

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
Share Improve this question edited Mar 21 at 12:07 Voo asked Mar 21 at 11:59 VooVoo 30.3k13 gold badges89 silver badges163 bronze badges 7
  • Try to pass continuationToken as an URL parameter as in this answer: stackoverflow/a/57982008/7571258 – zett42 Commented Mar 21 at 12:15
  • @Zett42 That's under "I also tried" - sadly doesn't work either. – Voo Commented Mar 21 at 12:19
  • How does that continuation token look like? Does it contain special characters that need to be URL-encoded? – zett42 Commented Mar 21 at 12:31
  • @Zett42: It's of the form 1699083_100002 so this shouldn't require url encoding. – Voo Commented Mar 21 at 12:33
  • 1 Do you need the value of the token? $ContinuationToken.Value – jdweng Commented Mar 21 at 14:00
 |  Show 2 more comments

1 Answer 1

Reset to default 0

You 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.

发布评论

评论列表(0)

  1. 暂无评论