How can I query for the yaml filepath for all pipelines in our dev azure project?

Viewed 60

I want to list all the yaml files in use in any devops pipeline. I can do:

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

and get the right result:

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

but if I list instead of show -- I want all of them, not one at a time -- list doesn't return the same level of detail. It doesn't give me repository and process data, so I can't list the repo name or the yaml path.

How can I get repo name and yaml path for all my pipelines?

1 Answers

To get repo name and yaml path for all your pipeline, you could use REST API to list all your pipeline, and get each pipeline details, then, according to result to get repository. Finally, generate a file with pipeline name, repository name and path. Here is the PowerShell script for the whole process. Please replace with your own PAT, organization name, project name and the path you want to store the file. Here set the path=null for classic pipeline.

$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
   }
Related