migration - 我可以批量更新 VSTS 构建管道定义吗?
问题描述
我正在从本地 TFS 实例迁移到 VSTS。我有很多迁移到 VSTS 的构建管道(vNext 构建定义),但现在我必须更新它们以使用特定的代理。
UI 和命令行客户端中都没有可用的选项。
我是否错过了一个可用的选项,以便我可以一次更新它们?
解决方案
根据我对 Manuel 所做的迁移工作(参考 Jesse 提到的帖子),我提供了一些可用的脚本来获取 TFS 队列,然后使用它来更新 VSTS 构建定义。
- 读取队列FromTfs.ps1
- 修复-BuildDefinitions.ps1
这两个脚本都需要一个参数 PersonalAccesToken - 一个是您所针对的 VSTS 帐户的 PAT,另一个是针对 TFS 环境的 PAT。
第一个脚本可帮助您获取包含所有 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
}
}
查看存储库中的 Builds 文件夹https://github.com/JasperGilhuis/VSTS-RestAPI/tree/master/Builds
推荐阅读
- java - 我需要了解如何将 API 网关与身份验证微服务和其他微服务连接
- javascript - 如何提交包含相关字段列表的表单?
- javascript - 试图理解“西蒙”游戏
- node.js - Mongoose - 接收 JSON 正文时出现“ValidationError:xxx:”
- c - 动态数组和意外输出
- swift - 在自定义 Publisher 中使用 Realm 时无法消除见证错误
- opencv - OpenCV多波段混合断言错误
- html - 兄弟 div 的上边距不是从同一点开始
- c++ - 忽略输入行中的某些输入
- google-chrome - 渐进式 Web 应用程序适用于本地设置,但在暂存时,Chrome 控制台显示“Manifest: Line: 1, column: 1, Syntax error”