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,

1az pipelines show --id 321

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

 1{
 2  "__comment": "Many properties omitted for brevity",
 3  "authoredBy": {
 4    "descriptor": "aad.redacted",
 5    "directoryAlias": null,
 6    "displayName": "Miles Dyson",
 7    "id": "redacted-guid",
 8    "imageUrl": "https://dev.azure.com/cyberdyne/_apis/GraphProfile/MemberAvatars/aad.redacted",
 9    "uniqueName": "mdyson@cyberdyne.com",
10    "url": "https://redactedurl"
11  },
12  "createdDate": "1997-08-04T16:41:48.533000+00:00",
13  "name": "Skynet Infra",
14  "options": null,
15  "path": "\\Infra\\CD\\Skynet",
16  "process": {
17    "type": 2,
18    "yamlFilename": "pipelines/Cyberdyne-Infra/Skynet.yml"
19  },
20  "processParameters": null,
21  "project": {
22    "id": "redacted-guid",
23    "lastUpdateTime": "1997-08-04T20:43:19.643Z",
24    "name": "Skynet",
25    "revision": 78,
26    "state": "wellFormed",
27    "url": "https://dev.azure.com/cyberdyne/_apis/projects/redactedguid",
28    "visibility": "private"
29  },
30}

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

1az 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,

1$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

1ForEach ($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