Querying Azure DevOps Pipelines YAML Files

Scenario Link to heading

Your project has tens or hundreds of Azure DevOps Pipelines, and you need to determine if a particular YAML definition is used for any of the pipelines.

The Azure DevOps user interface provides this information, but it requires going pipeline by pipeline since the current experience doesn’t shows it in the pipelines list.

Querying pipeline details with the Azure CLI Link to heading

The Azure CLI allows querying pipelines, for example, in PowerShell,

az pipelines show --id 321

Returns a JSON with the details for the pipeline with Id 321

{
  "__comment": "Many properties omitted for brevity",
  "authoredBy": {
    "descriptor": "aad.redacted",
    "directoryAlias": null,
    "displayName": "Miles Dyson",
    "id": "redacted-guid",
    "imageUrl": "https://dev.azure.com/cyberdyne/_apis/GraphProfile/MemberAvatars/aad.redacted",
    "uniqueName": "mdyson@cyberdyne.com",
    "url": "https://redactedurl"
  },
  "createdDate": "1997-08-04T16:41:48.533000+00:00",
  "name": "Skynet Infra",
  "options": null,
  "path": "\\Infra\\CD\\Skynet",
  "process": {
    "type": 2,
    "yamlFilename": "pipelines/Cyberdyne-Infra/Skynet.yml"
  },
  "processParameters": null,
  "project": {
    "id": "redacted-guid",
    "lastUpdateTime": "1997-08-04T20:43:19.643Z",
    "name": "Skynet",
    "revision": 78,
    "state": "wellFormed",
    "url": "https://dev.azure.com/cyberdyne/_apis/projects/redactedguid",
    "visibility": "private"
  },
}

Since we are only interested in the yamlFilename, the –query parameter allows filtering, for example

az pipelines show --id 321 --query process.yamlFilename

Returns the YAML file for the pipeline with Id 321

"pipelines/Cyberdyne-Infra/Skynet.yml"

Looping over all pipelines Link to heading

Now that we know how to get the information, we need it for every pipeline, so first, get a list of all pipeline Ids,

$pipelines = az pipelines list --query [].id | ConvertFrom-Json

Then iterate over the list, to get the details for each of the pipelines, and save it to a file

ForEach ($pipeline in $pipelines) {az pipelines show --id $pipeline --query [id,name,process.yamlFilename]} | Out-File c:\pipelines.txt

Enjoy! Link to heading

Open the resulting text file in your preferred text editor, and easily find the pipelines using the YAML file of interest