Mik*_*ehl 2 migration azure-devops azure-pipelines
我正在从一个内部部署的TFS实例迁移到VSTS.我有很多迁移到VSTS的构建管道(vNext构建定义),但现在我必须更新它们才能使用特定的代理.
UI和命令行客户端中没有可用选项.
我错过了一个可用的选项,所以我可以立即更新它们吗?
小智 5
基于我在Manuel中所做的迁移工作(参见Jesse提到的帖子),我提供了一些可用于获取TFS队列的脚本,然后使用它来更新VSTS构建定义.
这两个脚本都需要参数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
}
}
Run Code Online (Sandbox Code Playgroud)
看看存储库中的Builds文件夹https://github.com/JasperGilhuis/VSTS-RestAPI/tree/master/Builds
| 归档时间: |
|
| 查看次数: |
281 次 |
| 最近记录: |