-1

我在 Azure DevOps 中创建了一个构建管道,它连接到我在 Github 中的一个存储库。但是,我想将此构建管道连接/克隆到我的 github 中任何新创建的存储库中,其名称中带有特定前缀,例如“构建”一词。

4

2 回答 2

1

您可以导航到您的构建管道,从管道详细信息页面的右侧选择选项菜单,然后选择该Clone项目。

然后,您可以将克隆的构建管道指向您的新 Git 存储库,并将管道的名称更改为具有您希望的前缀。

于 2019-11-21T17:36:20.053 回答
0

将 AzureDevOps 中的构建管道自动连接到具有特定前缀的新创建的存储库

要自动化该过程,您需要使用定义 REST AP 获取 json 正文:

https://docs.microsoft.com/en-us/rest/api/azure/devops/build/definitions/get?view=azure-devops-rest-5.0

然后我们可以根据需要更改 json 文件,例如存储库 URL,将其更改为您在我的 github 中新创建的存储库的新路径。

最后,我们可以使用上面的 Json 文件创建定义 REST API 来创建新的管道:

https://docs.microsoft.com/en-us/rest/api/azure/devops/build/definitions/create?view=azure-devops-rest-5.0

$thisBuildDef.Name = $Clone_Name
$thisBuildDef.path = $BuildDefURL  # Relative to the Project name; like "Release/2019"
$thisBuildDef.buildNumberFormat = $BuildNumberFormat

# Update source control path to new branch
$defAsJson = $thisBuildDef | ConvertTo-Json -Depth 100
$defAsJson = $defAsJson.Replace($sourceControlMainline, $sourceControlBranch)

$Uri = "https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=2.0"

$newBuildDef = Invoke-RestMethod -Uri $Uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -Body $defAsJson -ContentType "application/json" -ErrorAction Stop

检查文档Using JSON via REST to create build definitions in VSOvsts-clone-build-with-powershell.ps1 示例

希望这可以帮助。

于 2019-11-22T09:17:25.430 回答