【问题标题】:Azure Devops - use a script to access the number of build validation pipelines in a Pull RequestAzure Devops - 使用脚本访问 Pull Request 中构建验证管道的数量
【发布时间】:2022-12-18 02:30:17
【问题描述】:

我想在合并请求 (PR) 中访问构建验证管道检查的数量。 我希望我可以使用 powershell 来集成 azure api,即 https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/get-pull-request?view=azure-devops-rest-7.0

这个好像没有这个信息。 有谁知道这是否可以实现?

【问题讨论】:

  • AzDO 是一个 SAP 应用程序。在导航器控制台中,您可以检索客户端执行的所有请求。
  • 似乎此端点下的构建验证信息:POST http://azuredevops.pasquier.loc:8080/tfs/SI/_apis/Contribution/dataProviders/query/project/{project-guid}。这是一个专用端点。有关此的更多信息post

标签: azure azure-devops azure-pipelines devops azure-powershell


【解决方案1】:

我想在合并请求 (PR) 中访问构建验证管道检查的数量。

为了满足您的要求,您可以使用 Rest API:Evaluations - List 获取 Pull Request 中的构建数。

这是一个例子:

休息 API 网址:

GET https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId={artifactId}&api-version=7.1-preview.1

ArtifactID 示例:

vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}

PowerShell 示例:

$token = "PAT"

$url=" https://dev.azure.com/ORGNAME/PROJECTNAME/_apis/policy/evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/projectid/pullrequestid&api-version=7.1-preview.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Method Get  -Headers @{Authorization = "Basic $token"}   -ContentType 'application/json'

$number = 0

Foreach( $configurationlist in $response.value )
{
   $buildid =  $configurationlist.configuration.settings.buildDefinitionId
   $type = $configurationlist.configuration.type.displayName

   if($type -eq "Build")

    {
       echo $buildid
       $number= $number+ 1
    }   
 
   

}


echo "Pull Request Build Number: $number"

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2021-03-09
    相关资源
    最近更新 更多