3

(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 ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yann.T
  • 33
  • 6
  • Does this answer your question? [Create a new pipeline from existing YML file in the repository (Azure Pipelines)](https://stackoverflow.com/questions/59067096/create-a-new-pipeline-from-existing-yml-file-in-the-repository-azure-pipelines) – TTT Mar 22 '21 at 14:51
  • Unfortunately no :/ Actually the azure devops api took the master branch as the default branch. – Yann.T Mar 22 '21 at 15:20

1 Answers1

1

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]
Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12
  • Thanks a lot for your answer, I understand better now the situation ! I gonna rework my script to do it as well as possible :) – Yann.T Mar 23 '21 at 11:14