Automate deploy
It is possible to use TFS lab management to automate the deploy process described in the previous chapter.
Install the test controller
The test controller installation is located on the "Agents for Visual Studio 2013" DVD. In this case, the test controller is installed on the same server as the build controller.
After install, specify test and lab accounts, and connect the test controller to your team project collection.
Configure the lab
Make sure the lab service account used in the previous step is a local administrator on the BizTalk servers you plan to deploy to.
Start “Microsoft Test Manager 2013” and connect it to your team project. Then, switch to the “Lab Center” part of the application.

Create a new standard environment.

Add the BizTalk servers.

Select test test controller.

Click through to the end of the wizard. The test and lab agents will now be installed on the servers.

When the installation is done, log on to the BizTalk servers and add the lab service account to the local administrators group. Also, add the account to the BizTalk administrators and SSO administrators groups. We need these permissions to be able to install BizTalk applications.
For some reason the test and lab agents are not configured with the correct service accounts. Run the "Test Agent Configuration Tool" to change the test service account.

There is no tool for the lab service. Change the account from the Computer Management console.
Create build definition for deployment
Create a new build definition that builds the test branch and deploys the applications after build. Give it at name, e.g. "Test
BuildDeploy". Start with triggering the build manually. For this type of build, the source settings are not really used, but we have to specify something, so select the Test branch. Under "Build Settings", select the build controller and select "This build does not copy output files to the drop folder".
Select the LabDefault build template.

Select the environment that we defined previously.

Select the build to deploy. "Test" is the build definition for the Test branch that we defined earlier.

Add the servers you want to deploy to, and set the script to:
powershell.exe -File "$(BuildLocation)\AutoDeploy.ps1" "$(BuildLocation)"And the working folder to:
C:\BizTalkDeployImportant Make sure the server where the environment variable BTDF_DeployToBizTalk is true, is the last one in the list.
The AutoDeploy script will copy the ZIP file from the drop folder to the server, extract it, and run Undeploy.ps1 followed by Deploy.ps1.

Click "Finish" and save the build definition. Queue a new build.
Observe that two builds are queued. The lab template first builds the Test build, and then runs deployment.
Important! Always check to build log. The icon may turn green even if the scripts fail.
If no errors occurred, the BizTalk applications are now deployed to the BizTalk group.