Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps API - Create a pipeline from a YAML file located in a specific branch source

(this is my first question, I gonna try to be understandable)

Objective : From a Powershell script create a new Pipeline from a YAML file (located on a specific branch)

According to the documentation and my own knowledge I got this JSON to create my own pipeline :

$pipelineJSON = @{
    configuration = @{
        variables = @{
            example = @{
                value =  "to be defined"
            }
        }
        path = "azure-pipelines.yml"
        repository = @{
            id = "myRepoId"
            name = "myRepoName"
            type = "azureReposGit"
        }
        type = "yaml"
    }
    name = "pipeline-test"
    folder= "\\"
} | ConvertTo-Json
$request = 'https://dev.azure.com/' + $organization + '/' + $projectName + '/_apis/pipelines?api-version=6.0-preview.1'
$responseCreatePipeline = Invoke-RestMethod $request -Method 'POST' -Headers $headers -Body $pipelineJSON -ContentType "application/json"

With this code above I can create a pipeline but only from a YAML which is located on the master branch but in my case I want to create this pipeline from a YAML file located in a different branch.

I guess we should be able to add a field in the JSON to specify it but I did not find anything.

Does anyone know how to do it ?

like image 284
Yann.T Avatar asked Dec 19 '25 09:12

Yann.T


1 Answers

When using the endpoint "Pipelines - Create" to create a YAML pipeline for a repository, if the specified path of the YAML file is existing on the default branch, by default the endpoint will use existing YAML file from the default branch. And currently we have not any available option on this endpoint to allow specifying the existing YAML files from other branches. You need to manually switch the branch and YAML file after creating and saving the new YAML pipeline.

However, as a workaround, maybe you can try the Azure CLI "az pipelines create". With this command, you can specify the branch via the parameter '--branch'.

az pipelines create --name
                    [--branch]
                    [--description]
                    [--detect {false, true}]
                    [--folder-path]
                    [--org]
                    [--project]
                    [--queue-id]
                    [--repository]
                    [--repository-type {github, tfsgit}]
                    [--service-connection]
                    [--skip-first-run {false, true}]
                    [--subscription]
                    [--yaml-path]
like image 90
Bright Ran-MSFT Avatar answered Dec 21 '25 22:12

Bright Ran-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!