1
votes

I'm looking for a way to list all YAML Pipelines "definition" that trigger deployments using the deployment job feature (released in GA in 2020).

In previous Classic Release pipeline, it was easy, you just had to list all existing release definitions pipelines using the release REST API endpoint:

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0

I didn't find anything similar with YAML Pipelines.

I tried using the pipelines endpoint (released in REST API version 6.0) to get pipeline information:

GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}?api-version=6.0-preview.1

Returning this JSON (redacted):

    {
        "_links": {
            "self": {
                "href": "https://dev.azure.com/myorganization/19d42339-19ab-0000-aa1c-3f8e53300000/_apis/pipelines/1813?revision=2"
            },
            "web": {
                "href": "https://dev.azure.com/myorganization/19d42339-19ab-0000-aa1c-3f8e53300000/_build/definition?definitionId=1813"
            }
        },
        "configuration": {
            "path": "azure-pipelines/CI.yml",
            "repository": {
                "id": "a5e1ea98-1181-40a0-932f-6fcbdb92b1a0",
                "type": "azureReposGit"
            },
            "type": "yaml"
        },
        "url": "https://dev.azure.com/myorganization/19d42339-19ab-0000-aa1c-3f8e53300000/_apis/pipelines/1813?revision=2",
        "id": 1813,
        "revision": 2,
        "name": "My YAML Pipeline definition",
        "folder": "\\"
    }

You get the repository and YAML file used to create this pipeline, but no information about the content. There is no way to know this pipeline is used for deployments.

Using Azure DevOps REST API, is there a way to retrieve more information about a YAML pipeline to be able to know if it will be involved in deployments ?

PS: Downloading YAML files and parsing them to get deployment job references is NOT an option.

2
Related question about missing features in YAML Pipelines used for deployment : stackoverflow.com/questions/66108530/…Cédric V
Are the following replies helpful?Cece Dong - MSFT

2 Answers

1
votes

Unfortunately, no, you can't use any of the available APIs to retrieve YAML pipelines associated with releases.

The best I can offer for advice in that regard is to do one of two things to be able to easily detect if a pipeline both builds & deploys, or just builds:

  1. Update the naming conventions of your YAML pipelines to include a suffix that indicates what the purpose of the pipeline is. For Example: My Pipeline - Release & My Pipeline - Build
  2. Organize your folders to include a Build and Release folder within your pipeline hierarchy.

If you use either of those options, you'll be able to easily detect if a pipeline is deploying within a script.

0
votes

How to list YAML pipelines with deployment jobs using Azure DevOps REST API?

Indeed, there is no such out of box way to list YAML pipelines with deployment jobs using Azure DevOps REST API.

But we could use the REST API Yaml - Get:

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}/yaml?api-version=6.1-preview.1

One thing to note is that response body is not a standard YAML format, we can simply transform it:

$outfile = "D:\YAMLTempFolder\test.yaml"

$connectionToken="Your PAT Here"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::  

ASCII.GetBytes(":$($connectionToken)"))

$YAMLURL = "GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}/yaml?api-version=6.1-preview.1"   

$YAMLInfo = Invoke-RestMethod -Uri $YAMLURL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get 

$yaml = $YAMLInfo.yaml

echo $yaml.Replace("...","") > $outfile

The test result of my YAML file is:

enter image description here

Now, we only need to determine whether the file contains keywords -deployment.