in Continuous Delivery

Scripting TFS Command line for get latest version, check-out, check-in, new branch

Getting latest version of you code from TFS is not so easy, especially if you compare with Git. In some cases you need to be able to perform get latest command, check-ins, check-outs from a custom script and not from Jenkins plugins. Finding the right sequence of TF commands and the right combination of parameters can be very hard.

Note: For TFS Online (http://*****.visualstudio.com) you need to use Team Explorer Everywhere (TEE-CLC-12.0.2.zip) because the classic tf.exe does not support passing credentials via command line.

For on-premise TFS instance, WindowsLiveId must have the format of domain\username.

Get latest version from TFS Online or On-Premise

tf workspace
-new CodeWorkspace;WindowsLiveId
-noprompt
-server:https://***.visualstudio.com/defaultcollection
-login:WindowsLiveId,Password

tf workfold
-map $/TFS-PATH-TO-PROJECT .                  <— you need to use that dot (.)
-workspace:CodeWorkspace
-server:https://***.visualstudio.com/defaultcollection
-login:WindowsLiveId,Password

tf get
/force
/all
-recursive
-noprompt
-login:WindowsLiveId,Password

tf workfold
-unmap .                                                              <— you need to use that dot (.)
-workspace:CodeWorkspace
-login:WindowsLiveId,Password

tf workspace
/delete CodeWorkspace
/noprompt
/server:https://***.visualstudio.com/defaultcollection
/login:WindowsLiveId,Password

Check-out

tf checkout $/TFS-PATH
/login:WindowsLiveId,Password

Check-in

tf checkin $/TFS-PATH
/noprompt
/force
/comment:’***FROM_CI***’
/login:WindowsLiveId,Password

Create new branch

tf branch $/existing-branch $/new-branch
/noget
/checkin
/noprompt
/comment:’***FROM_CI***’
/login:WindowsLiveId,Password