首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure powershell API: DevOps获取测试点列表

Azure powershell API: DevOps获取测试点列表
EN

Stack Overflow用户
提问于 2021-06-12 08:10:38
回答 1查看 154关注 0票数 1

有没有办法通过Azure DevOps API获取测试点数据列表?

list

我尝试过这个powershell脚本

代码语言:javascript
复制
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

StatusCode: 404

StatusDescription:未找到

有人能告诉我我哪里做错了吗我刚开始使用powershell和azure devops rest api

EN

回答 1

Stack Overflow用户

发布于 2021-06-12 11:38:50

查看$tfsBaseUrl变量的内容。它包括组织名称,但不包括项目名称。您需要在URL中包含项目名称。查看文档,并将您的URL与文档的URL进行比较。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67944594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档