Jenkins_FileCenter_Deploy

@ECHO OFF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::Init environment for FileCentre
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

IF %1]==]  GOTO Usage
IF %2]==]  GOTO Usage
IF %3]==]  GOTO Usage
IF %4]==]  GOTO Usage
IF %5]==]  GOTO Usage
IF %6]==]  GOTO Usage
IF %7]==]  GOTO Usage
IF %8]==]  GOTO Usage

SET @AppInfo=%1
SET @SourcePackageDir=%2
SET @IsBackup=%3
SET @BackupBuildNumber=%4
SET @TargetBackupDir=%5
SET @TargetDir=%6
SET @TargetServerInfo=%7
SET @TargetEnvironment=%8

::Split parameter @AppInfo to @AppName , @TargetAppName and @PackageName
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%A IN ("%@AppInfo%") DO SET @AppName=%%A&SET @TargetAppName=%%B&SET @PackageName=%%C
IF ERRORLEVEL 1 (
   ECHO ERROR: ** Split parameter AppInfo - %@AppInfo%  failed
   GOTO ExitError
)

::Split parameter @TargetServerInfo to TargetServer , @TargetAppStartNum and @TargetAppEndNum
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%A IN ("%@TargetServerInfo%") DO SET @TargetServer=%%A&SET @TargetAppStartNum=%%B&SET @TargetAppEndNum=%%C
IF ERRORLEVEL 1 (
   ECHO ERROR: ** Split parameter TargetServerInfo - %@TargetServerInfo%  failed
   GOTO ExitError
)

:: Set variables for target server dir
SET @TargetServerDir=\\%@TargetServer%\%@TargetDir%
:: Set variables for all config directory
SET @AllConifgDir=Beta Development Production Production-Dallas

:: Check if deployed package is existed or not
 IF NOT EXIST %@SourcePackageDir%\%@PackageName% (
    ECHO ERROR: ** Could not find deployment package "%@PackageName%"
    GOTO ExitError
)

:: Set variables for 7zip
IF EXIST "C:\Program Files\7-Zip\7z.exe" (
  SET @7ZEXE="C:\Program Files\7-Zip\7z.exe"
) ELSE (
  ECHO ERROR: ** Could not find 7Zip EXE
  GOTO ExitError
)


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO ::::: Deploy application - %@AppName% on target server - %@TargetServer%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

