Friday, August 20, 2010

Command line : Combine old style deployment with TFS 2010

Here is an old style batch command line (remember thoses days with MS-DOS 6).
We can still combine a batch with the brand TFS2010 and Silverlight:

Note: Introduced in SQL 2005, you could use the command sqlcmd insead of osql used below (osql is older).

@ECHO OFF
CLS

rem Check if the parameter %1 allows the access to the proper folder
DIR \\myTFSBuildServer\TFSDropBuild\GC-in\%1\_PublishedWebsites\myProject.Server.Web\*.*
CLS
IF %ERRORLEVEL% == 1 GOTO GatedCheckInVersionNotSpecified


rem -------------------------------------------------------
rem         RUNS ALL SILVERLIGHT UNIT TESTS
rem -------------------------------------------------------
-- ECHO Running the Silverlight Unit Tests on your machine before the deployment
CD ..\Tests\UnitTests


      -- ECHO SILVERLIGHT UNIT TEST NUMBER 1
       CD ..\..\..\Projects\Tests\UnitTests\myProject.Client.Tests
       C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild /t:test
       CD ..\..\Deployment


rem -------------------------------------------------------
rem         CHECK IF ALL SILVERLIGHT UNIT TESTS PASSED
rem -------------------------------------------------------
CHOICE /C:YN Did all the Silverlight UnitTests passed
IF ERRORLEVEL==2 GOTO SilverlightUTfailed rem n (no)
IF ERRORLEVEL==1 GOTO SilverlightUTpassed rem y (yes)


:SilverlightUTpassed rem We can deploy
CLS


ECHO -----------------------------------------------------------
ECHO         START : DEPLOYMENT of the Database and the C# code
ECHO -----------------------------------------------------------
ECHO 1. Drops ALL TABLES of myProject for the SQL instance of the TFS integration serveur
rem On d├ętruit toutes les tables de myProject sur l'instance SQL pour le serveur d'int├ęgration TFS
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -i ..\SQL\Drop_ALL_Tables_of_myProject.sql
CLS
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -i ..\SQL\Drop_ALL_Tables_of_myProject.sql
PAUSE

ECHO 2. CREATION OF THE EMPTY STRUCTURE
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -i ..\..\Projects\Sql\myEntityFrameworkThing.edmx.sql
rem -Q "ALTER DATABASE myProject SET ANSI_NULL_DEFAULT ON"

CLS
ECHO DONE : CREATION OF THE EMPTY STRUCTURE
PAUSE

ECHO 3. CREATION OF THE DATABASE STRUCTURE AND THE DATA
rem ~ ~ ~ ~ ~ ~ ~ ~  W A R N I N G   A T T E N T I O N  ~ ~ ~ ~ ~ ~ ~ ~
rem ~ in order not to have the accent's bug, you have to "save as" the script below in Notepad
rem ~ and change the encoding to "unicode"
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -Q "USE [myProject]"
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -i ..\SQL\ProductManager.Populate.Parcours.sql -o LogPopulate.txt
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -i ..\SQL\Insert_Blocs_Labels.sql -o LogPopulateBlocsLabels.txt

rem 4. (Hack - Waiting for myProject Product Designer) Temporarily remove the Name of ALL SCREENS so that they becomes a template
rem because a template has no name
osql -U myUserLogin -P myPassword -S MY_SQL_SERVER\MY_SQL_INSTANCE -Q "UPDATE Screens SET Name=NULL"

rem 5. If required, call a SCRIPT to ATTACH extra BEHAVIORS on the screen

ECHO 6. DEPLOY the code and the binaries, and create a log file containing the name of the deployed version
CLS
ECHO BACKUP of the previous version
set T=%time:~0,5%
SET backupDir=\\myTFSBuildServer\myFolder\Backups\%1.%T::=-%
ECHO The backup folder is "%backupDir%".
MD %backupDir%

PAUSE
XCOPY  \\myTFSBuildServer\myFolder\Web\*.* %backupDir% /E
PAUSE

ECHO 6. DEPLOY the code and the binaries, and create a log file containing the name of the deployed version
ECHO    (except the list of files in FilesToIgnore.txt such as web.Config)
XCOPY  \\myTFSBuildServer\TFSDropBuild\GC-in\%1\_PublishedWebsites\myProject.Server.Web\*.* \\myTFSBuildServer\myFolder\Web /E /W /Y /EXCLUDE:FilesToIgnore.txt
rem Gets the Zip file so that it can be extracted below
COPY  \\myTFSBuildServer\TFSDropBuild\GC-in\%1\_PublishedWebsites\myProject.Server.Web\ClientBin\myProject.xap myProject_Log.zip

rem COPY  the TRACE file and unzip the ServiceReferences.ClientConfig file from myProject.xap
COPY  \\myTFSBuildServer\TFSDropBuild\GC-in\%1\_PublishedWebsites\myProject.Server.Services.WebProbe\Trace\WebProbe.aspx \\myTFSBuildServer\myFolder\Web\Trace\
PKUNZIP myProject_Log.zip ServiceReferences.ClientConfig
rem Due to the fact that PkZip is old, we have to rename the extracted file
REN SERVICER.CLI ServiceReferences.ClientConfig
COPY  ServiceReferences.ClientConfig \\myTFSBuildServer\myFolder\Web\Trace

ECHO  This file is auto-generated by the deployed gated checkin.> DeployedVersion_%1.log
COPY  DeployedVersion_%1.log \\myTFSBuildServer\myFolder\Web\Trace
rem Clean up the mess
DEL myProject_Log.zip
DEL ServiceReferences.ClientConfig

PAUSE

rem END of the deployment, we can quit
ECHO -----------------------------------------------------------
ECHO         END : DEPLOYMENT of the Database and the C# code
ECHO READY to use
ECHO http://myServer/myFolder/Web/StaticDemo_Accueil.aspx
ECHO -----------------------------------------------------------
GOTO END


:SilverlightUTfailed  rem AN ERROR occured and at least one Silverlight Unit Test FAILED
CLS
ECHO -----------------------------------------------------------
ECHO Silverlight Unit Test FAILED :
ECHO You are NOT allowed to deploy on the myFolder server
ECHO Please correct the error, check-in and try again.
ECHO -----------------------------------------------------------
GOTO END

:GatedCheckInVersionNotSpecified
CLS
ECHO -----------------------------------------------------------
ECHO Please specify the name of the gated check-in to deploy
ECHO for example :
ECHO Only_for_the_CSharpTeam_DeployInto_myFolder.bat GC-in_20000429.12
ECHO OR the folder
ECHO \\myTFSBuildServer\TFSDropBuild\GC-in\%1\_PublishedWebsites\myProject.Server.Web\
ECHO does not exists
ECHO -----------------------------------------------------------
GOTO END

:END

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.