powershell - Azure DevOps API:powershell 获取测试点列表
问题描述
有没有办法通过 Azure DevOps API 获取测试点数据列表?
我试过这个powershell脚本
function GetUrl() {
param(
[string]$orgUrl,
[hashtable]$header,
[string]$AreaId
)
# Area ids
# https://docs.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http&viewFallbackFrom=vsts#resource-area-ids-reference
# Build the URL for calling the org-level Resource Areas REST API for the RM APIs
$orgResourceAreasUrl = [string]::Format("{0}/_apis/resourceAreas/{1}?api-preview=5.0-preview.1", $orgUrl, $AreaId)
# Do a GET on this URL (this returns an object with a "locationUrl" field)
$results = Invoke-RestMethod -Uri $orgResourceAreasUrl -Headers $header
# The "locationUrl" field reflects the correct base URL for RM REST API calls
if ("null" -eq $results) {
$areaUrl = $orgUrl
}
else {
$areaUrl = $results.locationUrl
}
return $areaUrl
}
$orgUrl = "https://dev.azure.com/fodservices"
$personalToken = "<my token pat>"
Write-Host "Initialize authentication context" -ForegroundColor Yellow
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}
Write-Host "Demo 3"
$coreAreaId = "3b95fb80-fdda-4218-b60e-1052d070ae6b"
$tfsBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId
$relDefUrl = "$($tfsBaseUrl)/_apis/testplan/Plans/70152/Suites/70154/TestPoint?api-version=5.0-preview.2"
try {
$output = Invoke-RestMethod -Uri $relDefUrl -Method Get -ContentType "application/json" -Headers $header
}
catch{
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}
$output.value | ForEach-Object {
Write-Host $_.id
}
结果是:
演示 3
状态码:404
状态描述:未找到
谁能告诉我我在使用 powershell 和 azure devops rest api 时做错了什么
解决方案
查看$tfsBaseUrl
变量的内容。它包括组织名称,但不包括项目名称。您需要在 URL 中包含项目名称。查看文档并将您的 URL 与文档的 URL 进行比较。
推荐阅读
- php - 从一个字符串中分解多个元素
- rollback - xen-hypervisor - 正确的快照和恢复方式
- html - 仅管理包含 * ngFor 的第一个 div 父级的不透明度
- html - Wrong height of youtube-iframe inside flexbox item
- angularjs - angularjs 在使用 POST 向服务器发送数据时导致 json 格式错误
- safari - requirejs从不同路径加载文件
- opengl - 解析 gl.xml - 不一致?
- sql-server - SSIS - 超大文件 (500MB) 因 OutOfMemory 异常而失败
- mysql - MySQL - 确定存在于给定列表中但不存在于表中的数据
- python - 如何使用 swig C++ 命名空间作为 python 模块公开