【问题标题】:Managing branches with Azure DevOps Classic Build Pipelines and TFVC使用 Azure DevOps Classic Build Pipelines 和 TFVC 管理分支
【发布时间】:2021-03-14 08:53:35
【问题描述】:

在使用 Azure DevOps Classic Build Pipelines 和 TFVC 时如何管理从分支构建?

我认为唯一可行的选择是使用新名称复制构建管道并更新源代码映射以指向新的 TFVC 分支。

我看到 ADO Web UI 提供了克隆单个构建定义的选项,但由于我有超过 200 多个构建管道可以在我分支时进行克隆,是否有更有效的方法来执行此操作?或者是编写自定义工具以利用 ADO REST Api 的唯一选择?

【问题讨论】:

  • 嗨@Techromancer。这张票有更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒this
  • 我希望得到一个不需要我编写自定义工具并且不需要迁移到 Git 和 YML 构建的答案(这看起来是 MS 唯一支持的选项!Tfvc 与 Git 的奇偶校验发生了什么功能?),不过你的例子真的很有帮助,非常感谢。

标签: azure-devops tfvc


【解决方案1】:

由于您需要批量克隆管道,因此使用脚本运行 Rest API 将是一种合理的方法。据我所知,除此之外没有其他简单的方法可以开箱即用。

您可以尝试以下 PowerShell 脚本示例:

$DefinitionIds = "PipelineIDs"  #InPut All Pipelineids(e.g. "324,323,xxx" )
$DefinitionId = $DefinitionIds.split(",");
$token = "PAT Token"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

foreach ($i in $DefinitionId)
{
echo $i

$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/definitions/$($i)?api-version=6.0"


$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get  -ContentType application/json

Write-Host "$($response | ConvertTo-Json -Depth 100)"


$response.repository.properties.tfvcMapping= '{"mappings":[{"serverPath":"$/TFVCBranchName","mappingType":"map","localPath":"\\"}]}' # ServerPath is the Branch name

$response.repository.name = "TFVCRepoName" #Repo Source Name

$response.name = "Pipeline $i Clone" # Cloned PipelineName 

echo $response.name

$url1= "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/definitions?api-version=6.0"


$json = @($response) | ConvertTo-Json -Depth 100

$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Post -Body $json -ContentType application/json


}

以下是脚本中使用的两个 Rest API:

Definitions - Get

Definitions - Create

结果:

克隆的管道将设置为新的 TFVC 分支和构建定义名称。

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 2020-12-12
    • 2019-10-19
    • 1970-01-01
    • 2021-12-16
    • 2022-11-25
    • 2019-02-20
    • 1970-01-01
    相关资源
    最近更新 更多