Search code examples
tfsteamcitytfsbuildoctopus-deploy

Copy source files to other TFS


We have a TeamCity/Octopus setup that runs great for several projects.

A new client wants access to the source code during development. Is it possible to copy code from our TFS to an other TFS using TeamCity? It does not need to be real-time. Daily copies are OK.

Not sure if we should use TeamCity for this or if there are possibilities within TFS itself.


Solution

  • You could setup a daily build schedule and use the TFS command line utilities to transfer the files to another server. You'll probably get all kinds of sync issues along the way, unless you always take your own solution as the current situation.

    Look at tf.exe, especially the workspace, workfold commands and add, delete, and optionally destroy. Complete the job with a tf checkin.

    Process as follows:

    • Create a workspace on your source TFS server (or use the built-in workspace features in team city): tf workspace /new
    • Map the folders you want to share: tf workfold /map
    • Get the files to the machine that's doing the transfer: tf get /recursive
    • Create a workspace on your target TFS server: tf workspace /new
    • Map the folders you want to share to tf workfold /map to a new folder that's not mapped to the source TFS server.
    • WS2 delete the files in the target folder: tf delete * /recursive
    • WS2 Check in to make sure you won't get any conflict remotely: tf checkin /recursive
    • WS1 -> WS2 Copy the files from the first workspace to the second: xcopy
    • WS2 Add all files: tf add * /recursive
    • WS2 Checkin all files tf checkin * /recursive
    • WS2 & WS2 Delete the workspace: tf workspace /delete
    • (Optional) Delete the files in the folders of the deleted workspaces on disk.

    PS: if you move to git, this all becomes a lot easier, since the distributed nature of git is kind of meant for scenarios like these.