Jenkins_MSDeploySample

@ECHO OFF


ECHO ***************************************************************************************************
ECHO ** Deploy Command For  SoapDataManager.Performance                                     
ECHO ***************************************************************************************************

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::Init environment and check before deployment
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

IF %1]==] GOTO Usage
IF %2]==] GOTO Usage
IF %3]==] GOTO Usage
IF %4]==] GOTO Usage

SET @AppName=SoapDataManager.Performance
SET @VersionNumber=%1
SET @PackageName=%@AppName%-%@VersionNumber%.Latest.zip
SET @BuildNumber=%2
SET @IsBackup=%3
SET @TargetEnvironment=%4
SET @TargetServer=SZPC668G
SET @SourcePackageRoot=\\10.86.17.1\DeployPackages\GPP\%@AppName%


:: Set variables for beta environment
IF %@TargetEnvironment% EQU Beta (
   SET @TargetRoot=\\%@TargetServer%\D$\WWWRoot\%@AppName%
   SET @TargetBackupRoot=\\%@TargetServer%\D$\Processes\Performance
)

:: Set variables for production environment
IF %@TargetEnvironment% EQU Production (
   SET @TargetRoot=\\%@TargetServer%\D$\WWWRoot\%@AppName%
   SET @TargetBackupRoot=\\%@TargetServer%\D$\Processes\Performance
)

:: Check if deployed package is existed or not
IF NOT EXIST %@SourcePackageRoot%/%@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
)

:: Set msdeploy variables
IF EXIST "C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" (
  SET MSDEPLOY_EXE=C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe
) ELSE (
  ECHO Could not find Microsoft Web Deploy V2 msdeploy.exe
  GOTO ErrorExit
)

ECHO AppName ------------- %@AppName%
ECHO PackageName --------- %@PackageName%
ECHO IsBackup ------------ %@IsBackup%
ECHO TargetEnvironment --- %@TargetEnvironment%
ECHO SourcePackageRoot --- %@SourcePackageRoot%
ECHO TargetRoot ---------- %@TargetRoot%
ECHO TargetServer -------- %@TargetServer%
ECHO TargetBackupRoot ---- %@TargetBackupRoot%

 

ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO ::::Step 1 -deploy Applications Part
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

IF EXIST "%@TargetRoot%" (
   IF %@IsBackup% EQU Y (
      ECHO INFO :## Backup target application - "%@AppName%" ...
      %@7ZEXE% A "%@TargetBackupRoot%\%@AppName%\Backup\%@AppName%-%@VersionNumber%.%@BuildNumber%.zip" "%@TargetRoot%\*" -x!"Backup\*" ) )
IF ERRORLEVEL 1 (
   ECHO ERROR: ** Backup target application - "%@AppName%" failed
   GOTO ExitError )
     
ECHO INFO : ## Deploying "%@AppName%" by msdeploy ...

"%MSDEPLOY_EXE%" ^
    -verb:sync ^
    -source:package="%@SourcePackageRoot%/%@PackageName%" ^
    -dest:contentPath=%@TargetRoot%,computerName=%@TargetServer% ^
   
IF ERRORLEVEL 1 (
   ECHO ERROR: ** Deploying "%@TargetAppName%" by msdeploy failed
   GOTO ExitError)


ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO ::::Step 2 -Deployment finish
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

ECHO INFO : ## Deploy "%@AppName%" successfully
EXIT /B 0


:ExitError
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO ::::Step 2 -Deployment finish
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

ECHO Error : ** Deploy "%@AppName%" failed
EXIT /B 1

:Usage
ECHO Usage: %0 [Team Name]
ECHO Example: %0 GPP

 

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