Team Foundation Server Build Automation

22
Team Foundation Server Build Automation Give me a Light, Build Light Mike Douglas [email protected] www.CodeSmartNotHard.com www.CodePlex.com/TeamDepl oy

description

Extend the functionality of Team Build creating custom build tasks. Utilize Team Deploy, a set of custom tasks to deploy MSIs to remote machines. I presented this to the Omaha Team System User Group Meeting on 05/27/2008

Transcript of Team Foundation Server Build Automation

Page 1: Team Foundation Server Build Automation

Team Foundation ServerBuild Automation

Give me a Light, Build LightMike Douglas

[email protected]

www.CodePlex.com/TeamDeploy

Page 2: Team Foundation Server Build Automation

About Me

• Current Lead Developer / Analyst at Farm Credit Services of America

• Wide variety background in .NET– Web Services, Remoting, WCF, WinForms, ASP.NET,

Biztalk, TFS, CSLA.NET, Code Generation• Frameworks, Code Generation, and Agile Blog– www.CodeSmartNotHard.com

• Open Source Project for TFS Builds– www.CodePlex.com/TeamDeploy

• 3rd .NET User Group Presentation

Page 3: Team Foundation Server Build Automation

Agenda

• Build Automation – more than just build• Creating a build• What’s in a build – Proj, Targets, and Tasks• Creating a Custom Task• Team Deploy

Page 4: Team Foundation Server Build Automation

Build Automation

• Should be part of a good configuration management process

• Our Goal – Deploy same MSI to test as production– Separate Environments• Development, Test, Staging, Production

– Continuous and “Build and Deploy” Builds– Admin Install MSIs – ConfigFiles folder for multiple environments

Page 5: Team Foundation Server Build Automation

ConfigFiles folder

Page 6: Team Foundation Server Build Automation

Creating a Build

• Demo

Page 7: Team Foundation Server Build Automation

What is in a build?

• TFSBuild.proj – XML for TeamBuild• Targets – “Events” of the build, Before/After

are overrideable for custom functionality.• Tasks – built in or custom actions that perform

a set piece of functionality.

Quick Demo

Page 8: Team Foundation Server Build Automation

Build Targets

Clean

Get Source

Label

Compile

Run Tests

Drop Build Files

End to End Iteration

Build ErrorBuild Break

Page 9: Team Foundation Server Build Automation

Targets

• Commonly used onesTarget Name Description

BeforeEndtoEndIteration Runs tasks before EndToEndIteration target. Use this to run something before the build starts.Example: Turn street light yellow.

AfterEndtoEndIteration Runs tasks after EndToEndIteration target. Use this to run something after the build successfully completes.Example: Copy Binaries and Config Files to MSI, Deploy MSI, Turn on Green Street Light

BeforeTest Called before tests are run.Example: Update or Prepare database or spreadsheet for Unit Tests

AfterOnBuildBreak Called after a work item is created when a build failsExample: Turn on Red Street Light

Page 10: Team Foundation Server Build Automation

Other Overridable TargetsTarget Name DescriptionBuildNumberOverrideTarget Used to override a target to customize a build number. The task you write must

create an ouptut property called BuildNumberBeforeClean Called before clean is tried. Insert your task into this target to run pre-clean

custom target.AfterClean Called after clean is completed.

BeforeGet Called before sources are retrieved from source control

AfterGet Called after sources are retrieved

BeforeLabel Called before sources are labeled.

AfterLabel Called after labeling is completed.

BeforeCompile Called before compilation is completed.

AfterCompile Called after compilation is completed.

AfterTest Called after testing is completed.

BeforeDropBuild Called before saving the built binaries, build log files and test results to the build-drop directory.

AfterDropBuild Called after dropping the built binaries, build log files and test results to the build-drop directory.

BeforeOnBuildBreak Called before creating a work item on the build that fails

Page 11: Team Foundation Server Build Automation

Tasks

• Built in tasks– About 45 built in tasks– Complete List

http://msdn.microsoft.com/en-us/library/7z253716.aspx

• Custom tasks projects– SDC (over 300 tasks!)

http://www.codeplex.com/sdctasks– Community Tasks (about 50 tasks)

http://msbuildtasks.tigris.org/– Team Deploy (Dedicated to Deployments)

http://www.codeplex.com/teamdeploy

Page 12: Team Foundation Server Build Automation

Creating a custom task

• Microsoft.Build.Framework.ITask• Microsoft.Build.Utilities.Task base class

public override bool Execute() { DoSomething();

return true; }

Page 13: Team Foundation Server Build Automation

Creating a custom task (cont)

• Unit Tests – BuildEngine [TestMethod] public void KillProcessExecute() {

Process.Start("notepad.exe"); KillProcess task = new KillProcess();

task.BuildEngine = new MockBuild(); task.ProcessName = "notepad.exe"; task.KillAppPathFilename = "c:\\pstools\\pskill.exe"; task.TargetMachine = Environment.MachineName;

Assert.IsTrue(task.Execute(), "Execute Failed");

}

Page 14: Team Foundation Server Build Automation

Create a custom task

• Demo

Page 15: Team Foundation Server Build Automation

Team Deploy

• Today is the launch of 1.0.0!• 273 Downloads!• Set of Custom Tasks– Deploying MSIs– Controlling Devices like Lava Lamps and Street

Lights• DeviceController Application• Guidance Document

Page 16: Team Foundation Server Build Automation

Team Deploy Features

• Parallel MSI Deployments• Unit Tests• Code Analysis = Green• No unknown programs need to run on target

machines• Utilizes strength and trust of PS Tools.

Page 17: Team Foundation Server Build Automation

Team Deploy Architecture

Page 18: Team Foundation Server Build Automation

Team Deploy TasksTask Name Description

Install Installs a MSI to a target machine

Uninstall Uninstalls MSI on target machine by product code

KillProcess Kills a process on a target machine

StartService Starts are windows service

StopService Stops a windows service (usually before uninstalling)

DeviceController Use lava lamps or street lights to display status of builds

Deploy Primary Task – Reads Deployment Script. The script contains the list of target machines, MSIs to install, any kill processes, and uninstalls.

Page 19: Team Foundation Server Build Automation

Device Controller

• Calls the x10Communicator.exe (part of Team Deploy) to turn on and off devices

• StartTime and StopTime so device doesn’t turn on at night

• Device state is stored in Isolated Storage• Start and Shutdown arguments to turn all

devices either on or off.

Page 20: Team Foundation Server Build Automation

Device Controller Parts

• X10 Firecracker

Page 21: Team Foundation Server Build Automation

Team Deploy Demo

• Street Light Demo

Page 22: Team Foundation Server Build Automation

Links

• X10 Firecracker• SysInternals PSExec• http://www.CodePlex.com/TeamDeploy• http://www.CodeSmartNotHard.com• http://www.tfsbuild.com