【问题标题】:Can I mass-update VSTS build pipeline definitions?我可以批量更新 VSTS 构建管道定义吗?
【发布时间】:2018-08-16 22:32:58
【问题描述】:

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

UI 和命令行客户端中都没有可用的选项。

我是否缺少一个可用的选项,以便我可以一次更新它们?

【问题讨论】:

  • medium.com/@MRiezebosch/… 我已经 ping Manuel 让脚本上线。
  • 不确定为什么会被搁置。除非您知道 REST API 的可用性,否则用户无法找到简单的方法来修复 CI/CD 管道。使这是一个非常有效的问题。我觉得这个问题被不了解 VSTS 的人解决了。它也不是在没有进一步解释的情况下关闭的事实/不符合新的行为准则。 @Mike-diehl 他的名字只有 6 分,有点屈膝会很好。
  • 感谢版主做了正确的事。欢迎@Mike-Diehl。不要让这种经历吓跑您远离 Stack Overflow,有很多人想要提供帮助。只要确保您解释了您已经尝试过的内容以及您已经搜索过的文档。在这种情况下,解决方案很难找到的。

标签: migration azure-devops azure-pipelines


【解决方案1】:

根据我对 Manuel 所做的迁移工作(参考 Jesse 提到的帖子),我已经制作了一些可用的脚本来获取 TFS 队列,然后使用它来更新 VSTS 构建定义。

  • Read-QueuesFromTfs.ps1
  • 修复-BuildDefinitions.ps1

这两个脚本都需要一个参数 PersonalAccesToken - 一个是针对您所定位的 VSTS 帐户的 PAT,另一个是针对 TFS 环境的参数。

第一个脚本可帮助您获取包含所有 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
    }
}

在此文件中描述。 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

【讨论】:

  • 感谢版主做了正确的事。欢迎@jasper。不要让这种经历吓跑您远离 Stack Overflow,有很多人想要提供帮助。当您回答时,请确保在链接到外部资源时包含相关的 sn-ps。尤其是“年轻”用户,当链接到内容的比例不好时,会自动被标记。
猜你喜欢
  • 1970-01-01
  • 2018-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 2018-12-04
  • 1970-01-01
相关资源
最近更新 更多