Search code examples
azure-devopsazure-sdk-.net

Is there a attribute or set of attributes in Azure SDK for .NET to determine if pipeline is classic or using YAML


Is there a attribute or set of attributes in Azure SDK for .NET to determine if a pipeline in Azure DevOps is using classic architecture or using YAML?


Solution

  • You can use the .NET client libraries for Azure DevOps.

    you need to install the following NuGet packages with the latest stable versions in your project:

    • Microsoft.TeamFoundationServer.Client
    • Microsoft.VisualStudio.Services.Client
    • Microsoft.VisualStudio.Services.InteractiveClient

    enter image description here

    And below is a sample of the C# code as reference.

    using Microsoft.Azure.Pipelines.WebApi;
    using Microsoft.VisualStudio.Services.Common;
    using Microsoft.VisualStudio.Services.WebApi;
    
    . . .
    
    public static void getPipeline(string orgName, string projName, int pipID, string pat)
    {
        try {
            var orgUrl = new Uri($"https://dev.azure.com/{orgName}");
            VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, pat));
            PipelinesHttpClient pipClient = connection.GetClient<PipelinesHttpClient>();
    
            var get_pipe = pipClient.GetPipelineAsync(projName, pipID).Result;
            var type = get_pipe.Configuration.Type.ToString();
            Console.Write($"The type of pipeline {pipID} is {type}.");
        }
        catch(Exception ex) { 
            Console.Write(ex.ToString());
        }
    }
    

    When the pipeline is a YAML pipeline, the returned value of type is 'yaml' (or 'Yaml'). Otherwise, it is not a YAML pipeline.

    If classic build pipeline, the type value should be 'designerJson'.

    The corresponding REST API is "Pipelines - Get".

    enter image description here