TFS 2017 是否能够将构建定义导出和导入远程服务器?

Does TFS 2017 have the ability to export and import build definitions into remote server?

我们在内部服务器上安装了 Team Foundation Server 2017,我们在沙盒环境中构建 .NET 代码,但希望能够远程推出新的构建定义或更新(到我们的客户端 - 生产服务器) 手动还是自动方式?

是的,您可以在 TFS 2017 中导出和导入构建定义。

在您的情况下,如果您有权从远程服务器访问和创建构建定义,那么您可以 export/import 直接构建定义。参考下面的截图。

此外,您还可以使用扩展名Export/Import Build Definition

要更新构建定义,您可以使用 REST API (Update a build definition) 和 PUT 方法:

例如:

PUT http://server:8080/tfs/DefaultCollection/Project/_apis/build/definitions/29?api-version=2.0

Content-Type: application/json
{json body here}

更新:

您可以参考以下示例来更新构建定义:

Param( 

   [string]$baseurl = "http://server:8080/tfs/Collection",   

   [string]$projectName = "ProjectName",

   [string]$builddefinitionID = "29",

   [string]$keepForever = "true", 

   [string]$user = "username", 

   [string]$token = "password" 

) 

# Base64-encodes the Personal Access Token (PAT) appropriately 

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token))) 


function CreateJsonBody 

{ 

    $value = @" 

{ 

  body here

}  


"@ 



 return $value 

} 


$json = CreateJsonBody 


$uri = "$baseurl/$($projectName)/_apis/build/definitions/$($builddefinitionID)?api-version=2.0" 

$result = Invoke-RestMethod -Uri $uri -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}