jlo
jlo

Reputation: 1120

How can I copy a Visual Studio Team Service build to a new project?

I'm moving a particular set of builds from an existing Visual Studio Team Service project to a new one. Unfortunately, I cannot locate a way to migrate the build definitions from one project to another. There doesn't appear to be an import/export function or another mechanism.

Is there a way to move these without manually recreating the builds in the new project?

Upvotes: 19

Views: 8392

Answers (6)

SCDomingos
SCDomingos

Reputation: 11

In

  1. On the Source project export (via ...) each build definition

  2. On the Destination project, in the folder view for build definitions, New->Import one and adjust: Agent Pool Repository Path (to be reviewed later, while saving the import)

  3. Export the successfully imported build definition

  4. Edit remaining extracted build definitions and replace (with values from that first successful imported build definition) the values for Agent Pool, Repository and Path
  5. Import the remaining builds Review name (remove the -import suffix) Review the Agent Pool Review the Path within the Destination project's folder view, when saving the imported build

Upvotes: 0

Codingrunr
Codingrunr

Reputation: 186

You could do something like the following:

$project1Url = "http://tfs:8080/tfs/collection/project1/_apis/build/definitions/$($buildId)?api-version=2.0"
$obj = Invoke-RestMethod -Uri $project1Url -Method Get -ContentType "application/json" -UseDefaultCredentials

$obj.project = $null

#TODO: Update all repository/source control info, too.

$json = ConvertTo-Json $obj -Depth 3

$project2Url = "http://tfs:8080/tfs/collection/project2/_apis/build/definitions/?api-version=2.0"
Invoke-RestMethod -Uri $url -Method Post -Body $json -ContentType "application/json" -UseDefaultCredentials

The gist is: Get the existing definition from the source project (projec1), clear the project ties, set the new repository information as needed, and send the new definition as a POST (CREATE) to the target project (project2).

Upvotes: 4

Dhruv Patel
Dhruv Patel

Reputation: 305

You can use the REST APIs to perform this. There is an example shown here.

It shows how to get the JSON response of a build definition and again using the same reference to make a new one in the project you desire.

Upvotes: 2

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51093

There's no way to copy or sync a vnext build definition template between team projects. The build definition template is only for the present team project. So you need to create a build definition template for each team project.

And also there have been a feature request on UserVoice, you can vote up and monitor it

VSO build vnext: share build templates between projects https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/8468566-vso-build-vnext-share-build-templates-between-pro

However, it can be achieved using the API. Here is a simple tool you can use. (Need to be in the same team project collection.)

Upvotes: 3

marv
marv

Reputation: 211

This is now available from within the VSTS Build Definitions web UI:

VSTS Export and clone.

Upvotes: 17

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29966

There is an Export/Import Build Definition extension in Visual Studio Marketplace you can use now.

Upvotes: 13

Related Questions