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

查看:17
本文介绍了我可以批量更新 VSTS 构建管道定义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

第一个脚本可帮助您获得一个 queues.json 文件,该文件包含所有 TFS 队列.第二个脚本迭代您的目标 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天全站免登陆