2

We have Team Foundation Server 2017 setup on our internal server which we build our .NET code in our sandbox environment, but would like to be able to push out new build definitions or updates remotely (to our client - production server) either manually or in an automated manner?

Chaka
  • 1,709
  • 11
  • 33
  • 58

1 Answers1

2

Yes, you can export and import the build definitions in TFS 2017.

In you case, if you have the permission to access and create build definitions from the remote server, then you can export/import the build defintions directly. Reference below screenshot.

Besides, you can also use the extension Export/Import Build Definition.

To update the build definition, you can use the REST API (Update a build definition) with the PUT method:

e.g.:

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

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

UPDATE:

You can reference below sample to update the build definiton:

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)} 

enter image description here

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • Hi Andy, how do you execute the REST API commands, is there a toolset within TFS or will it be a custom script running outside of TFS? – Chaka Feb 14 '18 at 17:18
  • Also, how did you get the import button to display on the right of "+ New"? There is a note on the plugin that it doesn't display on-promise but on the right click menu. – Chaka Feb 14 '18 at 19:06
  • @Chaka I captured the screenshot from VSTS, no "Import" option in TFS 2017. So, you can use the export/import extension. For exexuting the REST API, you can use the tools such as [Postman](https://www.getpostman.com/), you can also use custom script e.g. Poweshell. – Andy Li-MSFT Feb 15 '18 at 10:28
  • Thank you Andy, it was helpful! – Chaka Feb 21 '18 at 00:09