【问题标题】:VSTS REST API for creating TFVC Branch用于创建 TFVC 分支的 VSTS REST API
【发布时间】:2019-01-09 22:04:53
【问题描述】:

我正在尝试自动化一些与构建相关的任务,其中包括为每个版本创建新的发布分支和构建定义。我使用 VSTS TFVC 进行版本管理。当我尝试使用 TFS REST API 执行此操作时,我找不到任何用于创建分支的 API (microsoft documentation)。

我可以看到.NET API 可以执行此操作;找不到一个作为 REST API 的。

【问题讨论】:

    标签: rest azure-devops tfvc azure-devops-rest-api


    【解决方案1】:

    暂时没有这样的 REST API 来创建分支,我已经提交了 user voice here 来建议该功能,您可以去投票以实现该功能。

    作为一种解决方法,您可以尝试以下方法在代码或脚本中创建分支:


    tf branch olditem newitem [/version:versionspec] [/noget] [/lock:(none|checkin|checkout)] [/noprompt] [/silent] [/checkin] [/comment:("comment"|@commentfile)] [/author:authorname] [/login:username, [password]] [/recursive]
    

    【讨论】:

      【解决方案2】:

      正如您在“分支”页面中看到的那样,没有任何方法可以使用 Rest API 创建分支。大多数情况下,您现在只能使用版本控制 API 读取/获取信息。

      如果您不想使用 C#,可以使用 Powerhshell 自动化该过程:

      param(
      
      )
      begin
      {
       # load the required dll's
          [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
          [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")   
      }
      
      process
      {
       $server = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer("http://tfsserver:8080/tfs/DefaultCollection")
      
       $vcServer = $server.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]); 
      
       $changesetId = $vcServer.CreateBranch('$/Demo/Code/Main', '$/Demo/Code/Dev/Branch', [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest, $null, "New branch from script", $null, $null, $null)
      
       "Branch created with ChangesetID: $changesetId"
      }
      

      【讨论】:

      • 感谢脚本。是的,我知道这一点,我正在尝试使用 Python 脚本将其自动化。我想知道为什么微软不支持这个。
      猜你喜欢
      • 2021-09-06
      • 2018-08-23
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多