我可以批量更新VSTS构建管道定义吗? [英] Can I mass-update VSTS build pipeline definitions?

查看:65
本文介绍了我可以批量更新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 "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/blob/master/README.md#update-vsts-build-definitions-based-on-tfs-queues

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

Look that the Builds folder in the repository https://github.com/JasperGilhuis/VSTS-RestAPI/tree/master/Builds

这篇关于我可以批量更新VSTS构建管道定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