gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:10:53 26 4
gpt4 key购买 nike

我想列出任何 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 路径?

最佳答案

要获取所有管道的存储库名称和 yaml 路径,您可以使用 REST API list all your pipeline ,和get each pipeline details ,则根据结果为get repository 。最后,生成一个包含管道名称、存储库名称和路径的文件。这是整个过程的 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
}

关于azure - 如何查询 dev azure 项目中所有管道的 yaml 文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73402074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com