azure-devops - 使用 Azure DevOps 经典构建管道和 TFVC 管理分支

标签 azure-devops tfvc

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

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

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

最佳答案

由于需要批量克隆流水线,使用脚本运行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 分支和构建定义名称。

enter image description here

关于azure-devops - 使用 Azure DevOps 经典构建管道和 TFVC 管理分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65107374/

相关文章:

tfs - 是否应该为变更集迁移用户名和时间戳?

azure-devops - 有没有办法识别在 Azure Devops CI 构建中 checkin 的 TFS 分支?

未检测到 TFS 合并更改

azure-devops - AzureKeyVault@2 任务并通过变量检索 key 保管库值检索?

azure - 在 HelmDeploy 的任务之间共享管道变量

django - 复制失败: stat/var/lib/docker/tmp/docker-builder<num>/server/requirements. txt:没有这样的文件或目录

tfs - 无法使用 Visual Studio 代码连接到 tfvc

reactjs - 使用 Azure DevOps 将 React 应用程序部署到 Azure Web App 时发布失败

Azure DevOps Build Pipeline 适用于具有多种项目类型的解决方案

java - 除了 TFVC 之外,还可以使用哪些源代码控制从 TFS 获取代码?