【问题标题】:Azure DevOps API - Create a pipeline from a YAML file located in a specific branch sourceAzure DevOps API - 从位于特定分支源中的 YAML 文件创建管道
【发布时间】:2021-06-19 03:59:13
【问题描述】:

(这是我的第一个问题,我会尽量理解)

目标:从 Powershell 脚本从 YAML 文件(位于特定分支上)创建新管道

根据文档和我自己的知识,我得到了这个 JSON 来创建自己的管道:

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

使用上面的代码,我可以创建一个管道但只能从位于主分支上的 YAML 但在我的情况下 我想从位于一个不同的分支

我想我们应该能够在 JSON 中添加一个字段来指定它,但我没有找到任何东西。

有人知道怎么做吗?

【问题讨论】:

标签: git azure-devops yaml azure-pipelines azure-devops-rest-api


【解决方案1】:

使用端点“Pipelines - Create”为存储库创建 YAML 管道时,如果默认分支上存在 YAML 文件的指定路径,则默认情况下端点将使用默认分支中的现有 YAML 文件。目前,我们在此端点上没有任何可用选项来允许指定来自其他分支的现有 YAML 文件。创建并保存新的 YAML 管道后,您需要手动切换分支和 YAML 文件。

但是,作为一种解决方法,也许您可​​以尝试使用 Azure CLI“az pipelines create”。使用此命令,您可以通过参数“--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]

【讨论】:

  • 非常感谢您的回答,我现在更了解情况了!我会重新编写我的脚本以尽可能地做到这一点:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 2023-02-05
  • 2021-04-28
  • 1970-01-01
  • 2019-05-14
  • 2021-07-05
相关资源
最近更新 更多