如何查询我们的 dev azure 项目中所有管道的 yaml 文件路径?

问题描述 投票:0回答:2

我想列出任何 DevOps 管道中使用的所有 yaml 文件。我能做到:

az pipelines show --project ProjectName --query '{pipeline:name,repo:repository.name,yml:process.yamlFilename}' --output table --name PipelineName

并得到正确的结果:

Pipeline       Repo           Yml
-------------  -------------  ---------------------------------------
PipelineName   RepoName       path/to/azure-pipeline.yaml

但是如果我

list
而不是
show
—— 我想要所有的,而不是一次一个 ——
list
不会返回相同级别的细节。它没有为我提供存储库和流程数据,因此我无法列出存储库名称或 yaml 路径。

如何获取所有我的管道的存储库名称和 yaml 路径?

azure azure-devops azure-pipelines
2个回答
2
投票

要获取所有管道的存储库名称和 yaml 路径,您可以使用 REST API 列出所有管道,并获取每个管道详细信息,然后根据结果获取存储库。最后,生成一个包含管道名称、存储库名称和路径的文件。这是整个过程的 PowerShell 脚本。请替换为您自己的PAT、组织名称、项目名称和您要存储文件的路径。这里为经典管道设置path=null

$PAT ="<PAT>"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic $base64AuthInfo")
$response = Invoke-RestMethod "https://dev.azure.com/<orgName>/<ProjectName>/_apis/pipelines?api-version=6.0-preview.1" -Method 'GET' -Headers $headers
$response | ConvertTo-Json   

foreach ($value in $response.value)
  {
  $mid=$value.id
  $url = "https://dev.azure.com/<orgName>/<ProjectName>/_apis/pipelines/"+$mid+"?api-version=7.1-preview.1"
  $pipeline = Invoke-RestMethod $url -Method 'GET' -Headers $headers
  $pipeline | ConvertTo-Json
  $pipelinename = $pipeline.name
  if ($pipeline.configuration.path)
    {
    $path=$pipeline.configuration.path
    $repositoryid=$pipeline.configuration.repository.id
    $url = "https://dev.azure.com/<orgName>/<ProjectName>/_apis/git/repositories/"+$repositoryid+"?api-version=6.0"
    $repositorydetails = Invoke-RestMethod $url -Method 'GET' -Headers $headers
    $repositorydetails | ConvertTo-Json
    $repositoryName=$repositorydetails.name
    }
  else
   {
   $path="null"
   $repositoryname=$pipeline.configuration.designerJson.repository.name
   }
   Write-Output "$pipelinename, $repositoryName, $path" >> C:\workspace1\new1\test.txt
   }

0
投票
az pipelines list --project $proj --query "[].{ id: id, name: name }" |
ConvertFrom-Json |
%{
  az pipelines show --project $proj --query '{ name: name, id: id, repo: repository.url, file: process.yamlFilename }' --name $_.name |
  ConvertFrom-Json
}
© www.soinside.com 2019 - 2024. All rights reserved.