![](/img/trans.png)
[英]Azure DevOps API - Push a YAML file from a powershell script
[英]Azure DevOps API - Create a pipeline from a YAML file located in a specific branch source
(这是我的第一个问题,我会尽量理解)
目标:从 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"
使用上面的代码,我可以创建一个管道,但只能从位于 master 分支上的 YAML 中创建,但在我的情况下,我想从位于不同分支中的 YAML 文件创建此管道。
我想我们应该能够在 JSON 中添加一个字段来指定它,但我没有找到任何东西。
有谁知道该怎么做?
使用端点“ 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.