Pages

Friday, 10 August 2012

Upgraded Batch file for download project / code from Team Foundation Server (TFS) using command line/ command prompt

In my last post I shared how we can download code/project from TFS:

http://www.blogger.com/blogger.g?blogID=8188117718822686915#editor/target=post;postID=583709375510837785;onPublishedMenu=overview;onClosedMenu=overview;postNum=12;src=postname

Please find upgraded version of the same batch file with some extra features:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@echo off
:: variable declarations
::*********************************************************
set userName=
set password=
::GetLatest:Only If User Need Latest Code;
::CreateTFS:Only if User want to create new mapping with TFS and take latest code;
::NO: User Don't want to create New TFS not need latest code
set isLatestCodeRequired=CreateTFS
set workSpacename=
set tfsURL=
set tfsAddress=
::*********************************************************
::**************************************************
:: Create work space and Download code from TFS
::**************************************************
:: check for existence of [Program Files(x86)]
::if %isTFSMappingRequired% == Y (GOTO CreateNewTFSAndGetLatest)

if %isLatestCodeRequired% == GetLatest (GOTO DownloadTFSCode)
if %isLatestCodeRequired% == CreateTFS (GOTO CreateNewTFSAndGetLatest)
if %isLatestCodeRequired% == NO (GOTO NotDownloadTFSCode)
:DownloadTFSCode
set EnvpathVS2010=%VS100COMNTOOLS%
::Creating path of Visual Studio Command Prompt
set PathToAppend=\VC\vcvarsall.bat" x86
set EnvpathVS2010=%EnvpathVS2010:\Common7\Tools\=%
set RootDirectory=%windir%
set RootDirectory=%windir:\Windows=%
set FinalPath="%EnvpathVS2010%%PathToAppend%
call %FinalPath%
cd\
%RootDirectory%
::Create Directory Application_App_Checkout
md %workSpacename%
::Into Directory Application_App_Checkout
cd %workSpacename%
::tf workspace /delete %workSpacename% /noprompt
::tf workspace /new %workSpacename% /noprompt /collection:%tfsURL% /login:%userName%,%password%
tf.exe get %tfsAddress% /recursive /all /overwrite /force /login:%userName%,%password%
echo %isLatestCodeRequired%
call C:\Application_AppCheckout_SourceCode_Download\AutomatedTests\ApplicationCheckOut\Development\Application_AppCheckoutRelease.bat
GOTO End
:NotDownloadTFSCode
echo "User does not wish to download latest code from TFS."
pause
echo %isLatestCodeRequired%

GOTO End
:CreateNewTFSAndGetLatest
set EnvpathVS2010=%VS100COMNTOOLS%
::Creating path of Visual Studio Command Prompt
set PathToAppend=\VC\vcvarsall.bat" x86
set EnvpathVS2010=%EnvpathVS2010:\Common7\Tools\=%
set RootDirectory=%windir%
set RootDirectory=%windir:\Windows=%
set FinalPath="%EnvpathVS2010%%PathToAppend%
call %FinalPath%
cd\
%RootDirectory%
::Create Directory Application_App_Checkout
md %workSpacename%
::Into Directory Application_App_Checkout
cd %workSpacename%
tf workspace /delete %workSpacename% /noprompt
tf workspace /new %workSpacename% /noprompt /collection:%tfsURL% /login:%userName%,%password%
tf.exe get %tfsAddress% /recursive /login:%userName%,%password%
echo %isLatestCodeRequired%

GOTO End
End Local

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

No comments:

Post a Comment