FOR /l %%i in (%@TargetAppStartNum%,1,%@TargetAppEndNum%) DO (
   IF EXIST "%@TargetServerDir%\%@TargetAppName%%%i" (
      IF %@IsBackup% EQU Y (
         ECHO INFO :## Backup target application - "%@TargetAppName%%%i" ...
         %@7ZEXE% A "%@TargetBackupDir%\%@TargetAppName%%%i\Backup\%@TargetAppName%%%i-%@VersionNumber%.%@@BackupBuildNumber%.zip" "%@TargetServerDir%\%@TargetAppName%%%i\*" -x!"Backup\*" ) )
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Backup target application - "%@TargetAppName%%%i" failed
      GOTO ExitError )
     
   IF NOT EXIST "%@TargetServerDir%\%@TargetAppName%%%i" (
      ECHO INFO : ## Create directory - "%@TargetServerDir%\%@TargetAppName%%%i" for target application ...
      MKDIR "%@TargetServerDir%\%@TargetAppName%%%i")
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Create directory - "%@TargetServerDir%\%@TargetAppName%%%i" for target application failed
      GOTO ExitError)
     
   ECHO INFO : ## Extracting "%@PackageName%" package for target directory - "%@TargetServerDir%\%@TargetAppName%%%i" ...
   %@7ZEXE% x -y %@SourcePackageDir%\%@PackageName% -o"%@TargetServerDir%\%@TargetAppName%%%i\"
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Extracting "%@PackageName%" package for target directory - "%@TargetServerDir%\%@TargetAppName%%%i" failed
      GOTO ExitError)
  
   ECHO INFO : ## Starting to update for application - %@TargetAppName%%%i" ...
   FOR %%D IN ( %@AllConifgDir% ) DO (
   IF EXIST "%@TargetServerDir%\%@TargetAppName%%%i\__appconfig\%%D" (
      IF %@TargetEnvironment% NEQ %%D (
         ECHO INFO : ## Remove unuseful configure directory  __appconfig\%%D ...
         RD /S /Q  "%@TargetServerDir%\%@TargetAppName%%%i\__appconfig\%%D"
         IF ERRORLEVEL 1 (
         ECHO ERROR: ** Remove unuseful configure directory  __appconfig\%%D  failed
         GOTO ExitError ) ) ) )
     
   IF EXIST "%@TargetServerDir%\%@TargetAppName%%%i\%@TargetAppName%%%i.exe" (
      ECHO INFO : ## Delete "%@TargetServerDir%\%@TargetAppName%%%i\%@TargetAppName%%%i.exe" ...
      DEL %@TargetServerDir%\%@TargetAppName%%%i\%@TargetAppName%%%i.exe /q )
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Delete "%@TargetServerDir%\%@TargetAppName%%%i\%@TargetAppName%%%i.exe" failed
      GOTO ExitError)
     
   IF EXIST "%@TargetServerDir%\%@TargetAppName%%%i\%@AppName%.exe.config" (
      ECHO INFO : ## Delete "%@TargetServerDir%\%@TargetAppName%%%i\%@AppName%.exe.config"
      DEL %@TargetServerDir%\%@TargetAppName%%%i\%@AppName%.exe.config /q )
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Delete "%@TargetServerDir%\%@TargetAppName%%%i\%@AppName%.exe.config" failed
      GOTO ExitError )
     
   IF EXIST "%@TargetServerDir%\%@TargetAppName%%%i\App.config" (
      ECHO INFO : ## Delete "%@TargetServerDir%\%@TargetAppName%%%i\App.config" ...
      DEL %@TargetServerDir%\%@TargetAppName%%%i\App.config /q )
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Delete "%@TargetServerDir%\%@TargetAppName%%%i\App.config" failed
      GOTO ExitError )

   ECHO INFO : ## Rename "%@AppName%.exe" for "%@TargetAppName%%%i.exe" ...
   RENAME %@TargetServerDir%\%@TargetAppName%%%i\%@AppName%.exe %@TargetAppName%%%i.exe
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Rename "%@AppName%.exe" for "%@TargetAppName%%%i.exe" failed
      GOTO ExitError )
     
   ECHO INFO : ## Move config file -"%@TargetEnvironment%\EXEConfig\%@TargetAppName%%%i.exe.config" for target application - "%@TargetAppName%%%i\%@TargetAppName%%%i.exe.config" ...
   MOVE /Y "%@TargetServerDir%\%@TargetAppName%%%i\__appconfig\%@TargetEnvironment%\EXEConfig\%@TargetAppName%%%i.exe.config" "%@TargetServerDir%\%@TargetAppName%%%i\%@TargetAppName%%%i.exe.config"
   IF ERRORLEVEL 1 (
      ECHO ERROR: ** Move config file -"%@TargetEnvironment%\EXEConfig\%@TargetAppName%%%i.exe.config" for target application - "%@TargetAppName%%%i\%@TargetAppName%%%i.exe.config" failed
      GOTO ExitError )
)

EXIT /B 0

:ExitError
EXIT /B 1

:Usage
ECHO Usage: %0 %@AppInfo% %@SourcePackageDir% %@IsBackup% %@BackupBuildNumber% %@TargetBackupDir% %@TargetServerDir% %@TargetServerInfo% %@TargetEnvironment%

 

posted @ 2012-08-06 10:13  Alex Tian  阅读(211)  评论(0编辑  收藏  举报