Monday, April 10, 2006 3:44 PM bart

Automated build in Team Foundation Server

Performing builds using Visual Studio 2005 Team Foundation Server on a regular basis seems to be attractive, isn't it? Starting a build simply comes down to an invocation of the online build server included with the product. Quite some people have been writing clients to invoke the webservice. However, TFS comes with a (command-line) tool called tfsbuild.exe that performs this job for you. Thanks to this, scheduling a build is pretty straightforward to do using Scheduled Tasks in Windows. The following script works like a charm if your build types don't have spaces in it:

@echo off

if "%1" == "" goto Help
if /i "%1" == "-h" goto Help

set server=%1
set project=%2
set buildType=%3

set schedule=%4
set startTime=%5
set startDate=%6

set schName=%2_%3

set tfsCommand="C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\TfsBuild.exe start %server% %project% %buildType%"

set user=%userdomain%\%username%
echo %tfsCommand%

schtasks /create /sc %schedule% /tn %schName% /tr %tfsCommand% /st %startTime% /sd %startDate% /ru %user% /rp *
Goto Done

:Help
@echo Usage: schbuild TeamfoundationServer TeamProject BuildType Schedule StartTime StartDate
@echo.
@echo     TeamfoundationServer   The Team Foundation server.
@echo.
@echo     TeamProject            Team project name.
@echo.
@echo     BuildType              Build Type name.
@echo.
@echo     Schedule               Specifies the schedule frequency.
@echo                            Valid schedule types: MINUTE, HOURLY,
@echo                            DAILY, WEEKLY, MONTHLY, ONCE.
@echo.
@echo     StartTime              Time to start the build in HH:MM:SS
@echo                            (24 hour format)
@echo.
@echo     StartDate              Specifies the first date on which the
@echo                            task runs. The format is mm/dd/yyyy.

:Done

If the BuildType includes a space however, you'd have to type something like:

schbuild.bat buildmachine123 OurProject "Server Core Engine" DAILY 03:10:00 04/01/2006

In such a case you can either add the task manually or re-write the script.

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

No Comments