如何使用 REST 在 PowerShell 中获取 TFS 构建报告 API
How to get TFS build report in PowerShell with REST API
我正在尝试通过 REST 使用 PowerShell 脚本获取构建报告 API
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
使用浏览器调用相同的请求工作正常,并且 returns 带有构建报告的 HTML 文本。
我做错了什么?使用相同的方法毫无问题地获取定义、构建、发布...
您需要添加以下URL参数:
type=html
因此,在您的情况下:
$url = "$TfsUri/$TeamProject/_apis/build/builds/$buildId/report?api-version=4.1-preview.2&type=html"
我正在尝试通过 REST 使用 PowerShell 脚本获取构建报告 API 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
使用浏览器调用相同的请求工作正常,并且 returns 带有构建报告的 HTML 文本。
我做错了什么?使用相同的方法毫无问题地获取定义、构建、发布...
您需要添加以下URL参数:
type=html
因此,在您的情况下:
$url = "$TfsUri/$TeamProject/_apis/build/builds/$buildId/report?api-version=4.1-preview.2&type=html"