我正在从本地TFS实例迁移到VSTS的过程中。我有很多迁移到VSTS的构建管道(vNext构建定义),但是现在我必须全部更新它们以使用特定的代理。
UI和命令行客户端中没有可用的选项。
我是否缺少可用的选项,所以我可以一次更新它们?
答案 0 :(得分:5)
基于我对Manuel所做的迁移工作(请参阅Jesse提到的帖子),我提供了一些脚本,这些脚本可以获取TFS队列,然后将其用于更新VSTS构建定义。
这两个脚本都需要一个参数PersonalAccesToken-一个是您要定位的VSTS帐户的PAT,另一个是用于TFS环境的目标。
第一个脚本可帮助您获取包含所有TFS队列的queues.json文件。第二个脚本迭代您要定位的VSTS项目,以更新构建定义。脚本应该很不言自明。
# Get all queues and based on previous names get the id's
(Invoke-RestMethod `
-Uri "https://$account.visualstudio.com/$_/_apis/distributedtask/queues" `
-Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=3.2-preview" } `
-Method Get `
-ContentType "application/json" -Verbose).value | % { $vstsqueues[$_.name] = $_.id }
# get all the builds
$builds = (Invoke-RestMethod `
-Uri "https://$account.visualstudio.com/$_/_apis/build/definitions" `
-Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
-Method Get `
-ContentType "application/json").value
# get the full build definition
$build = Invoke-RestMethod `
-Uri $_.url `
-Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
-Method Get `
-ContentType "application/json"
# get queue
$queuename = $tfsqueues[$_.queue.id]
Write-Output " queue name: $queuename"
# update build
$build.queue = @{ id = $vstsqueues[$queuename] }
# post changes
Invoke-RestMethod `
-Uri $_.url `
-Headers @{Authorization = "Basic $auth"; Accept = "application/json; api-version=4.1-preview.6" } `
-Method Put `
-ContentType "application/json" `
-Body ($build | ConvertTo-Json -Depth 100 -Compress) | Out-Null
}
}
查看存储库https://github.com/JasperGilhuis/VSTS-RestAPI/tree/master/Builds中的Builds文件夹