我可以批量更新VSTS构建管道定义吗?

编程入门 行业动态 更新时间:2024-10-24 22:17:53
本文介绍了我可以批量更新VSTS构建管道定义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从本地TFS实例迁移到VSTS的过程中.我有很多构建管道(vNext构建定义)已迁移到VSTS,但是现在我必须更新它们全部以使用特定的代理.

I'm in the process of migrating from an on-premise TFS instance to VSTS. I have a lot of build pipelines (vNext build definitions) that were migrated to VSTS, but now I have to update them all to use a specific Agent.

用户界面和命令行客户端中没有可用的选项.

There is no option available in the UI nor in the commandline client.

我是否缺少可用的选项,所以我可以一次全部更新它们?

Am I missing an option available to me so I can update them all at once?

推荐答案

基于我对Manuel所做的迁移工作(请参阅Jesse提到的帖子),我提供了一些脚本来获取TFS队列,然后使用它们用于更新VSTS构建定义.

Based on the migration work I did with Manuel (referred to the post Jesse mentions), I have made some scripts available that get the TFS queues and then use that for updating the VSTS build definitions.

  • Read-QueuesFromTfs.ps1
  • Repair-BuildDefinitions.ps1

这两个脚本都需要一个参数PersonalAccesToken-一个是您要定位的VSTS帐户的PAT,另一个是用于TFS环境的目标.

Both scripts require a parameters PersonalAccesToken - One is a PAT for the VSTS account you are targeting and one for targeting the TFS environment.

第一个脚本可帮助您获取包含所有TFS队列的queues.json文件.第二个脚本迭代您要定位的VSTS项目,以更新构建定义.脚本应该很不言自明.

First script helps you get a queues.json file that holds all TFS Queues. Second script iterates the VSTS projects you are targeting for updating the build definitions. Scripts should be quite self-explanatory.

# Get all queues and based on previous names get the id's (Invoke-RestMethod ` -Uri "$account.visualstudio/$_/_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 "$account.visualstudio/$_/_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/JasperGilhuis/VSTS-RestAPI/blob/master/README.md#update-vsts-build-definitions-based-on-tfs-queues

查看存储库中的Builds文件夹 github/JasperGilhuis/VSTS-RestAPI/tree/master/Builds

Look that the Builds folder in the repository github/JasperGilhuis/VSTS-RestAPI/tree/master/Builds

更多推荐

我可以批量更新VSTS构建管道定义吗?

本文发布于:2023-07-07 22:18:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批量   管道   定义   VSTS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!