【问题标题】:How to get TFS build report in PowerShell with REST API [duplicate]如何使用 REST API 在 PowerShell 中获取 TFS 构建报告 [重复]
【发布时间】:2020-11-11 19:55:12
【问题描述】:

我正在尝试通过 REST API 使用 PowerShell 脚本获取构建报告 https://docs.microsoft.com/en-us/rest/api/azure/devops/build/report/get?view=vsts-rest-tfs-4.1

$PAT = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
# Base64-encodes the Personal Access Token (PAT) appropriately
# This is required to pass PAT through HTTP header
$script:User = "" # Not needed when using PAT, can be set to anything
$script:Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $PAT)))

$url = "$TfsUri/$TeamProject/_apis/build/builds/$buildId/report?api-version=4.1-preview.2"
$buildReport = Invoke-RestMethod -Uri $url -Method GET -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}

但我收到错误报告不支持请求的流

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Requested stream  is not supported for reports.","typeName":"Microsoft.TeamFoundation.Build.WebApi.ReportStreamNotSupportedE 
xception, Microsoft.TeamFoundation.Build2.WebApi","typeKey":"ReportStreamNotSupportedException","errorCode":0,"eventId":3000}
At C:\Source\Configurations\Scripts\CheckLastBuild.ps1:76 char:20
+ ... ildReport = Invoke-RestMethod -Uri $url -Method GET -Headers @{Author ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

使用浏览器调用相同的请求可以正常工作,并返回带有构建报告的 HTML 文本。

我做错了什么?使用相同的方法毫无问题地获取定义、构建、发布...

【问题讨论】:

    标签: powershell tfs azure-devops-rest-api


    【解决方案1】:

    您需要添加以下网址参数:

    type=html
    

    所以,在你的情况下:

    $url = "$TfsUri/$TeamProject/_apis/build/builds/$buildId/report?api-version=4.1-preview.2&type=html"
    

    【讨论】:

    • 感谢您的成功。你知道这个参数的允许值是多少吗?文档没有显示任何细节。
    • 我不知道,但有人在这里回答stackoverflow.com/questions/49976217/…,它只是html
    猜你喜欢
    • 2018-08-22
    • 2016-07-19
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 2015-10-01
    • 2019-10-13
    • 2018-04-02
    • 1970-01-01
    相关资源
    最近更新 更多