Deploy on remote machine during builds

Clearly Lab Management is really good to manage virtual environments and give a lot of flexibility on how to deploy your application on virtual machines, but if you do not have Lab Management you can still use the same technique to deploy application in remote computer during a build with the use of a simple scripts. The key is the ability to execute code on a remote computer with beyondexec or similar tool. Suppose you need to deploy an application called demo, you have a Tfs build called Demo, and you want to be able to deploy a specific build on a remote server, the solution could be this simple script

@echo off

set RemotePath= \\drops\demo%1_PublishedWebsites\Demo_Package*. set LocalPath=c:\setup\demo*

if exist %LocalPath% ( rmdir /s /q %LocalPath% ) mkdir %LocalPath%

if not exist %RemotePath% ( echo remote path %RemotePath% doesn’t exist goto Error )
xcopy /c %RemotePath% %LocalPath%. %LocalPath%\Demo.deploy.cmd /Y

echo Demo Copied to LocalPath %LocalPath% exit /b 0

:Error echo Unable to Copy Demo Scripts exit /b 1

The script is really simple, it simply compose the drop folder \\drops\demo with the single argument of the batch to find the path where the build had dropped the packages, then it creates a local directory where to copy all deploy plackage and run it.

Now you can store this script in source control, and use it with a tfs build, to deploy on a remote server, you can for example run from a command prompt:

  • beyondexecv2 \ -p “pa$$word -c Deploy\DeployWeb.bat demo_20100607.3* *

This will copy the script on the server, and launch the script with the argument demo_20100607.3 (the build number), here is the result.

BeyondExec V2.05 – Spawn Remote Processes on Windows NT/2000/XP WorkStations. Copyright(C) 2002-2003 [email protected] [] Establishing Connection… [] BeyondExec service already installed on remote machine. [] Copying Deploy\DeployWeb.bat to \\ADMIN$\temp\DeployWeb.bat [] Command Successfully Issued to on Pipe 1. [win-y4onzs094up] Process started, ProcessID = 9780, ThreadID = 9788 \\drops\demo\demo_20100607.3_PublishedWebsites\Demo_Package\Demo.deploy-readme.txt \\drops\demo\demo_20100607.3_PublishedWebsites\Demo_Package\Demo.deploy.cmd \\drops\demo\demo_20100607.3_PublishedWebsites\Demo_Package\Demo.SetParameters.xml \\drops\demo\demo_20100607.3_PublishedWebsites\Demo_Package\Demo.SourceManifest.xml \\drops\demo\demo_20100607.3_PublishedWebsites\Demo_Package\ 5 File(s) copied ========================================================= SetParameters from: "c:\setup\demo\Demo.SetParameters.xml" You can change IIS Application Name, Physical path, connectionString or other deploy parameters in the above file. ——————————————————- Start executing msdeploy.exe ——————————————————- "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -source:package=’c:\setup\demo\’ -dest:auto,includeAcls=’False’ -verb:syn c -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"c:\setup\demo\Demo.SetParamet ers.xml" Info: Adding sitemanifest (sitemanifest). Info: Updating createApp (Default Web Site/Demo_deploy). Info: Adding contentPath (Default Web Site/Demo_deploy). … Info: Adding setAcl (Default Web Site/Demo_deploy). Total changes: 37 (36 added, 0 deleted, 1 updated, 0 parameters changed, 737702 bytes copied) [win-y4onzs094up] Process terminated with exit code 0 after 00:00:03.850s [win-y4onzs094up] Removing C:\Windows\temp\DeployWeb.bat

As you can verify, the beyondexec tool was able to connect to remote machine, copied the deployweb.bat script on the remote machine and launched it with the right argument, now I can verify with IIS that the new web application was created in target machine.


Et voilà , we deployed a web application to a remote machine with a simple command. You can use this technique in a tfs build to deploy to a remote server.