implement manhole (ssh-based, colorized/line-editing terminal)
[buildbot.git] / docs / buildbot.texinfo
blob888d18f8a1a88011b571362bbf2467a07a7951c8
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.3+
5 @c %**end of header
7 @copying
8 This is the BuildBot manual.
10 Copyright (C) 2005,2006 Brian Warner
12 Copying and distribution of this file, with or without
13 modification, are permitted in any medium without royalty
14 provided the copyright notice and this notice are preserved.
16 @end copying
18 @titlepage
19 @title BuildBot
20 @page
21 @vskip 0pt plus 1filll
22 @insertcopying
23 @end titlepage
25 @c Output the table of the contents at the beginning.
26 @contents
28 @ifnottex
29 @node Top, Introduction, (dir), (dir)
30 @top BuildBot
32 @insertcopying
33 @end ifnottex
35 @menu
36 * Introduction::                What the BuildBot does.
37 * Installation::                Creating a buildmaster and buildslaves,
38                                 running them.
39 * Concepts::                    What goes on in the buildbot's little mind.
40 * Configuration::               Controlling the buildbot.
41 * Getting Source Code Changes::  Discovering when to run a build.
42 * Build Process::               Controlling how each build is run.
43 * Status Delivery::             Telling the world about the build's results.
44 * Command-line tool::           
45 * Resources::                   Getting help.
46 * Developer's Appendix::        
47 * Index::                       Complete index.
49 @detailmenu
50  --- The Detailed Node Listing ---
52 Introduction
54 * History and Philosophy::      
55 * System Architecture::         
56 * Control Flow::                
58 Installation
60 * Requirements::                
61 * Installing the code::         
62 * Creating a buildmaster::      
63 * Creating a buildslave::       
64 * Launching the daemons::       
65 * Logfiles::                    
66 * Shutdown::                    
67 * Maintenance::                 
68 * Troubleshooting::             
70 Creating a buildslave
72 * Buildslave Options::          
74 Troubleshooting
76 * Starting the buildslave::     
77 * Connecting to the buildmaster::  
78 * Forcing Builds::              
80 Concepts
82 * Version Control Systems::     
83 * Schedulers::                  
84 * BuildSet::                    
85 * BuildRequest::                
86 * Builder::                     
87 * Users::                       
89 Version Control Systems
91 * Generalizing VC Systems::     
92 * Source Tree Specifications::  
93 * How Different VC Systems Specify Sources::  
94 * Attributes of Changes::       
96 Users
98 * Doing Things With Users::     
99 * Email Addresses::             
100 * IRC Nicknames::               
101 * Live Status Clients::         
103 Configuration
105 * Config File Format::          
106 * Loading the Config File::     
107 * Defining the Project::        
108 * Listing Change Sources and Schedulers::  
109 * Setting the slaveport::       
110 * Buildslave Specifiers::       
111 * Defining Builders::           
112 * Defining Status Targets::     
113 * Debug options::               
115 Listing Change Sources and Schedulers
117 * Scheduler Types::             
118 * Build Dependencies::          
120 Getting Source Code Changes
122 * Change Sources::              
124 Change Sources
126 * Choosing ChangeSources::      
127 * CVSToys - PBService::         
128 * CVSToys - mail notification::  
129 * Other mail notification ChangeSources::  
130 * PBChangeSource::              
131 * P4Source::                    
133 Build Process
135 * Build Steps::                 
136 * Interlocks::                  
137 * Build Factories::             
139 Build Steps
141 * Common Parameters::           
142 * Source Checkout::             
143 * ShellCommand::                
144 * Simple ShellCommand Subclasses::  
145 * Writing New BuildSteps::      
147 Source Checkout
149 * CVS::                         
150 * SVN::                         
151 * Darcs::                       
152 * Mercurial::                   
153 * Arch::                        
154 * Bazaar::                      
155 * P4::                          
157 Simple ShellCommand Subclasses
159 * Configure::                   
160 * Compile::                     
161 * Test::                        
162 * Build Properties::            
164 Writing New BuildSteps
166 * Adding LogObservers::         
168 Build Factories
170 * BuildStep Objects::           
171 * BuildFactory::                
172 * Process-Specific build factories::  
174 BuildFactory
176 * BuildFactory Attributes::     
177 * Quick builds::                
179 Process-Specific build factories
181 * GNUAutoconf::                 
182 * CPAN::                        
183 * Python distutils::            
184 * Python/Twisted/trial projects::  
186 Status Delivery
188 * HTML Waterfall::              
189 * IRC Bot::                     
190 * PBListener::                  
191 * Writing New Status Plugins::  
193 Command-line tool
195 * Administrator Tools::         
196 * Developer Tools::             
197 * Other Tools::                 
198 * .buildbot config directory::  
200 Developer Tools
202 * statuslog::                   
203 * statusgui::                   
204 * try::                         
206 Other Tools
208 * sendchange::                  
209 * debugclient::                 
211 @end detailmenu
212 @end menu
214 @node Introduction, Installation, Top, Top
215 @chapter Introduction
217 @cindex introduction
219 The BuildBot is a system to automate the compile/test cycle required by most
220 software projects to validate code changes. By automatically rebuilding and
221 testing the tree each time something has changed, build problems are
222 pinpointed quickly, before other developers are inconvenienced by the
223 failure. The guilty developer can be identified and harassed without human
224 intervention. By running the builds on a variety of platforms, developers
225 who do not have the facilities to test their changes everywhere before
226 checkin will at least know shortly afterwards whether they have broken the
227 build or not. Warning counts, lint checks, image size, compile time, and
228 other build parameters can be tracked over time, are more visible, and
229 are therefore easier to improve.
231 The overall goal is to reduce tree breakage and provide a platform to
232 run tests or code-quality checks that are too annoying or pedantic for
233 any human to waste their time with. Developers get immediate (and
234 potentially public) feedback about their changes, encouraging them to
235 be more careful about testing before checkin.
237 Features:
239 @itemize @bullet
240 @item
241 run builds on a variety of slave platforms
242 @item
243 arbitrary build process: handles projects using C, Python, whatever
244 @item
245 minimal host requirements: python and Twisted
246 @item
247 slaves can be behind a firewall if they can still do checkout
248 @item
249 status delivery through web page, email, IRC, other protocols
250 @item
251 track builds in progress, provide estimated completion time
252 @item
253 flexible configuration by subclassing generic build process classes
254 @item
255 debug tools to force a new build, submit fake Changes, query slave status
256 @item
257 released under the GPL
258 @end itemize
260 @menu
261 * History and Philosophy::      
262 * System Architecture::         
263 * Control Flow::                
264 @end menu
267 @node History and Philosophy, System Architecture, Introduction, Introduction
268 @section History and Philosophy
270 @cindex Philosophy of operation
272 The Buildbot was inspired by a similar project built for a development
273 team writing a cross-platform embedded system. The various components
274 of the project were supposed to compile and run on several flavors of
275 unix (linux, solaris, BSD), but individual developers had their own
276 preferences and tended to stick to a single platform. From time to
277 time, incompatibilities would sneak in (some unix platforms want to
278 use @code{string.h}, some prefer @code{strings.h}), and then the tree
279 would compile for some developers but not others. The buildbot was
280 written to automate the human process of walking into the office,
281 updating a tree, compiling (and discovering the breakage), finding the
282 developer at fault, and complaining to them about the problem they had
283 introduced. With multiple platforms it was difficult for developers to
284 do the right thing (compile their potential change on all platforms);
285 the buildbot offered a way to help.
287 Another problem was when programmers would change the behavior of a
288 library without warning its users, or change internal aspects that
289 other code was (unfortunately) depending upon. Adding unit tests to
290 the codebase helps here: if an application's unit tests pass despite
291 changes in the libraries it uses, you can have more confidence that
292 the library changes haven't broken anything. Many developers
293 complained that the unit tests were inconvenient or took too long to
294 run: having the buildbot run them reduces the developer's workload to
295 a minimum.
297 In general, having more visibility into the project is always good,
298 and automation makes it easier for developers to do the right thing.
299 When everyone can see the status of the project, developers are
300 encouraged to keep the tree in good working order. Unit tests that
301 aren't run on a regular basis tend to suffer from bitrot just like
302 code does: exercising them on a regular basis helps to keep them
303 functioning and useful.
305 The current version of the Buildbot is additionally targeted at
306 distributed free-software projects, where resources and platforms are
307 only available when provided by interested volunteers. The buildslaves
308 are designed to require an absolute minimum of configuration, reducing
309 the effort a potential volunteer needs to expend to be able to
310 contribute a new test environment to the project. The goal is for
311 anyone who wishes that a given project would run on their favorite
312 platform should be able to offer that project a buildslave, running on
313 that platform, where they can verify that their portability code
314 works, and keeps working.
316 @node System Architecture, Control Flow, History and Philosophy, Introduction
317 @comment  node-name,  next,  previous,  up
318 @section System Architecture
320 The Buildbot consists of a single @code{buildmaster} and one or more
321 @code{buildslaves}, connected in a star topology. The buildmaster
322 makes all decisions about what and when to build. It sends commands to
323 be run on the build slaves, which simply execute the commands and
324 return the results. (certain steps involve more local decision making,
325 where the overhead of sending a lot of commands back and forth would
326 be inappropriate, but in general the buildmaster is responsible for
327 everything).
329 The buildmaster is usually fed @code{Changes} by some sort of version
330 control system @xref{Change Sources}, which may cause builds to be
331 run. As the builds are performed, various status messages are
332 produced, which are then sent to any registered Status Targets
333 @xref{Status Delivery}.
335 @ifinfo
336 @smallexample
337 @group
338  TODO: picture of change sources, master, slaves, status targets
339  should look like docs/PyCon-2003/sources/overview.svg
340 @end group
341 @end smallexample
342 @end ifinfo
343 @ifnotinfo
344 @c @image{images/overview}
345 @end ifnotinfo
347 The buildmaster is configured and maintained by the ``buildmaster
348 admin'', who is generally the project team member responsible for
349 build process issues. Each buildslave is maintained by a ``buildslave
350 admin'', who do not need to be quite as involved. Generally slaves are
351 run by anyone who has an interest in seeing the project work well on
352 their platform.
355 @node Control Flow,  , System Architecture, Introduction
356 @comment  node-name,  next,  previous,  up
357 @section Control Flow
359 A day in the life of the buildbot:
361 @itemize @bullet
363 @item
364 A developer commits some source code changes to the repository. A hook
365 script or commit trigger of some sort sends information about this
366 change to the buildmaster through one of its configured Change
367 Sources. This notification might arrive via email, or over a network
368 connection (either initiated by the buildmaster as it ``subscribes''
369 to changes, or by the commit trigger as it pushes Changes towards the
370 buildmaster). The Change contains information about who made the
371 change, what files were modified, which revision contains the change,
372 and any checkin comments.
374 @item
375 The buildmaster distributes this change to all of its configured
376 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
377 to be started, and the Change is added to a list of those that will go
378 into a new Build. When the timer expires, a Build is started on each
379 of a set of configured Builders, all compiling/testing the same source
380 code. Unless configured otherwise, all Builds run in parallel on the
381 various buildslaves.
383 @item
384 The Build consists of a series of Steps. Each Step causes some number
385 of commands to be invoked on the remote buildslave associated with
386 that Builder. The first step is almost always to perform a checkout of
387 the appropriate revision from the same VC system that produced the
388 Change. The rest generally perform a compile and run unit tests. As
389 each Step runs, the buildslave reports back command output and return
390 status to the buildmaster.
392 @item
393 As the Build runs, status messages like ``Build Started'', ``Step
394 Started'', ``Build Finished'', etc, are published to a collection of
395 Status Targets. One of these targets is usually the HTML ``Waterfall''
396 display, which shows a chronological list of events, and summarizes
397 the results of the most recent build at the top of each column.
398 Developers can periodically check this page to see how their changes
399 have fared. If they see red, they know that they've made a mistake and
400 need to fix it. If they see green, they know that they've done their
401 duty and don't need to worry about their change breaking anything.
403 @item
404 If a MailNotifier status target is active, the completion of a build
405 will cause email to be sent to any developers whose Changes were
406 incorporated into this Build. The MailNotifier can be configured to
407 only send mail upon failing builds, or for builds which have just
408 transitioned from passing to failing. Other status targets can provide
409 similar real-time notification via different communication channels,
410 like IRC.
412 @end itemize
415 @node Installation, Concepts, Introduction, Top
416 @chapter Installation
418 @menu
419 * Requirements::                
420 * Installing the code::         
421 * Creating a buildmaster::      
422 * Creating a buildslave::       
423 * Launching the daemons::       
424 * Logfiles::                    
425 * Shutdown::                    
426 * Maintenance::                 
427 * Troubleshooting::             
428 @end menu
430 @node Requirements, Installing the code, Installation, Installation
431 @section Requirements
433 At a bare minimum, you'll need the following (for both the buildmaster
434 and a buildslave):
436 @itemize @bullet
437 @item
438 Python: http://www.python.org
440 Buildbot requires python-2.2 or later, and is primarily developed
441 against python-2.3. The buildmaster uses generators, a feature which
442 is not available in python-2.1, and both master and slave require a
443 version of Twisted which only works with python-2.2 or later. Certain
444 features (like the inclusion of build logs in status emails) require
445 python-2.2.2 or later. The IRC ``force build'' command requires
446 python-2.3 (for the shlex.split function).
448 @item
449 Twisted: http://twistedmatrix.com
451 Both the buildmaster and the buildslaves require Twisted-1.3.0 or
452 later. It has been mainly developed against Twisted-2.0.1, but has
453 been tested against Twisted-2.1.0 (the most recent as of this
454 writing), and might even work on versions as old as Twisted-1.1.0, but
455 as always the most recent version is recommended.
457 Twisted-1.3.0 and earlier were released as a single monolithic
458 package. When you run Buildbot against Twisted-2.0.0 or later (which
459 are split into a number of smaller subpackages), you'll need at least
460 "Twisted" (the core package), and you'll also want TwistedMail,
461 TwistedWeb, and TwistedWords (for sending email, serving a web status
462 page, and delivering build status via IRC, respectively).
463 @end itemize
465 Certain other packages may be useful on the system running the
466 buildmaster:
468 @itemize @bullet
469 @item
470 CVSToys: http://purl.net/net/CVSToys
472 If your buildmaster uses FreshCVSSource to receive change notification
473 from a cvstoys daemon, it will require CVSToys be installed (tested
474 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
475 only use a mail-parsing change source, or the SVN notification
476 script), you will not need CVSToys.
478 @end itemize
480 And of course, your project's build process will impose additional
481 requirements on the buildslaves. These hosts must have all the tools
482 necessary to compile and test your project's source code.
485 @node Installing the code, Creating a buildmaster, Requirements, Installation
486 @section Installing the code
488 @cindex installation
490 The Buildbot is installed using the standard python @code{distutils}
491 module. After unpacking the tarball, the process is:
493 @example
494 python setup.py build
495 python setup.py install
496 @end example
498 where the install step may need to be done as root. This will put the
499 bulk of the code in somewhere like
500 /usr/lib/python2.3/site-packages/buildbot . It will also install the
501 @code{buildbot} command-line tool in /usr/bin/buildbot.
503 To test this, shift to a different directory (like /tmp), and run:
505 @example
506 buildbot --version
507 @end example
509 If it shows you the versions of Buildbot and Twisted, the install went
510 ok. If it says @code{no such command} or it gets an @code{ImportError}
511 when it tries to load the libaries, then something went wrong.
512 @code{pydoc buildbot} is another useful diagnostic tool.
514 Windows users will find these files in other places. You will need to
515 make sure that python can find the libraries, and will probably find
516 it convenient to have @code{buildbot} on your PATH.
518 If you wish, you can run the buildbot unit test suite like this:
520 @example
521 PYTHONPATH=. trial buildbot.test
522 @end example
524 This should run up to 192 tests, depending upon what VC tools you have
525 installed. On my desktop machine it takes about five minutes to
526 complete. Nothing should fail, a few might be skipped. If any of the
527 tests fail, you should stop and investigate the cause before
528 continuing the installation process, as it will probably be easier to
529 track down the bug early.
531 If you cannot or do not wish to install the buildbot into a site-wide
532 location like @file{/usr} or @file{/usr/local}, you can also install
533 it into the account's home directory. Do the install command like
534 this:
536 @example
537 python setup.py install --home=~
538 @end example
540 That will populate @file{~/lib/python} and create
541 @file{~/bin/buildbot}. Make sure this lib directory is on your
542 @code{PYTHONPATH}.
545 @node Creating a buildmaster, Creating a buildslave, Installing the code, Installation
546 @section Creating a buildmaster
548 As you learned earlier (@pxref{System Architecture}), the buildmaster
549 runs on a central host (usually one that is publically visible, so
550 everybody can check on the status of the project), and controls all
551 aspects of the buildbot system. Let us call this host
552 @code{buildbot.example.org}.
554 You may wish to create a separate user account for the buildmaster,
555 perhaps named @code{buildmaster}. This can help keep your personal
556 configuration distinct from that of the buildmaster and is useful if
557 you have to use a mail-based notification system (@pxref{Change
558 Sources}). However, the Buildbot will work just fine with your regular
559 user account.
561 You need to choose a directory for the buildmaster, called the
562 @code{basedir}. This directory will be owned by the buildmaster, which
563 will use configuration files therein, and create status files as it
564 runs. @file{~/Buildbot} is a likely value. If you run multiple
565 buildmasters in the same account, or if you run both masters and
566 slaves, you may want a more distinctive name like
567 @file{~/Buildbot/master/gnomovision} or
568 @file{~/Buildmasters/fooproject}. If you are using a separate user
569 account, this might just be @file{~buildmaster/masters/fooprojects}.
571 Once you've picked a directory, use the @command{buildbot master}
572 command to create the directory and populate it with startup files:
574 @example
575 buildbot master @var{basedir}
576 @end example
578 You will need to create a configuration file (@pxref{Configuration})
579 before starting the buildmaster. Most of the rest of this manual is
580 dedicated to explaining how to do this. A sample configuration file is
581 placed in the working directory, named @file{master.cfg.sample}, which
582 can be copied to @file{master.cfg} and edited to suit your purposes.
584 (Internal details: This command creates a file named
585 @file{buildbot.tac} that contains all the state necessary to create
586 the buildmaster. Twisted has a tool called @code{twistd} which can use
587 this .tac file to create and launch a buildmaster instance. twistd
588 takes care of logging and daemonization (running the program in the
589 background). @file{/usr/bin/buildbot} is a front end which runs twistd
590 for you.)
592 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
593 installed. This can be used as the basis for customized daemon startup,
594 @xref{Launching the daemons}.
597 @node Creating a buildslave, Launching the daemons, Creating a buildmaster, Installation
598 @section Creating a buildslave
600 Typically, you will be adding a buildslave to an existing buildmaster,
601 to provide additional architecture coverage. The buildbot
602 administrator will give you several pieces of information necessary to
603 connect to the buildmaster. You should also be somewhat familiar with
604 the project being tested, so you can troubleshoot build problems
605 locally.
607 The buildbot exists to make sure that the project's stated ``how to
608 build it'' process actually works. To this end, the buildslave should
609 run in an environment just like that of your regular developers.
610 Typically the project build process is documented somewhere
611 (@file{README}, @file{INSTALL}, etc), in a document that should
612 mention all library dependencies and contain a basic set of build
613 instructions. This document will be useful as you configure the host
614 and account in which the buildslave runs.
616 Here's a good checklist for setting up a buildslave:
618 @enumerate
619 @item
620 Set up the account
622 It is recommended (although not mandatory) to set up a separate user
623 account for the buildslave. This account is frequently named
624 @code{buildbot} or @code{buildslave}. This serves to isolate your
625 personal working environment from that of the slave's, and helps to
626 minimize the security threat posed by letting possibly-unknown
627 contributors run arbitrary code on your system. The account should
628 have a minimum of fancy init scripts.
630 @item
631 Install the buildbot code
633 Follow the instructions given earlier (@pxref{Installing the code}).
634 If you use a separate buildslave account, and you didn't install the
635 buildbot code to a shared location, then you will need to install it
636 with @code{--home=~} for each account that needs it.
638 @item
639 Set up the host
641 Make sure the host can actually reach the buildmaster. Usually the
642 buildmaster is running a status webserver on the same machine, so
643 simply point your web browser at it and see if you can get there.
644 Install whatever additional packages or libraries the project's
645 INSTALL document advises. (or not: if your buildslave is supposed to
646 make sure that building without optional libraries still works, then
647 don't install those libraries).
649 Again, these libraries don't necessarily have to be installed to a
650 site-wide shared location, but they must be available to your build
651 process. Accomplishing this is usually very specific to the build
652 process, so installing them to @file{/usr} or @file{/usr/local} is
653 usually the best approach.
655 @item
656 Test the build process
658 Follow the instructions in the INSTALL document, in the buildslave's
659 account. Perform a full CVS (or whatever) checkout, configure, make,
660 run tests, etc. Confirm that the build works without manual fussing.
661 If it doesn't work when you do it by hand, it will be unlikely to work
662 when the buildbot attempts to do it in an automated fashion.
664 @item
665 Choose a base directory
667 This should be somewhere in the buildslave's account, typically named
668 after the project which is being tested. The buildslave will not touch
669 any file outside of this directory. Something like @file{~/Buildbot}
670 or @file{~/Buildslaves/fooproject} is appropriate.
672 @item
673 Get the buildmaster host/port, botname, and password
675 When the buildbot admin configures the buildmaster to accept and use
676 your buildslave, they will provide you with the following pieces of
677 information:
679 @itemize @bullet
680 @item
681 your buildslave's name
682 @item
683 the password assigned to your buildslave
684 @item
685 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
686 @end itemize
688 @item
689 Create the buildslave
691 Now run the 'buildbot' command as follows:
693 @example
694 buildbot slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
695 @end example
697 This will create the base directory and a collection of files inside,
698 including the @file{buildbot.tac} file that contains all the
699 information you passed to the @code{buildbot} command.
701 @item
702 Fill in the hostinfo files
704 When it first connects, the buildslave will send a few files up to the
705 buildmaster which describe the host that it is running on. These files
706 are presented on the web status display so that developers have more
707 information to reproduce any test failures that are witnessed by the
708 buildbot. There are sample files in the @file{info} subdirectory of
709 the buildbot's base directory. You should edit these to correctly
710 describe you and your host.
712 @file{BASEDIR/info/admin} should contain your name and email address.
713 This is the ``buildslave admin address'', and will be visible from the
714 build status page (so you may wish to munge it a bit if
715 address-harvesting spambots are a concern).
717 @file{BASEDIR/info/host} should be filled with a brief description of
718 the host: OS, version, memory size, CPU speed, versions of relevant
719 libraries installed, and finally the version of the buildbot code
720 which is running the buildslave.
722 If you run many buildslaves, you may want to create a single
723 @file{~buildslave/info} file and share it among all the buildslaves
724 with symlinks.
726 @end enumerate
728 @menu
729 * Buildslave Options::          
730 @end menu
732 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
733 @subsection Buildslave Options
735 There are a handful of options you might want to use when creating the
736 buildslave with the @command{buildbot slave <options> DIR <params>}
737 command. You can type @command{buildbot slave --help} for a summary.
738 To use these, just include them on the @command{buildbot slave}
739 command line, like this:
741 @example
742 buildbot slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
743 @end example
745 @table @code
746 @item --usepty
747 This is a boolean flag that tells the buildslave whether to launch
748 child processes in a PTY (the default) or with regular pipes. The
749 advantage of using a PTY is that ``grandchild'' processes are more
750 likely to be cleaned up if the build is interrupted or times out
751 (since it enables the use of a ``process group'' in which all child
752 processes will be placed). The disadvantages: some forms of Unix have
753 problems with PTYs, some of your unit tests may behave differently
754 when run under a PTY (generally those which check to see if they are
755 being run interactively), and PTYs will merge the stdout and stderr
756 streams into a single output stream (which means the red-vs-black
757 coloring in the logfiles will be lost). If you encounter problems, you
758 can add @code{--usepty=0} to disable the use of PTYs. Note that
759 windows buildslaves never use PTYs.
761 @item --umask
762 This is a string (generally an octal representation of an integer)
763 which will cause the buildslave process' ``umask'' value to be set
764 shortly after initialization. The ``twistd'' daemonization utility
765 forces the umask to 077 at startup (which means that all files created
766 by the buildslave or its child processes will be unreadable by any
767 user other than the buildslave account). If you want build products to
768 be readable by other accounts, you can add @code{--umask=022} to tell
769 the buildslave to fix the umask after twistd clobbers it. If you want
770 build products to be @emph{writable} by other accounts too, use
771 @code{--umask=000}, but this is likely to be a security problem.
773 @item --keepalive
774 This is a number that indicates how frequently ``keepalive'' messages
775 should be sent from the buildslave to the buildmaster, expressed in
776 seconds. The default (600) causes a message to be sent to the
777 buildmaster at least once every 10 minutes. To set this to a lower
778 value, use e.g. @code{--keepalive=120}.
780 If the buildslave is behind a NAT box or stateful firewall, these
781 messages may help to keep the connection alive: some NAT boxes tend to
782 forget about a connection if it has not been used in a while. When
783 this happens, the buildmaster will think that the buildslave has
784 disappeared, and builds will time out. Meanwhile the buildslave will
785 not realize than anything is wrong.
787 @end table
790 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
791 @section Launching the daemons
793 Both the buildmaster and the buildslave run as daemon programs. To
794 launch them, pass the working directory to the @code{buildbot}
795 command:
797 @example
798 buildbot start @var{BASEDIR}
799 @end example
801 This command will start the daemon and then return, so normally it
802 will not produce any output. To verify that the programs are indeed
803 running, look for a pair of files named @file{twistd.log} and
804 @file{twistd.pid} that should be created in the working directory.
805 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
807 When the buildslave connects to the buildmaster, new directories will
808 start appearing in its base directory. The buildmaster tells the slave
809 to create a directory for each Builder which will be using that slave.
810 All build operations are performed within these directories: CVS
811 checkouts, compiles, and tests.
813 Once you get everything running, you will want to arrange for the
814 buildbot daemons to be started at boot time. One way is to use
815 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
816 @@reboot syntax is understood by Vixie cron, which is the flavor
817 usually provided with linux systems. Other unices may have a cron that
818 doesn't understand @@reboot}:
820 @example
821 @@reboot buildbot start @var{BASEDIR}
822 @end example
824 When you run @command{crontab} to set this up, remember to do it as
825 the buildmaster or buildslave account! If you add this to your crontab
826 when running as your regular account (or worse yet, root), then the
827 daemon will run as the wrong user, quite possibly as one with more
828 authority than you intended to provide.
830 It is important to remember that the environment provided to cron jobs
831 and init scripts can be quite different that your normal runtime.
832 There may be fewer environment variables specified, and the PATH may
833 be shorter than usual. It is a good idea to test out this method of
834 launching the buildslave by using a cron job with a time in the near
835 future, with the same command, and then check @file{twistd.log} to
836 make sure the slave actually started correctly. Common problems here
837 are for @file{/usr/local} or @file{~/bin} to not be on your
838 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
839 Sometimes @code{HOME} is messed up too.
841 To modify the way the daemons are started (perhaps you want to set
842 some environment variables first, or perform some cleanup each time),
843 you can create a file named @file{Makefile.buildbot} in the base
844 directory. When the @file{buildbot} front-end tool is told to
845 @command{start} the daemon, and it sees this file (and
846 @file{/usr/bin/make} exists), it will do @command{make -f
847 Makefile.buildbot start} instead of its usual action (which involves
848 running @command{twistd}). When the buildmaster or buildslave is
849 installed, a @file{Makefile.sample} is created which implements the
850 same behavior as the the @file{buildbot} tool uses, so if you want to
851 customize the process, just copy @file{Makefile.sample} to
852 @file{Makefile.buildbot} and edit it as necessary.
854 @node Logfiles, Shutdown, Launching the daemons, Installation
855 @section Logfiles
857 @cindex logfiles
859 While a buildbot daemon runs, it emits text to a logfile, named
860 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
861 to watch the command output as it runs.
863 The buildmaster will announce any errors with its configuration file
864 in the logfile, so it is a good idea to look at the log at startup
865 time to check for any problems. Most buildmaster activities will cause
866 lines to be added to the log.
868 @node Shutdown, Maintenance, Logfiles, Installation
869 @section Shutdown
871 To stop a buildmaster or buildslave manually, use:
873 @example
874 buildbot stop @var{BASEDIR}
875 @end example
877 This simply looks for the @file{twistd.pid} file and kills whatever
878 process is identified within.
880 At system shutdown, all processes are sent a @code{SIGKILL}. The
881 buildmaster and buildslave will respond to this by shutting down
882 normally.
884 The buildmaster will respond to a @code{SIGHUP} by re-reading its
885 config file. The following shortcut is available:
887 @example
888 buildbot sighup @var{BASEDIR}
889 @end example
891 When you update the Buildbot code to a new release, you will need to
892 restart the buildmaster and/or buildslave before it can take advantage
893 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
894 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
895 use the @code{restart} shortcut, which does both steps for you:
897 @example
898 buildbot restart @var{BASEDIR}
899 @end example
902 @node Maintenance, Troubleshooting, Shutdown, Installation
903 @section Maintenance
905 It is a good idea to check the buildmaster's status page every once in
906 a while, to see if your buildslave is still online. Eventually the
907 buildbot will probably be enhanced to send you email (via the
908 @file{info/admin} email address) when the slave has been offline for
909 more than a few hours.
911 If you find you can no longer provide a buildslave to the project, please
912 let the project admins know, so they can put out a call for a
913 replacement.
915 The Buildbot records status and logs output continually, each time a
916 build is performed. The status tends to be small, but the build logs
917 can become quite large. Each build and log are recorded in a separate
918 file, arranged hierarchically under the buildmaster's base directory.
919 To prevent these files from growing without bound, you should
920 periodically delete old build logs. A simple cron job to delete
921 anything older than, say, two weeks should do the job. The only trick
922 is to leave the @file{buildbot.tac} and other support files alone, for
923 which find's @code{-mindepth} argument helps skip everything in the
924 top directory. You can use something like the following:
926 @example
927 @@weekly cd BASEDIR && find . -mindepth 2 -type f -mtime +14 -exec rm @{@} \;
928 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
929 @end example
931 @node Troubleshooting,  , Maintenance, Installation
932 @section Troubleshooting
934 Here are a few hints on diagnosing common problems.
936 @menu
937 * Starting the buildslave::     
938 * Connecting to the buildmaster::  
939 * Forcing Builds::              
940 @end menu
942 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
943 @subsection Starting the buildslave
945 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
946 @file{/bin/bash}), and tilde expansion is not always performed in such
947 commands. You may want to use explicit paths, because the @code{PATH}
948 is usually quite short and doesn't include anything set by your
949 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
950 you've installed buildbot (or other python libraries) to an unusual
951 location, you may need to add a @code{PYTHONPATH} specification (note
952 that python will do tilde-expansion on @code{PYTHONPATH} elements by
953 itself). Sometimes it is safer to fully-specify everything:
955 @example
956 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
957 @end example
959 Take the time to get the @@reboot job set up. Otherwise, things will work
960 fine for a while, but the first power outage or system reboot you have will
961 stop the buildslave with nothing but the cries of sorrowful developers to
962 remind you that it has gone away.
964 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
965 @subsection Connecting to the buildmaster
967 If the buildslave cannot connect to the buildmaster, the reason should
968 be described in the @file{twistd.log} logfile. Some common problems
969 are an incorrect master hostname or port number, or a mistyped bot
970 name or password. If the buildslave loses the connection to the
971 master, it is supposed to attempt to reconnect with an
972 exponentially-increasing backoff. Each attempt (and the time of the
973 next attempt) will be logged. If you get impatient, just manually stop
974 and re-start the buildslave.
976 When the buildmaster is restarted, all slaves will be disconnected,
977 and will attempt to reconnect as usual. The reconnect time will depend
978 upon how long the buildmaster is offline (i.e. how far up the
979 exponential backoff curve the slaves have travelled). Again,
980 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
981 speed up the process.
983 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
984 @subsection Forcing Builds
986 From the buildmaster's main status web page, you can force a build to
987 be run on your build slave. Figure out which column is for a builder
988 that runs on your slave, click on that builder's name, and the page
989 that comes up will have a ``Force Build'' button. Fill in the form,
990 hit the button, and a moment later you should see your slave's
991 @file{twistd.log} filling with commands being run. Using @code{pstree}
992 or @code{top} should also reveal the cvs/make/gcc/etc processes being
993 run by the buildslave. Note that the same web page should also show
994 the @file{admin} and @file{host} information files that you configured
995 earlier.
997 @node Concepts, Configuration, Installation, Top
998 @chapter Concepts
1000 This chapter defines some of the basic concepts that the Buildbot
1001 uses. You'll need to understand how the Buildbot sees the world to
1002 configure it properly.
1004 @menu
1005 * Version Control Systems::     
1006 * Schedulers::                  
1007 * BuildSet::                    
1008 * BuildRequest::                
1009 * Builder::                     
1010 * Users::                       
1011 @end menu
1013 @node Version Control Systems, Schedulers, Concepts, Concepts
1014 @section Version Control Systems
1016 @cindex Version Control
1018 These source trees come from a Version Control System of some kind.
1019 CVS and Subversion are two popular ones, but the Buildbot supports
1020 others. All VC systems have some notion of an upstream
1021 @code{repository} which acts as a server@footnote{except Darcs, but
1022 since the Buildbot never modifies its local source tree we can ignore
1023 the fact that Darcs uses a less centralized model}, from which clients
1024 can obtain source trees according to various parameters. The VC
1025 repository provides source trees of various projects, for different
1026 branches, and from various points in time. The first thing we have to
1027 do is to specify which source tree we want to get.
1029 @menu
1030 * Generalizing VC Systems::     
1031 * Source Tree Specifications::  
1032 * How Different VC Systems Specify Sources::  
1033 * Attributes of Changes::       
1034 @end menu
1036 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1037 @subsection Generalizing VC Systems
1039 For the purposes of the Buildbot, we will try to generalize all VC
1040 systems as having repositories that each provide sources for a variety
1041 of projects. Each project is defined as a directory tree with source
1042 files. The individual files may each have revisions, but we ignore
1043 that and treat the project as a whole as having a set of revisions.
1044 Each time someone commits a change to the project, a new revision
1045 becomes available. These revisions can be described by a tuple with
1046 two items: the first is a branch tag, and the second is some kind of
1047 timestamp or revision stamp. Complex projects may have multiple branch
1048 tags, but there is always a default branch. The timestamp may be an
1049 actual timestamp (such as the -D option to CVS), or it may be a
1050 monotonically-increasing transaction number (such as the change number
1051 used by SVN and P4, or the revision number used by Arch, or a labeled
1052 tag used in CVS)@footnote{many VC systems provide more complexity than
1053 this: in particular the local views that P4 and ClearCase can assemble
1054 out of various source directories are more complex than we're prepared
1055 to take advantage of here}. The SHA1 revision ID used by Monotone and
1056 Mercurial is also a kind of revision stamp, in that it specifies a
1057 unique copy of the source tree, as does a Darcs ``context'' file.
1059 When we aren't intending to make any changes to the sources we check out
1060 (at least not any that need to be committed back upstream), there are two
1061 basic ways to use a VC system:
1063 @itemize @bullet
1064 @item
1065 Retrieve a specific set of source revisions: some tag or key is used
1066 to index this set, which is fixed and cannot be changed by subsequent
1067 developers committing new changes to the tree. Releases are built from
1068 tagged revisions like this, so that they can be rebuilt again later
1069 (probably with controlled modifications).
1070 @item
1071 Retrieve the latest sources along a specific branch: some tag is used
1072 to indicate which branch is to be used, but within that constraint we want
1073 to get the latest revisions.
1074 @end itemize
1076 Build personnel or CM staff typically use the first approach: the
1077 build that results is (ideally) completely specified by the two
1078 parameters given to the VC system: repository and revision tag. This
1079 gives QA and end-users something concrete to point at when reporting
1080 bugs. Release engineers are also reportedly fond of shipping code that
1081 can be traced back to a concise revision tag of some sort.
1083 Developers are more likely to use the second approach: each morning
1084 the developer does an update to pull in the changes committed by the
1085 team over the last day. These builds are not easy to fully specify: it
1086 depends upon exactly when you did a checkout, and upon what local
1087 changes the developer has in their tree. Developers do not normally
1088 tag each build they produce, because there is usually significant
1089 overhead involved in creating these tags. Recreating the trees used by
1090 one of these builds can be a challenge. Some VC systems may provide
1091 implicit tags (like a revision number), while others may allow the use
1092 of timestamps to mean ``the state of the tree at time X'' as opposed
1093 to a tree-state that has been explicitly marked.
1095 The Buildbot is designed to help developers, so it usually works in
1096 terms of @emph{the latest} sources as opposed to specific tagged
1097 revisions. However, it would really prefer to build from reproducible
1098 source trees, so implicit revisions are used whenever possible.
1100 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1101 @subsection Source Tree Specifications
1103 So for the Buildbot's purposes we treat each VC system as a server
1104 which can take a list of specifications as input and produce a source
1105 tree as output. Some of these specifications are static: they are
1106 attributes of the builder and do not change over time. Others are more
1107 variable: each build will have a different value. The repository is
1108 changed over time by a sequence of Changes, each of which represents a
1109 single developer making changes to some set of files. These Changes
1110 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1111 violates this assumption of cumulative Changes, but in most situations
1112 the changes don't occur frequently enough for this to be a significant
1113 problem}.
1115 For normal builds, the Buildbot wants to get well-defined source trees
1116 that contain specific Changes, and exclude other Changes that may have
1117 occurred after the desired ones. We assume that the Changes arrive at
1118 the buildbot (through one of the mechanisms described in @pxref{Change
1119 Sources}) in the same order in which they are committed to the
1120 repository. The Buildbot waits for the tree to become ``stable''
1121 before initiating a build, for two reasons. The first is that
1122 developers frequently make multiple related commits in quick
1123 succession, even when the VC system provides ways to make atomic
1124 transactions involving multiple files at the same time. Running a
1125 build in the middle of these sets of changes would use an inconsistent
1126 set of source files, and is likely to fail (and is certain to be less
1127 useful than a build which uses the full set of changes). The
1128 tree-stable-timer is intended to avoid these useless builds that
1129 include some of the developer's changes but not all. The second reason
1130 is that some VC systems (i.e. CVS) do not provide repository-wide
1131 transaction numbers, so that timestamps are the only way to refer to
1132 a specific repository state. These timestamps may be somewhat
1133 ambiguous, due to processing and notification delays. By waiting until
1134 the tree has been stable for, say, 10 minutes, we can choose a
1135 timestamp from the middle of that period to use for our source
1136 checkout, and then be reasonably sure that any clock-skew errors will
1137 not cause the build to be performed on an inconsistent set of source
1138 files.
1140 The Schedulers always use the tree-stable-timer, with a timeout that
1141 is configured to reflect a reasonable tradeoff between build latency
1142 and change frequency. When the VC system provides coherent
1143 repository-wide revision markers (such as Subversion's revision
1144 numbers, or in fact anything other than CVS's timestamps), the
1145 resulting Build is simply performed against a source tree defined by
1146 that revision marker. When the VC system does not provide this, a
1147 timestamp from the middle of the tree-stable period is used to
1148 generate the source tree@footnote{this @code{checkoutDelay} defaults
1149 to half the tree-stable timer, but it can be overridden with an
1150 argument to the Source Step}.
1152 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1153 @subsection How Different VC Systems Specify Sources
1155 For CVS, the static specifications are @code{repository} and
1156 @code{module}. In addition to those, each build uses a timestamp (or
1157 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1158 (which defaults to HEAD). These parameters collectively specify a set
1159 of sources from which a build may be performed.
1161 @uref{http://subversion.tigris.org, Subversion} combines the
1162 repository, module, and branch into a single @code{Subversion URL}
1163 parameter. Within that scope, source checkouts can be specified by a
1164 numeric @code{revision number} (a repository-wide
1165 monotonically-increasing marker, such that each transaction that
1166 changes the repository is indexed by a different revision number), or
1167 a revision timestamp. When branches are used, the repository and
1168 module form a static @code{baseURL}, while each build has a
1169 @code{revision number} and a @code{branch} (which defaults to a
1170 statically-specified @code{defaultBranch}). The @code{baseURL} and
1171 @code{branch} are simply concatenated together to derive the
1172 @code{svnurl} to use for the checkout.
1174 @uref{http://www.perforce.com/, Perforce} is similar. The server
1175 is specified through a @code{P4PORT} parameter. Module and branch
1176 are specified in a single depot path, and revisions are
1177 depot-wide. When branches are used, the @code{p4base} and
1178 @code{defaultBranch} are concatenated together to produce the depot
1179 path.
1181 @uref{http://wiki.gnuarch.org/, Arch} and
1182 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1183 URL, as well as a @code{version} which is kind of like a branch name.
1184 Arch uses the word @code{archive} to represent the repository. Arch
1185 lets you push changes from one archive to another, removing the strict
1186 centralization required by CVS and SVN. It retains the distinction
1187 between repository and working directory that most other VC systems
1188 use. For complex multi-module directory structures, Arch has a
1189 built-in @code{build config} layer with which the checkout process has
1190 two steps. First, an initial bootstrap checkout is performed to
1191 retrieve a set of build-config files. Second, one of these files is
1192 used to figure out which archives/modules should be used to populate
1193 subdirectories of the initial checkout.
1195 Builders which use Arch and Bazaar therefore have a static archive
1196 @code{url}, and a default ``branch'' (which is a string that specifies
1197 a complete category--branch--version triple). Each build can have its
1198 own branch (the category--branch--version string) to override the
1199 default, as well as a revision number (which is turned into a
1200 --patch-NN suffix when performing the checkout).
1202 @uref{http://abridgegame.org/darcs/, Darcs} doesn't really have the
1203 notion of a single master repository. Nor does it really have
1204 branches. In Darcs, each working directory is also a repository, and
1205 there are operations to push and pull patches from one of these
1206 @code{repositories} to another. For the Buildbot's purposes, all you
1207 need to do is specify the URL of a repository that you want to build
1208 from. The build slave will then pull the latest patches from that
1209 repository and build them. Multiple branches are implemented by using
1210 multiple repositories (possibly living on the same server).
1212 Builders which use Darcs therefore have a static @code{repourl} which
1213 specifies the location of the repository. If branches are being used,
1214 the source Step is instead configured with a @code{baseURL} and a
1215 @code{defaultBranch}, and the two strings are simply concatenated
1216 together to obtain the repository's URL. Each build then has a
1217 specific branch which replaces @code{defaultBranch}, or just uses the
1218 default one. Instead of a revision number, each build can have a
1219 ``context'', which is a string that records all the patches that are
1220 present in a given tree (this is the output of @command{darcs changes
1221 --context}, and is considerably less concise than, e.g. Subversion's
1222 revision number, but the patch-reordering flexibility of Darcs makes
1223 it impossible to provide a shorter useful specification).
1225 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1226 each branch is stored in a separate repository. The @code{repourl},
1227 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1228 same way as with Darcs. The ``revision'', however, is the hash
1229 identifier returned by @command{hg identify}.
1232 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1233 @subsection Attributes of Changes
1235 @heading Who
1237 Each Change has a @code{who} attribute, which specifies which
1238 developer is responsible for the change. This is a string which comes
1239 from a namespace controlled by the VC repository. Frequently this
1240 means it is a username on the host which runs the repository, but not
1241 all VC systems require this (Arch, for example, uses a fully-qualified
1242 @code{Arch ID}, which looks like an email address, as does Darcs).
1243 Each StatusNotifier will map the @code{who} attribute into something
1244 appropriate for their particular means of communication: an email
1245 address, an IRC handle, etc.
1247 @heading Files
1249 It also has a list of @code{files}, which are just the tree-relative
1250 filenames of any files that were added, deleted, or modified for this
1251 Change. These filenames are used by the @code{isFileImportant}
1252 function (in the Scheduler) to decide whether it is worth triggering a
1253 new build or not, e.g. the function could use
1254 @code{filename.endswith(".c")} to only run a build if a C file were
1255 checked in. Certain BuildSteps can also use the list of changed files
1256 to run a more targeted series of tests, e.g. the
1257 @code{step_twisted.Trial} step can run just the unit tests that
1258 provide coverage for the modified .py files instead of running the
1259 full test suite.
1261 @heading Comments
1263 The Change also has a @code{comments} attribute, which is a string
1264 containing any checkin comments.
1266 @heading Revision
1268 Each Change can have a @code{revision} attribute, which describes how
1269 to get a tree with a specific state: a tree which includes this Change
1270 (and all that came before it) but none that come after it. If this
1271 information is unavailable, the @code{.revision} attribute will be
1272 @code{None}. These revisions are provided by the ChangeSource, and
1273 consumed by the @code{computeSourceRevision} method in the appropriate
1274 @code{step.Source} class.
1276 @table @samp
1277 @item CVS
1278 @code{revision} is an int, seconds since the epoch
1279 @item SVN
1280 @code{revision} is an int, a transation number (r%d)
1281 @item Darcs
1282 @code{revision} is a large string, the output of @code{darcs changes --context}
1283 @item Mercurial
1284 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1285 @item Arch/Bazaar
1286 @code{revision} is the full revision ID (ending in --patch-%d)
1287 @item P4
1288 @code{revision} is an int, the transaction number
1289 @end table
1291 @heading Branches
1293 The Change might also have a @code{branch} attribute. This indicates
1294 that all of the Change's files are in the same named branch. The
1295 Schedulers get to decide whether the branch should be built or not.
1297 For VC systems like CVS, Arch, and Monotone, the @code{branch} name is
1298 unrelated to the filename. (that is, the branch name and the filename
1299 inhabit unrelated namespaces). For SVN, branches are expressed as
1300 subdirectories of the repository, so the file's ``svnurl'' is a
1301 combination of some base URL, the branch name, and the filename within
1302 the branch. (In a sense, the branch name and the filename inhabit the
1303 same namespace). Darcs branches are subdirectories of a base URL just
1304 like SVN. Mercurial branches are the same as Darcs.
1306 @table @samp
1307 @item CVS
1308 branch='warner-newfeature', files=['src/foo.c']
1309 @item SVN
1310 branch='branches/warner-newfeature', files=['src/foo.c']
1311 @item Darcs
1312 branch='warner-newfeature', files=['src/foo.c']
1313 @item Mercurial
1314 branch='warner-newfeature', files=['src/foo.c']
1315 @item Arch/Bazaar
1316 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1317 @end table
1319 @heading Links
1321 @c TODO: who is using 'links'? how is it being used?
1323 Finally, the Change might have a @code{links} list, which is intended
1324 to provide a list of URLs to a @emph{viewcvs}-style web page that
1325 provides more detail for this Change, perhaps including the full file
1326 diffs.
1329 @node Schedulers, BuildSet, Version Control Systems, Concepts
1330 @section Schedulers
1332 @cindex Scheduler
1334 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1335 gets a copy of every incoming Change. The Schedulers are responsible
1336 for deciding when Builds should be run. Some Buildbot installations
1337 might have a single Scheduler, while others may have several, each for
1338 a different purpose.
1340 For example, a ``quick'' scheduler might exist to give immediate
1341 feedback to developers, hoping to catch obvious problems in the code
1342 that can be detected quickly. These typically do not run the full test
1343 suite, nor do they run on a wide variety of platforms. They also
1344 usually do a VC update rather than performing a brand-new checkout
1345 each time. You could have a ``quick'' scheduler which used a 30 second
1346 timeout, and feeds a single ``quick'' Builder that uses a VC
1347 @code{mode='update'} setting.
1349 A separate ``full'' scheduler would run more comprehensive tests a
1350 little while later, to catch more subtle problems. This scheduler
1351 would have a longer tree-stable-timer, maybe 30 minutes, and would
1352 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1353 @code{'clobber'}, or @code{'export'}).
1355 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1356 made by the Scheduler. Dependencies are also implemented here.
1357 Periodic builds (those which are run every N seconds rather than after
1358 new Changes arrive) are triggered by a special @code{Periodic}
1359 Scheduler subclass. The default Scheduler class can also be told to
1360 watch for specific branches, ignoring Changes on other branches. This
1361 may be useful if you have a trunk and a few release branches which
1362 should be tracked, but when you don't want to have the Buildbot pay
1363 attention to several dozen private user branches.
1365 Some Schedulers may trigger builds for other reasons, other than
1366 recent Changes. For example, a Scheduler subclass could connect to a
1367 remote buildmaster and watch for builds of a library to succeed before
1368 triggering a local build that uses that library.
1370 Each Scheduler creates and submits @code{BuildSet} objects to the
1371 @code{BuildMaster}, which is then responsible for making sure the
1372 individual @code{BuildRequests} are delivered to the target
1373 @code{Builders}.
1375 @code{Scheduler} instances are activated by placing them in the
1376 @code{c['schedulers']} list in the buildmaster config file. Each
1377 Scheduler has a unique name.
1380 @node BuildSet, BuildRequest, Schedulers, Concepts
1381 @section BuildSet
1383 @cindex BuildSet
1385 A @code{BuildSet} is the name given to a set of Builds that all
1386 compile/test the same version of the tree on multiple Builders. In
1387 general, all these component Builds will perform the same sequence of
1388 Steps, using the same source code, but on different platforms or
1389 against a different set of libraries.
1391 The @code{BuildSet} is tracked as a single unit, which fails if any of
1392 the component Builds have failed, and therefore can succeed only if
1393 @emph{all} of the component Builds have succeeded. There are two kinds
1394 of status notification messages that can be emitted for a BuildSet:
1395 the @code{firstFailure} type (which fires as soon as we know the
1396 BuildSet will fail), and the @code{Finished} type (which fires once
1397 the BuildSet has completely finished, regardless of whether the
1398 overall set passed or failed).
1400 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1401 (branch, revision, changes, patch), some of which may be None, and a
1402 list of Builders on which it is to be run. They are then given to the
1403 BuildMaster, which is responsible for creating a separate
1404 @code{BuildRequest} for each Builder.
1406 There are a couple of different likely values for the
1407 @code{SourceStamp}:
1409 @table @code
1410 @item (revision=None, changes=[CHANGES], patch=None)
1411 This is a @code{SourceStamp} used when a series of Changes have
1412 triggered a build. The VC step will attempt to check out a tree that
1413 contains CHANGES (and any changes that occurred before CHANGES, but
1414 not any that occurred after them).
1416 @item (revision=None, changes=None, patch=None)
1417 This builds the most recent code on the default branch. This is the
1418 sort of @code{SourceStamp} that would be used on a Build that was
1419 triggered by a user request, or a Periodic scheduler. It is also
1420 possible to configure the VC Source Step to always check out the
1421 latest sources rather than paying attention to the Changes in the
1422 SourceStamp, which will result in same behavior as this.
1424 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1425 This builds the most recent code on the given BRANCH. Again, this is
1426 generally triggered by a user request or Periodic build.
1428 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1429 This checks out the tree at the given revision REV, then applies a
1430 patch (using @code{diff -pLEVEL <DIFF}). The @ref{try} feature uses
1431 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1432 step is bypassed.
1434 @end table
1436 The buildmaster is responsible for turning the @code{BuildSet} into a
1437 set of @code{BuildRequest} objects and queueing them on the
1438 appropriate Builders.
1441 @node BuildRequest, Builder, BuildSet, Concepts
1442 @section BuildRequest
1444 @cindex BuildRequest
1446 A @code{BuildRequest} is a request to build a specific set of sources
1447 on a single specific Builder. Each Builder runs the
1448 @code{BuildRequest} as soon as it can (i.e. when an associated
1449 buildslave becomes free).
1451 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1452 The actual process of running the build (the series of Steps that will
1453 be executed) is implemented by the @code{Build} object. In this future
1454 this might be changed, to have the @code{Build} define @emph{what}
1455 gets built, and a separate @code{BuildProcess} (provided by the
1456 Builder) to define @emph{how} it gets built.
1458 The @code{BuildRequest} may be mergeable with other compatible
1459 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1460 will generally be mergeable. Builds that are triggered by user
1461 requests are generally not, unless they are multiple requests to build
1462 the @emph{latest sources} of the same branch.
1464 @node Builder, Users, BuildRequest, Concepts
1465 @section Builder
1467 @cindex Builder
1469 The @code{Builder} is a long-lived object which controls all Builds of
1470 a given type. Each one is created when the config file is first
1471 parsed, and lives forever (or rather until it is removed from the
1472 config file). It mediates the connections to the buildslaves that do
1473 all the work, and is responsible for creating the @code{Build} objects
1474 that decide @emph{how} a build is performed (i.e., which steps are
1475 executed in what order).
1477 Each @code{Builder} gets a unique name, and the path name of a
1478 directory where it gets to do all its work (there is a
1479 buildmaster-side directory for keeping status information, as well as
1480 a buildslave-side directory where the actual checkout/compile/test
1481 commands are executed). It also gets a @code{BuildFactory}, which is
1482 responsible for creating new @code{Build} instances: because the
1483 @code{Build} instance is what actually performs each build, choosing
1484 the @code{BuildFactory} is the way to specify what happens each time a
1485 build is done.
1487 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1488 A @code{Builder} which is used to perform OS-X builds (as opposed to
1489 Linux or Solaris builds) should naturally be associated with an
1490 OS-X-based buildslave.
1493 @node Users,  , Builder, Concepts
1494 @section Users
1496 @cindex Users
1498 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1499 the world consists of a set of developers, each of whom can be
1500 described by a couple of simple attributes. These developers make
1501 changes to the source code, causing builds which may succeed or fail.
1503 Each developer is primarily known through the source control system. Each
1504 Change object that arrives is tagged with a @code{who} field that
1505 typically gives the account name (on the repository machine) of the user
1506 responsible for that change. This string is the primary key by which the
1507 User is known, and is displayed on the HTML status pages and in each Build's
1508 ``blamelist''.
1510 To do more with the User than just refer to them, this username needs to
1511 be mapped into an address of some sort. The responsibility for this mapping
1512 is left up to the status module which needs the address. The core code knows
1513 nothing about email addresses or IRC nicknames, just user names.
1515 @menu
1516 * Doing Things With Users::     
1517 * Email Addresses::             
1518 * IRC Nicknames::               
1519 * Live Status Clients::         
1520 @end menu
1522 @node Doing Things With Users, Email Addresses, Users, Users
1523 @subsection Doing Things With Users
1525 Each Change has a single User who is responsible for that Change. Most
1526 Builds have a set of Changes: the Build represents the first time these
1527 Changes have been built and tested by the Buildbot. The build has a
1528 ``blamelist'' that consists of a simple union of the Users responsible
1529 for all the Build's Changes.
1531 The Build provides (through the IBuildStatus interface) a list of Users
1532 who are ``involved'' in the build. For now this is equal to the
1533 blamelist, but in the future it will be expanded to include a ``build
1534 sheriff'' (a person who is ``on duty'' at that time and responsible for
1535 watching over all builds that occur during their shift), as well as
1536 per-module owners who simply want to keep watch over their domain (chosen by
1537 subdirectory or a regexp matched against the filenames pulled out of the
1538 Changes). The Involved Users are those who probably have an interest in the
1539 results of any given build.
1541 In the future, Buildbot will acquire the concept of ``Problems'',
1542 which last longer than builds and have beginnings and ends. For example, a
1543 test case which passed in one build and then failed in the next is a
1544 Problem. The Problem lasts until the test case starts passing again, at
1545 which point the Problem is said to be ``resolved''.
1547 If there appears to be a code change that went into the tree at the
1548 same time as the test started failing, that Change is marked as being
1549 resposible for the Problem, and the user who made the change is added
1550 to the Problem's ``Guilty'' list. In addition to this user, there may
1551 be others who share responsibility for the Problem (module owners,
1552 sponsoring developers). In addition to the Responsible Users, there
1553 may be a set of Interested Users, who take an interest in the fate of
1554 the Problem.
1556 Problems therefore have sets of Users who may want to be kept aware of
1557 the condition of the problem as it changes over time. If configured, the
1558 Buildbot can pester everyone on the Responsible list with increasing
1559 harshness until the problem is resolved, with the most harshness reserved
1560 for the Guilty parties themselves. The Interested Users may merely be told
1561 when the problem starts and stops, as they are not actually responsible for
1562 fixing anything.
1564 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1565 @subsection Email Addresses
1567 The @code{buildbot.status.mail.MailNotifier} class provides a
1568 status target which can send email about the results of each build. It
1569 accepts a static list of email addresses to which each message should be
1570 delivered, but it can also be configured to send mail to the Build's
1571 Interested Users. To do this, it needs a way to convert User names into
1572 email addresses.
1574 For many VC systems, the User Name is actually an account name on the
1575 system which hosts the repository. As such, turning the name into an
1576 email address is a simple matter of appending
1577 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1578 (for example the preferred email address may be at ``project.org''
1579 despite the repository host being named ``cvs.project.org''), and some
1580 VC systems have full separation between the concept of a user and that
1581 of an account on the repository host (like Perforce). Some systems
1582 (like Arch) put a full contact email address in every change.
1584 To convert these names to addresses, the MailNotifier uses an EmailLookup
1585 object. This provides a .getAddress method which accepts a name and
1586 (eventually) returns an address. The default @code{MailNotifier}
1587 module provides an EmailLookup which simply appends a static string,
1588 configurable when the notifier is created. To create more complex behaviors
1589 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1590 determine a preferred address for the developer), provide a different object
1591 as the @code{lookup} argument.
1593 In the future, when the Problem mechanism has been set up, the Buildbot
1594 will need to send mail to arbitrary Users. It will do this by locating a
1595 MailNotifier-like object among all the buildmaster's status targets, and
1596 asking it to send messages to various Users. This means the User-to-address
1597 mapping only has to be set up once, in your MailNotifier, and every email
1598 message the buildbot emits will take advantage of it.
1600 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1601 @subsection IRC Nicknames
1603 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1604 provides a status target which can announce the results of each build. It
1605 also provides an interactive interface by responding to online queries
1606 posted in the channel or sent as private messages.
1608 In the future, the buildbot can be configured map User names to IRC
1609 nicknames, to watch for the recent presence of these nicknames, and to
1610 deliver build status messages to the interested parties. Like
1611 @code{MailNotifier} does for email addresses, the @code{IRC} object
1612 will have an @code{IRCLookup} which is responsible for nicknames. The
1613 mapping can be set up statically, or it can be updated by online users
1614 themselves (by claiming a username with some kind of ``buildbot: i am
1615 user warner'' commands).
1617 Once the mapping is established, the rest of the buildbot can ask the
1618 @code{IRC} object to send messages to various users. It can report on
1619 the likelihood that the user saw the given message (based upon how long the
1620 user has been inactive on the channel), which might prompt the Problem
1621 Hassler logic to send them an email message instead.
1623 @node Live Status Clients,  , IRC Nicknames, Users
1624 @subsection Live Status Clients
1626 The Buildbot also offers a PB-based status client interface which can
1627 display real-time build status in a GUI panel on the developer's desktop.
1628 This interface is normally anonymous, but it could be configured to let the
1629 buildmaster know @emph{which} developer is using the status client. The
1630 status client could then be used as a message-delivery service, providing an
1631 alternative way to deliver low-latency high-interruption messages to the
1632 developer (like ``hey, you broke the build'').
1635 @node Configuration, Getting Source Code Changes, Concepts, Top
1636 @chapter Configuration
1638 @cindex Configuration
1640 The buildbot's behavior is defined by the ``config file'', which
1641 normally lives in the @file{master.cfg} file in the buildmaster's base
1642 directory (but this can be changed with an option to the
1643 @code{buildbot master} command). This file completely specifies which
1644 Builders are to be run, which slaves they should use, how Changes
1645 should be tracked, and where the status information is to be sent. The
1646 buildmaster's @file{buildbot.tac} file names the base directory;
1647 everything else comes from the config file.
1649 A sample config file was installed for you when you created the
1650 buildmaster, but you will need to edit it before your buildbot will do
1651 anything useful.
1653 This chapter gives an overview of the format of this file and the
1654 various sections in it. You will need to read the later chapters to
1655 understand how to fill in each section properly.
1657 @menu
1658 * Config File Format::          
1659 * Loading the Config File::     
1660 * Defining the Project::        
1661 * Listing Change Sources and Schedulers::  
1662 * Setting the slaveport::       
1663 * Buildslave Specifiers::       
1664 * Defining Builders::           
1665 * Defining Status Targets::     
1666 * Debug options::               
1667 @end menu
1669 @node Config File Format, Loading the Config File, Configuration, Configuration
1670 @section Config File Format
1672 The config file is, fundamentally, just a piece of Python code which
1673 defines a dictionary named @code{BuildmasterConfig}, with a number of
1674 keys that are treated specially. You don't need to know Python to do
1675 basic configuration, though, you can just copy the syntax of the
1676 sample file. If you @emph{are} comfortable writing Python code,
1677 however, you can use all the power of a full programming language to
1678 achieve more complicated configurations.
1680 The @code{BuildmasterConfig} name is the only one which matters: all
1681 other names defined during the execution of the file are discarded.
1682 When parsing the config file, the Buildmaster generally compares the
1683 old configuration with the new one and performs the minimum set of
1684 actions necessary to bring the buildbot up to date: Builders which are
1685 not changed are left untouched, and Builders which are modified get to
1686 keep their old event history.
1688 Basic Python syntax: comments start with a hash character (``#''),
1689 tuples are defined with @code{(parenthesis, pairs)}, arrays are
1690 defined with @code{[square, brackets]}, tuples and arrays are mostly
1691 interchangeable. Dictionaries (data structures which map ``keys'' to
1692 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
1693 'key2': 'value2'@} }. Function calls (and object instantiation) can use
1694 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
1696 The config file starts with a series of @code{import} statements,
1697 which make various kinds of Steps and Status targets available for
1698 later use. The main @code{BuildmasterConfig} dictionary is created,
1699 then it is populated with a variety of keys. These keys are broken
1700 roughly into the following sections, each of which is documented in
1701 the rest of this chapter:
1703 @itemize @bullet
1704 @item
1705 Project Definitions
1706 @item
1707 Change Sources / Schedulers
1708 @item
1709 Slaveport
1710 @item
1711 Buildslave Configuration
1712 @item
1713 Builders / Interlocks
1714 @item
1715 Status Targets
1716 @item
1717 Debug options
1718 @end itemize
1720 The config file can use a few names which are placed into its namespace:
1722 @table @code
1723 @item basedir
1724 the base directory for the buildmaster. This string has not been
1725 expanded, so it may start with a tilde. It needs to be expanded before
1726 use. The config file is located in
1727 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
1729 @end table
1732 @node Loading the Config File, Defining the Project, Config File Format, Configuration
1733 @section Loading the Config File
1735 The config file is only read at specific points in time. It is first
1736 read when the buildmaster is launched. Once it is running, there are
1737 various ways to ask it to reload the config file. If you are on the
1738 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
1739 it: the @command{buildbot} tool has a shortcut for this:
1741 @example
1742 buildbot sighup @var{BASEDIR}
1743 @end example
1745 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
1746 ``Reload .cfg'' button which will also trigger a reload. In the
1747 future, there will be other ways to accomplish this step (probably a
1748 password-protected button on the web page, as well as a privileged IRC
1749 command).
1752 @node Defining the Project, Listing Change Sources and Schedulers, Loading the Config File, Configuration
1753 @section Defining the Project
1755 There are a couple of basic settings that you use to tell the buildbot
1756 what project it is working on. This information is used by status
1757 reporters to let users find out more about the codebase being
1758 exercised by this particular Buildbot installation.
1760 @example
1761 c['projectName'] = "Buildbot"
1762 c['projectURL'] = "http://buildbot.sourceforge.net/"
1763 c['buildbotURL'] = "http://localhost:8010/"
1764 @end example
1766 @cindex c['projectName']
1767 @code{projectName} is a short string will be used to describe the
1768 project that this buildbot is working on. For example, it is used as
1769 the title of the waterfall HTML page. 
1771 @cindex c['projectURL']
1772 @code{projectURL} is a string that gives a URL for the project as a
1773 whole. HTML status displays will show @code{projectName} as a link to
1774 @code{projectURL}, to provide a link from buildbot HTML pages to your
1775 project's home page.
1777 @cindex c['buildbotURL']
1778 The @code{buildbotURL} string should point to the location where the
1779 buildbot's internal web server (usually the @code{html.Waterfall}
1780 page) is visible. This typically uses the port number set when you
1781 create the @code{Waterfall} object: the buildbot needs your help to
1782 figure out a suitable externally-visible host name.
1784 When status notices are sent to users (either by email or over IRC),
1785 @code{buildbotURL} will be used to create a URL to the specific build
1786 or problem that they are being notified about. It will also be made
1787 available to queriers (over IRC) who want to find out where to get
1788 more information about this buildbot.
1791 @node Listing Change Sources and Schedulers, Setting the slaveport, Defining the Project, Configuration
1792 @section Listing Change Sources and Schedulers
1794 @cindex c['sources']
1795 The @code{c['sources']} key is a list of ChangeSource
1796 instances@footnote{To be precise, it is a list of objects which all
1797 implement the @code{buildbot.interfaces.IChangeSource} Interface}.
1798 This defines how the buildmaster learns about source code changes.
1799 More information about what goes here is available in @xref{Getting
1800 Source Code Changes}.
1802 @example
1803 import buildbot.changes.pb
1804 c['sources'] = [buildbot.changes.pb.PBChangeSource()]
1805 @end example
1807 @cindex c['schedulers']
1808 @code{c['schedulers']} is a list of Scheduler instances, each of which
1809 causes builds to be started on a particular set of Builders. The two
1810 basic Scheduler classes you are likely to start with are
1811 @code{Scheduler} and @code{Periodic}, but you can write a customized
1812 subclass to implement more complicated build scheduling.
1814 The docstring for @code{buildbot.scheduler.Scheduler} is the best
1815 place to see all the options that can be used. Type @code{pydoc
1816 buildbot.scheduler.Scheduler} to see it, or look in
1817 @file{buildbot/scheduler.py} directly.
1819 The basic Scheduler takes four arguments:
1821 @table @code
1822 @item name
1823 Each Scheduler must have a unique name. This is only used in status
1824 displays.
1826 @item branch
1827 This Scheduler will pay attention to a single branch, ignoring Changes
1828 that occur on other branches. Setting @code{branch} equal to the
1829 special value of @code{None} means it should only pay attention to the
1830 default branch. Note that @code{None} is a keyword, not a string, so
1831 you want to use @code{None} and not @code{"None"}.
1833 @item treeStableTimer
1834 The Scheduler will wait for this many seconds before starting the
1835 build. If new changes are made during this interval, the timer will be
1836 restarted, so really the build will be started after a change and then
1837 after this many seconds of inactivity.
1839 @item builderNames
1840 When the tree-stable-timer finally expires, builds will be started on
1841 these Builders. Each Builder gets a unique name: these strings must
1842 match.
1844 @end table
1846 @example
1847 from buildbot import scheduler
1848 quick = scheduler.Scheduler("quick", None, 60,
1849                             ["quick-linux", "quick-netbsd"])
1850 full = scheduler.Scheduler("full", None, 5*60,
1851                            ["full-linux", "full-netbsd", "full-OSX"])
1852 nightly = scheduler.Periodic("nightly", ["full-solaris"], 24*60*60)
1853 c['schedulers'] = [quick, full, nightly]
1854 @end example
1856 In this example, the two ``quick'' builds are triggered 60 seconds
1857 after the tree has been changed. The ``full'' builds do not run quite
1858 so quickly (they wait 5 minutes), so hopefully if the quick builds
1859 fail due to a missing file or really simple typo, the developer can
1860 discover and fix the problem before the full builds are started. Both
1861 Schedulers only pay attention to the default branch: any changes on
1862 other branches are ignored by these Schedulers. Each Scheduler
1863 triggers a different set of Builders, referenced by name.
1865 The third Scheduler in this example just runs the full solaris build
1866 once per day. (note that this Scheduler only lets you control the time
1867 between builds, not the absolute time-of-day of each Build, so this
1868 could easily wind up a ``daily'' or ``every afternoon'' scheduler
1869 depending upon when it was first activated).
1871 @menu
1872 * Scheduler Types::             
1873 * Build Dependencies::          
1874 @end menu
1876 @node Scheduler Types, Build Dependencies, Listing Change Sources and Schedulers, Listing Change Sources and Schedulers
1877 @subsection Scheduler Types
1879 Here is a brief catalog of the available Scheduler types. All these
1880 Schedulers are classes in @code{buildbot.scheduler}, and the
1881 docstrings there are the best source of documentation on the arguments
1882 taken by each one.
1884 @table @code
1885 @item Scheduler
1886 This is the default Scheduler class. It follows exactly one branch,
1887 and starts a configurable tree-stable-timer after each change on that
1888 branch. When the timer expires, it starts a build on some set of
1889 Builders. The Scheduler accepts a @code{fileIsImportant} function
1890 which can be used to ignore some Changes if they do not affect any
1891 ``important'' files.
1893 @item AnyBranchScheduler
1894 This scheduler uses a tree-stable-timer like the default one, but
1895 follows multiple branches at once. Each branch gets a separate timer.
1897 @item Dependent
1898 This scheduler watches an ``upstream'' Builder. When that Builder
1899 successfully builds a particular set of Changes, it triggers builds of
1900 the same code on a configured set of ``downstream'' builders. The next
1901 section (@pxref{Build Dependencies}) describes this scheduler in more
1902 detail.
1904 @item Periodic
1905 This simple scheduler just triggers a build every N seconds.
1907 @item Nightly
1908 This is highly configurable periodic build scheduler, which triggers a
1909 build at particular times of day, week, month, or year. The
1910 configuration syntax is very similar to the well-known @code{crontab}
1911 format, in which you provide values for minute, hour, day, and month
1912 (some of which can be wildcards), and a build is triggered whenever
1913 the current time matches the given constraints. This can run a build
1914 every night, every morning, every weekend, alternate Thursdays, on
1915 your boss's birthday, etc.
1917 @item Try_Jobdir / Try_Userpass
1918 This scheduler allows developers to use the @code{buildbot try}
1919 command to trigger builds of code they have not yet committed. See
1920 @ref{try} for complete details.
1922 @end table
1924 @node Build Dependencies,  , Scheduler Types, Listing Change Sources and Schedulers
1925 @subsection Build Dependencies
1927 @cindex Dependent
1928 @cindex Dependencies
1930 It is common to wind up with one kind of build which should only be
1931 performed if the same source code was successfully handled by some
1932 other kind of build first. An example might be a packaging step: you
1933 might only want to produce .deb or RPM packages from a tree that was
1934 known to compile successfully and pass all unit tests. You could put
1935 the packaging step in the same Build as the compile and testing steps,
1936 but there might be other reasons to not do this (in particular you
1937 might have several Builders worth of compiles/tests, but only wish to
1938 do the packaging once). Another example is if you want to skip the
1939 ``full'' builds after a failing ``quick'' build of the same source
1940 code. Or, if one Build creates a product (like a compiled library)
1941 that is used by some other Builder, you'd want to make sure the
1942 consuming Build is run @emph{after} the producing one.
1944 You can use @code{Dependencies} to express this relationship to the
1945 Buildbot. There is a special kind of Scheduler named
1946 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
1947 for builds to complete successfully (on all of its Builders). Each
1948 time that happens, the same source code (i.e. the same
1949 @code{SourceStamp}) will be used to start a new set of builds, on a
1950 different set of Builders. This ``downstream'' scheduler doesn't pay
1951 attention to Changes at all, it only pays attention to the upstream
1952 scheduler.
1954 If the SourceStamp fails on any of the Builders in the upstream set,
1955 the downstream builds will not fire.
1957 @example
1958 from buildbot import scheduler
1959 tests = scheduler.Scheduler("tests", None, 5*60,
1960                             ["full-linux", "full-netbsd", "full-OSX"])
1961 package = scheduler.Dependent("package",
1962                               tests, # upstream scheduler
1963                               ["make-tarball", "make-deb", "make-rpm"])
1964 c['schedulers'] = [tests, package]
1965 @end example
1967 Note that @code{Dependent}'s upstream scheduler argument is given as a
1968 @code{Scheduler} @emph{instance}, not a name. This makes it impossible
1969 to create circular dependencies in the config file.
1972 @node Setting the slaveport, Buildslave Specifiers, Listing Change Sources and Schedulers, Configuration
1973 @section Setting the slaveport
1975 @cindex c['slavePortnum']
1977 The buildmaster will listen on a TCP port of your choosing for
1978 connections from buildslaves. It can also use this port for
1979 connections from remote Change Sources, status clients, and debug
1980 tools. This port should be visible to the outside world, and you'll
1981 need to tell your buildslave admins about your choice.
1983 It does not matter which port you pick, as long it is externally
1984 visible, however you should probably use something larger than 1024,
1985 since most operating systems don't allow non-root processes to bind to
1986 low-numbered ports. If your buildmaster is behind a firewall or a NAT
1987 box of some sort, you may have to configure your firewall to permit
1988 inbound connections to this port.
1990 @example
1991 c['slavePortnum'] = 10000
1992 @end example
1994 @code{c['slavePortnum']} is a @emph{strports} specification string,
1995 defined in the @code{twisted.application.strports} module (try
1996 @command{pydoc twisted.application.strports} to get documentation on
1997 the format). This means that you can have the buildmaster listen on a
1998 localhost-only port by doing:
2000 @example
2001 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2002 @end example
2004 This might be useful if you only run buildslaves on the same machine,
2005 and they are all configured to contact the buildmaster at
2006 @code{localhost:10000}.
2009 @node Buildslave Specifiers, Defining Builders, Setting the slaveport, Configuration
2010 @section Buildslave Specifiers
2012 @cindex c['bots']
2014 The @code{c['bots']} key is a list of known buildslaves. Each
2015 buildslave is defined by a tuple of (slavename, slavepassword). These
2016 are the same two values that need to be provided to the buildslave
2017 administrator when they create the buildslave.
2019 @example
2020 c['bots'] = [('bot-solaris', 'solarispasswd'),
2021              ('bot-bsd', 'bsdpasswd'),
2022             ]
2023 @end example
2025 The slavenames must be unique, of course. The password exists to
2026 prevent evildoers from interfering with the buildbot by inserting
2027 their own (broken) buildslaves into the system and thus displacing the
2028 real ones.
2030 Buildslaves with an unrecognized slavename or a non-matching password
2031 will be rejected when they attempt to connect, and a message
2032 describing the problem will be put in the log file (see @ref{Logfiles}).
2035 @node Defining Builders, Defining Status Targets, Buildslave Specifiers, Configuration
2036 @section Defining Builders
2038 @cindex c['builders']
2040 The @code{c['builders']} key is a list of dictionaries which specify
2041 the Builders. The Buildmaster runs a collection of Builders, each of
2042 which handles a single type of build (e.g. full versus quick), on a
2043 single build slave. A Buildbot which makes sure that the latest code
2044 (``HEAD'') compiles correctly across four separate architecture will
2045 have four Builders, each performing the same build but on different
2046 slaves (one per platform).
2048 Each Builder gets a separate column in the waterfall display. In
2049 general, each Builder runs independently (although various kinds of
2050 interlocks can cause one Builder to have an effect on another).
2052 Each Builder specification dictionary has several required keys:
2054 @table @code
2055 @item name
2056 This specifies the Builder's name, which is used in status
2057 reports.
2059 @item slavename
2060 This specifies which buildslave will be used by this Builder.
2061 @code{slavename} must appear in the @code{c['bots']} list. Each
2062 buildslave can accomodate multiple Builders.
2064 @item slavenames
2065 If you provide @code{slavenames} instead of @code{slavename}, you can
2066 give a list of buildslaves which are capable of running this Builder.
2067 If multiple buildslaves are available for any given Builder, you will
2068 have some measure of redundancy: in case one slave goes offline, the
2069 others can still keep the Builder working. In addition, multiple
2070 buildslaves will allow multiple simultaneous builds for the same
2071 Builder, which might be useful if you have a lot of forced or ``try''
2072 builds taking place.
2074 If you use this feature, it is important to make sure that the
2075 buildslaves are all, in fact, capable of running the given build. The
2076 slave hosts should be configured similarly, otherwise you will spend a
2077 lot of time trying (unsuccessfully) to reproduce a failure that only
2078 occurs on some of the buildslaves and not the others. Different
2079 platforms, operating systems, versions of major programs or libraries,
2080 all these things mean you should use separate Builders.
2082 @item builddir
2083 This specifies the name of a subdirectory (under the base directory)
2084 in which everything related to this builder will be placed. On the
2085 buildmaster, this holds build status information. On the buildslave,
2086 this is where checkouts, compiles, and tests are run.
2088 @item factory
2089 This is a @code{buildbot.process.factory.BuildFactory} instance which
2090 controls how the build is performed. Full details appear in their own
2091 chapter, @xref{Build Process}. Parameters like the location of the CVS
2092 repository and the compile-time options used for the build are
2093 generally provided as arguments to the factory's constructor.
2095 @end table
2097 Other optional keys may be set on each Builder:
2099 @table @code
2101 @item category
2102 If provided, this is a string that identifies a category for the
2103 builder to be a part of. Status clients can limit themselves to a
2104 subset of the available categories. A common use for this is to add
2105 new builders to your setup (for a new module, or for a new buildslave)
2106 that do not work correctly yet and allow you to integrate them with
2107 the active builders. You can put these new builders in a test
2108 category, make your main status clients ignore them, and have only
2109 private status clients pick them up. As soon as they work, you can
2110 move them over to the active category.
2112 @end table
2115 @node Defining Status Targets, Debug options, Defining Builders, Configuration
2116 @section Defining Status Targets
2118 The Buildmaster has a variety of ways to present build status to
2119 various users. Each such delivery method is a ``Status Target'' object
2120 in the configuration's @code{status} list. To add status targets, you
2121 just append more objects to this list:
2123 @cindex c['status']
2125 @example
2126 c['status'] = []
2128 from buildbot.status import html
2129 c['status'].append(html.Waterfall(http_port=8010))
2131 from buildbot.status import mail
2132 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
2133                       extraRecipients=["builds@@lists.example.com"],
2134                       sendToInterestedUsers=False)
2135 c['status'].append(m)
2137 from buildbot.status import words
2138 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
2139                              channels=["#example"]))
2140 @end example
2142 Status delivery has its own chapter, @xref{Status Delivery}, in which
2143 all the built-in status targets are documented.
2146 @node Debug options,  , Defining Status Targets, Configuration
2147 @section Debug options
2150 @cindex c['debugPassword']
2151 If you set @code{c['debugPassword']}, then you can connect to the
2152 buildmaster with the diagnostic tool launched by @code{buildbot
2153 debugclient MASTER:PORT}. From this tool, you can reload the config
2154 file, manually force builds, and inject changes, which may be useful
2155 for testing your buildmaster without actually commiting changes to
2156 your repository (or before you have the Change Sources set up). The
2157 debug tool uses the same port number as the slaves do:
2158 @code{c['slavePortnum']}, and is authenticated with this password.
2160 @example
2161 c['debugPassword'] = "debugpassword"
2162 @end example
2164 @cindex c['manhole']
2165 If you set @code{c['manhole']} to an instance of one of the classes in
2166 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
2167 and get an interactive Python shell, which may be useful for debugging
2168 buildbot internals. It is probably only useful for buildbot
2169 developers. It exposes full access to the buildmaster's account
2170 (including the ability to modify and delete files), so it should not
2171 be enabled with a weak or easily guessable password.
2173 There are three separate @code{Manhole} classes. Two of them use SSH,
2174 one uses unencrypted telnet. Two of them use a username+password
2175 combination to grant access, one of them uses an SSH-style
2176 @file{authorized_keys} file which contains a list of ssh public keys.
2178 @table @code
2179 @item manhole.AuthorizedKeysManhole
2180 You construct this with the name of a file that contains one SSH
2181 public key per line, just like @file{~/.ssh/authorized_keys}. If you
2182 provide a non-absolute filename, it will be interpreted relative to
2183 the buildmaster's base directory.
2185 @item manhole.PasswordManhole
2186 This one accepts SSH connections but asks for a username and password
2187 when authenticating. It accepts only one such pair.
2190 @item manhole.TelnetManhole
2191 This accepts regular unencrypted telnet connections, and asks for a
2192 username/password pair before providing access. Because this
2193 username/password is transmitted in the clear, and because Manhole
2194 access to the buildmaster is equivalent to granting full shell
2195 privileges to both the buildmaster and all the buildslaves (and to all
2196 accounts which then run code produced by the buildslaves), it is
2197 highly recommended that you use one of the SSH manholes instead.
2199 @end table
2201 @example
2202 # some examples:
2203 from buildbot import manhole
2204 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
2205 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
2206 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
2207 @end example
2209 The @code{Manhole} instance can be configured to listen on a specific
2210 port. You may wish to have this listening port bind to the loopback
2211 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
2212 restrict access to clients which are running on the same host.
2214 @example
2215 from buildbot.manhole import PasswordManhole
2216 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
2217 @end example
2219 To have the @code{Manhole} listen on all interfaces, use
2220 @code{"tcp:9999"} or simply 9999. This port specification uses
2221 @code{twisted.application.strports}, so you can make it listen on SSL
2222 or even UNIX-domain sockets if you want.
2224 Note that using any Manhole requires that the TwistedConch package be
2225 installed, and that you be using Twisted version 2.0 or later.
2228 @node Getting Source Code Changes, Build Process, Configuration, Top
2229 @chapter Getting Source Code Changes
2231 The most common way to use the Buildbot is centered around the idea of
2232 @code{Source Trees}: a directory tree filled with source code of some form
2233 which can be compiled and/or tested. Some projects use languages that don't
2234 involve any compilation step: nevertheless there may be a @code{build} phase
2235 where files are copied or rearranged into a form that is suitable for
2236 installation. Some projects do not have unit tests, and the Buildbot is
2237 merely helping to make sure that the sources can compile correctly. But in
2238 all of these cases, the thing-being-tested is a single source tree.
2240 A Version Control System mantains a source tree, and tells the
2241 buildmaster when it changes. The first step of each Build is typically
2242 to acquire a copy of some version of this tree.
2244 This chapter describes how the Buildbot learns about what Changes have
2245 occurred. For more information on VC systems and Changes, see
2246 @ref{Version Control Systems}.
2249 @menu
2250 * Change Sources::              
2251 @end menu
2255 @node Change Sources,  , Getting Source Code Changes, Getting Source Code Changes
2256 @section Change Sources
2258 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
2259 @c so narrow-minded anymore
2261 Each Buildmaster watches a single source tree. Changes can be provided
2262 by a variety of ChangeSource types, however any given project will
2263 typically have only a single ChangeSource active. This section
2264 provides a description of all available ChangeSource types and
2265 explains how to set up each of them.
2267 There are a variety of ChangeSources available, some of which are
2268 meant to be used in conjunction with other tools to deliver Change
2269 events from the VC repository to the buildmaster.
2271 @itemize @bullet
2273 @item CVSToys
2274 This ChangeSource opens a TCP connection from the buildmaster to a
2275 waiting FreshCVS daemon that lives on the repository machine, and
2276 subscribes to hear about Changes.
2278 @item MaildirSource
2279 This one watches a local maildir-format inbox for email sent out by
2280 the repository when a change is made. When a message arrives, it is
2281 parsed to create the Change object. A variety of parsing functions are
2282 available to accomodate different email-sending tools.
2284 @item PBChangeSource
2285 This ChangeSource listens on a local TCP socket for inbound
2286 connections from a separate tool. Usually, this tool would be run on
2287 the VC repository machine in a commit hook. It is expected to connect
2288 to the TCP socket and send a Change message over the network
2289 connection. The @command{buildbot sendchange} command is one example
2290 of a tool that knows how to send these messages, so you can write a
2291 commit script for your VC system that calls it to deliver the Change.
2292 There are other tools in the contrib/ directory that use the same
2293 protocol.
2295 @end itemize
2297 As a quick guide, here is a list of VC systems and the ChangeSources
2298 that might be useful with them. All of these ChangeSources are in the
2299 @code{buildbot.changes} module.
2301 @table @code
2302 @item CVS
2304 @itemize @bullet
2305 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
2306 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
2307 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
2308 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
2309 @item pb.PBChangeSource (listening for connections from @code{buildbot
2310 sendchange} run in a loginfo script)
2311 @item pb.PBChangeSource (listening for connections from a long-running
2312 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
2313 database directly
2314 @end itemize
2316 @item SVN
2317 @itemize @bullet
2318 @item pb.PBChangeSource (listening for connections from
2319 @code{contrib/svn_buildbot.py} run in a postcommit script)
2320 @item pb.PBChangeSource (listening for connections from a long-running
2321 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
2322 process
2323 @end itemize
2325 @item Darcs
2326 @itemize @bullet
2327 @item pb.PBChangeSource (listening for connections from
2328 @code{contrib/darcs_buildbot.py} in a commit script
2329 @end itemize
2331 @item Mercurial
2332 @itemize @bullet
2333 @item pb.PBChangeSource (listening for connections from
2334 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
2335 @end itemize
2337 @item Arch/Bazaar
2338 @itemize @bullet
2339 @item pb.PBChangeSource (listening for connections from
2340 @code{contrib/arch_buildbot.py} run in a commit hook)
2341 @end itemize
2343 @end table
2345 All VC systems can be driven by a PBChangeSource and the
2346 @code{buildbot sendchange} tool run from some form of commit script.
2347 If you write an email parsing function, they can also all be driven by
2348 a suitable @code{MaildirSource}.
2351 @menu
2352 * Choosing ChangeSources::      
2353 * CVSToys - PBService::         
2354 * CVSToys - mail notification::  
2355 * Other mail notification ChangeSources::  
2356 * PBChangeSource::              
2357 * P4Source::                    
2358 @end menu
2360 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Change Sources
2361 @subsection Choosing ChangeSources
2363 The @code{master.cfg} configuration file has a dictionary key named
2364 @code{BuildmasterConfig['sources']}, which holds a list of
2365 @code{IChangeSource} objects. The config file will typically create an
2366 object from one of the classes described below and stuff it into the
2367 list.
2369 @example
2370 s = FreshCVSSourceNewcred(host="host", port=4519,
2371                           user="alice", passwd="secret",
2372                           prefix="Twisted")
2373 BuildmasterConfig['sources'] = [s]
2374 @end example
2376 Each source tree has a nominal @code{top}. Each Change has a list of
2377 filenames, which are all relative to this top location. The
2378 ChangeSource is responsible for doing whatever is necessary to
2379 accomplish this. Most sources have a @code{prefix} argument: a partial
2380 pathname which is stripped from the front of all filenames provided to
2381 that @code{ChangeSource}. Files which are outside this sub-tree are
2382 ignored by the changesource: it does not generate Changes for those
2383 files.
2386 @node CVSToys - PBService, CVSToys - mail notification, Choosing ChangeSources, Change Sources
2387 @subsection CVSToys - PBService
2389 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
2390 server which runs on the machine that hosts the CVS repository it
2391 watches. It has a variety of ways to distribute commit notifications,
2392 and offers a flexible regexp-based way to filter out uninteresting
2393 changes. One of the notification options is named @code{PBService} and
2394 works by listening on a TCP port for clients. These clients subscribe
2395 to hear about commit notifications.
2397 The buildmaster has a CVSToys-compatible @code{PBService} client built
2398 in. There are two versions of it, one for old versions of CVSToys
2399 (1.0.9 and earlier) which used the @code{oldcred} authentication
2400 framework, and one for newer versions (1.0.10 and later) which use
2401 @code{newcred}. Both are classes in the
2402 @code{buildbot.changes.freshcvs} package.
2404 @code{FreshCVSSourceNewcred} objects are created with the following
2405 parameters:
2407 @table @samp
2409 @item @code{host} and @code{port}
2410 these specify where the CVSToys server can be reached
2412 @item @code{user} and @code{passwd}
2413 these specify the login information for the CVSToys server
2414 (@code{freshcvs}). These must match the server's values, which are
2415 defined in the @code{freshCfg} configuration file (which lives in the
2416 CVSROOT directory of the repository).
2418 @item @code{prefix}
2419 this is the prefix to be found and stripped from filenames delivered
2420 by the CVSToys server. Most projects live in sub-directories of the
2421 main repository, as siblings of the CVSROOT sub-directory, so
2422 typically this prefix is set to that top sub-directory name.
2424 @end table
2426 @heading Example
2428 To set up the freshCVS server, add a statement like the following to
2429 your @file{freshCfg} file:
2431 @example
2432 pb = ConfigurationSet([
2433     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
2434     ])
2435 @end example
2437 This will announce all changes to a client which connects to port 4519
2438 using a username of 'foo' and a password of 'bar'.
2440 Then add a clause like this to your buildmaster's @file{master.cfg}:
2442 @example
2443 BuildmasterConfig['sources'] = [FreshCVSSource("cvs.example.com", 4519,
2444                                 "foo", "bar",
2445                                 prefix="glib/")]
2446 @end example
2448 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
2449 "glib" is the top-level directory (relative to the repository's root) where
2450 all your source code lives. Most projects keep one or more projects in the
2451 same repository (along with CVSROOT/ to hold admin files like loginfo and
2452 freshCfg); the prefix= argument tells the buildmaster to ignore everything
2453 outside that directory, and to strip that common prefix from all pathnames
2454 it handles.
2458 @node CVSToys - mail notification, Other mail notification ChangeSources, CVSToys - PBService, Change Sources
2459 @subsection CVSToys - mail notification
2461 CVSToys also provides a @code{MailNotification} action which will send
2462 email to a list of recipients for each commit. This tends to work
2463 better than using @code{/bin/mail} from within the CVSROOT/loginfo
2464 file directly, as CVSToys will batch together all files changed during
2465 the same CVS invocation, and can provide more information (like
2466 creating a ViewCVS URL for each file changed).
2468 The Buildbot's @code{FCMaildirSource} is a ChangeSource which knows
2469 how to parse these CVSToys messages and turn them into Change objects.
2470 It watches a Maildir for new messages. The usually installation
2471 process looks like:
2473 @enumerate
2474 @item
2475 Create a mailing list, @code{projectname-commits}.
2476 @item
2477 In CVSToys' freshCfg file, use a @code{MailNotification} action to
2478 send commit mail to this mailing list.
2479 @item
2480 Subscribe the buildbot user to the mailing list.
2481 @item
2482 Configure your .qmail or .forward file to deliver these messages into
2483 a maildir.
2484 @item
2485 In the Buildbot's master.cfg file, use a @code{FCMaildirSource} to
2486 watch the maildir for commit messages.
2487 @end enumerate
2489 The @code{FCMaildirSource} is created with two parameters: the
2490 directory name of the maildir root, and the prefix to strip.
2492 @node Other mail notification ChangeSources, PBChangeSource, CVSToys - mail notification, Change Sources
2493 @subsection Other mail notification ChangeSources
2495 There are other types of maildir-watching ChangeSources, which only
2496 differ in the function used to parse the message body.
2498 @code{SyncmailMaildirSource} knows how to parse the message format
2499 used in mail sent by Syncmail.
2501 @code{BonsaiMaildirSource} parses messages sent out by Bonsai.
2503 @node PBChangeSource, P4Source, Other mail notification ChangeSources, Change Sources
2504 @subsection PBChangeSource
2506 The last kind of ChangeSource actually listens on a TCP port for
2507 clients to connect and push change notices @emph{into} the
2508 Buildmaster. This is used by the built-in @code{buildbot sendchange}
2509 notification tool, as well as the VC-specific
2510 @file{contrib/svn_buildbot.py} and @file{contrib/arch_buildbot.py}
2511 tools. These tools are run by the repository (in a commit hook
2512 script), and connect to the buildmaster directly each time a file is
2513 comitted. This is also useful for creating new kinds of change sources
2514 that work on a @code{push} model instead of some kind of subscription
2515 scheme, for example a script which is run out of an email .forward
2516 file.
2518 This ChangeSource can be configured to listen on its own TCP port, or
2519 it can share the port that the buildmaster is already using for the
2520 buildslaves to connect. (This is possible because the
2521 @code{PBChangeSource} uses the same protocol as the buildslaves, and
2522 they can be distinguished by the @code{username} attribute used when
2523 the initial connection is established). It might be useful to have it
2524 listen on a different port if, for example, you wanted to establish
2525 different firewall rules for that port. You could allow only the SVN
2526 repository machine access to the @code{PBChangeSource} port, while
2527 allowing only the buildslave machines access to the slave port. Or you
2528 could just expose one port and run everything over it. @emph{Note:
2529 this feature is not yet implemented, the PBChangeSource will always
2530 share the slave port and will always have a @code{user} name of
2531 @code{change}, and a passwd of @code{changepw}. These limitations will
2532 be removed in the future.}.
2535 The @code{PBChangeSource} is created with the following
2536 arguments:
2538 @table @samp
2539 @item @code{port}
2540 which port to listen on. If @code{None} (which is the default), it
2541 shares the port used for buildslave connections. @emph{Not
2542 Implemented, always set to @code{None}}.
2544 @item @code{user} and @code{passwd}
2545 the user/passwd account information that the client program must use
2546 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
2547 Implemented, @code{user} is currently always set to @code{change},
2548 @code{passwd} is always set to @code{changepw}}.
2550 @item @code{prefix}
2551 the prefix to be found and stripped from filenames delivered over the
2552 connection.
2553 @end table
2556 @node P4Source,  , PBChangeSource, Change Sources
2557 @subsection P4Source
2559 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
2560 Perforce} depot for changes. It accepts the following arguments:
2562 @table @samp
2563 @item @code{p4base}
2564 The base depot path to watch, without the trailing '/...'.
2566 @item @code{p4port}
2567 The Perforce server to connect to (as host:port).
2569 @item @code{p4user}
2570 The Perforce user.
2572 @item @code{p4passwd}
2573 The Perforce password.
2575 @item @code{split_file}
2576 A function that maps a pathname, without the leading @code{p4base}, to a
2577 (branch, filename) tuple. The default just returns (None, branchfile),
2578 which effectively disables branch support. You should supply a function
2579 which understands your repository structure.
2581 @item @code{pollinterval}
2582 How often to poll, in seconds. Defaults to 600 (10 minutes).
2584 @item @code{histmax}
2585 The maximum number of changes to inspect at a time. If more than this
2586 number occur since the last poll, older changes will be silently
2587 ignored.
2588 @end table
2590 @heading Example
2592 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
2593 specified in the buildmaster's environment. It watches a project in which the
2594 branch name is simply the next path component, and the file is all path
2595 components after.
2597 @example
2598 import buildbot.changes.p4poller
2599 c['sources'].append(p4poller.P4Source(
2600         p4base='//depot/project/',
2601         split_file=lambda branchfile: branchfile.split('/',1)
2603 @end example
2605 @node Build Process, Status Delivery, Getting Source Code Changes, Top
2606 @chapter Build Process
2608 A @code{Build} object is responsible for actually performing a build.
2609 It gets access to a remote @code{SlaveBuilder} where it may run
2610 commands, and a @code{BuildStatus} object where it must emit status
2611 events. The @code{Build} is created by the Builder's
2612 @code{BuildFactory}.
2614 The default @code{Build} class is made up of a fixed sequence of
2615 @code{BuildSteps}, executed one after another until all are complete
2616 (or one of them indicates that the build should be halted early). The
2617 default @code{BuildFactory} creates instances of this @code{Build}
2618 class with a list of @code{BuildSteps}, so the basic way to configure
2619 the build is to provide a list of @code{BuildSteps} to your
2620 @code{BuildFactory}.
2622 More complicated @code{Build} subclasses can make other decisions:
2623 execute some steps only if certain files were changed, or if certain
2624 previous steps passed or failed. The base class has been written to
2625 allow users to express basic control flow without writing code, but
2626 you can always subclass and customize to achieve more specialized
2627 behavior.
2629 @menu
2630 * Build Steps::                 
2631 * Interlocks::                  
2632 * Build Factories::             
2633 @end menu
2635 @node Build Steps, Interlocks, Build Process, Build Process
2636 @section Build Steps
2638 @code{BuildStep}s are usually specified in the buildmaster's
2639 configuration file, in a list of ``step specifications'' that is used
2640 to create the @code{BuildFactory}. These ``step specifications'' are
2641 not actual steps, but rather a tuple of the @code{BuildStep} subclass
2642 to be created and a dictionary of arguments. (the actual
2643 @code{BuildStep} instances are not created until the Build is started,
2644 so that each Build gets an independent copy of each BuildStep). There
2645 is a convenience function named ``@code{s}'' in the
2646 @code{buildbot.process.factory} module for creating these
2647 specification tuples. It allows you to create a
2648 @code{BuildFactory}-ready list like this:
2650 @example
2651 from buildbot.process import step, factory
2652 from buildbot.process.factory import s
2654 steps = [s(step.SVN, svnurl="http://svn.example.org/Trunk/"),
2655          s(step.ShellCommand, command=["make", "all"]),
2656          s(step.ShellCommand, command=["make", "test"]),
2657         ]
2658 f = factory.BuildFactory(steps)
2659 @end example
2661 The rest of this section lists all the standard BuildStep objects
2662 available for use in a Build, and the parameters which can be used to
2663 control each.
2665 @menu
2666 * Common Parameters::           
2667 * Source Checkout::             
2668 * ShellCommand::                
2669 * Simple ShellCommand Subclasses::  
2670 * Writing New BuildSteps::      
2671 @end menu
2673 @node Common Parameters, Source Checkout, Build Steps, Build Steps
2674 @subsection Common Parameters
2676 The standard @code{Build} runs a series of @code{BuildStep}s in order,
2677 only stopping when it runs out of steps or if one of them requests
2678 that the build be halted. It collects status information from each one
2679 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
2681 All BuildSteps accept some common parameters. Some of these control
2682 how their individual status affects the overall build. Others are used
2683 to specify which @code{Locks} (see @pxref{Interlocks}) should be
2684 acquired before allowing the step to run.
2686 Arguments common to all @code{BuildStep} subclasses:
2689 @table @code
2690 @item name
2691 the name used to describe the step on the status display. It is also
2692 used to give a name to any LogFiles created by this step.
2694 @item haltOnFailure
2695 if True, a FAILURE of this build step will cause the build to halt
2696 immediately with an overall result of FAILURE.
2698 @item flunkOnWarnings
2699 when True, a WARNINGS or FAILURE of this build step will mark the
2700 overall build as FAILURE. The remaining steps will still be executed.
2702 @item flunkOnFailure
2703 when True, a FAILURE of this build step will mark the overall build as
2704 a FAILURE. The remaining steps will still be executed.
2706 @item warnOnWarnings
2707 when True, a WARNINGS or FAILURE of this build step will mark the
2708 overall build as having WARNINGS. The remaining steps will still be
2709 executed.
2711 @item warnOnFailure
2712 when True, a FAILURE of this build step will mark the overall build as
2713 having WARNINGS. The remaining steps will still be executed.
2715 @item locks
2716 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
2717 @code{buildbot.locks.MasterLock}) that should be acquired before
2718 starting this Step. The Locks will be released when the step is
2719 complete. Note that this is a list of actual Lock instances, not
2720 names. Also note that all Locks must have unique names.
2722 @end table
2725 @node Source Checkout, ShellCommand, Common Parameters, Build Steps
2726 @subsection Source Checkout
2728 The first step of any build is typically to acquire the source code
2729 from which the build will be performed. There are several classes to
2730 handle this, one for each of the different source control system that
2731 Buildbot knows about. For a description of how Buildbot treats source
2732 control in general, see @ref{Version Control Systems}.
2734 All source checkout steps accept some common parameters to control how
2735 they get the sources and where they should be placed. The remaining
2736 per-VC-system parameters are mostly to specify where exactly the
2737 sources are coming from.
2739 @table @code
2740 @item mode
2742 a string describing the kind of VC operation that is desired. Defaults
2743 to @code{update}.
2745 @table @code
2746 @item update
2747 specifies that the CVS checkout/update should be performed directly
2748 into the workdir. Each build is performed in the same directory,
2749 allowing for incremental builds. This minimizes disk space, bandwidth,
2750 and CPU time. However, it may encounter problems if the build process
2751 does not handle dependencies properly (sometimes you must do a ``clean
2752 build'' to make sure everything gets compiled), or if source files are
2753 deleted but generated files can influence test behavior (e.g. python's
2754 .pyc files), or when source directories are deleted but generated
2755 files prevent CVS from removing them. Builds ought to be correct
2756 regardless of whether they are done ``from scratch'' or incrementally,
2757 but it is useful to test both kinds: this mode exercises the
2758 incremental-build style.
2760 @item copy
2761 specifies that the CVS workspace should be maintained in a separate
2762 directory (called the 'copydir'), using checkout or update as
2763 necessary. For each build, a new workdir is created with a copy of the
2764 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
2765 disk space required, but keeps the bandwidth low (update instead of a
2766 full checkout). A full 'clean' build is performed each time. This
2767 avoids any generated-file build problems, but is still occasionally
2768 vulnerable to CVS problems such as a repository being manually
2769 rearranged, causing CVS errors on update which are not an issue with a
2770 full checkout.
2772 @c TODO: something is screwy about this, revisit. Is it the source
2773 @c directory or the working directory that is deleted each time?
2775 @item clobber
2776 specifes that the working directory should be deleted each time,
2777 necessitating a full checkout for each build. This insures a clean
2778 build off a complete checkout, avoiding any of the problems described
2779 above. This mode exercises the ``from-scratch'' build style.
2781 @item export
2782 this is like @code{clobber}, except that the 'cvs export' command is
2783 used to create the working directory. This command removes all CVS
2784 metadata files (the CVS/ directories) from the tree, which is
2785 sometimes useful for creating source tarballs (to avoid including the
2786 metadata in the tar file).
2787 @end table
2789 @item workdir
2790 like all Steps, this indicates the directory where the build will take
2791 place. Source Steps are special in that they perform some operations
2792 outside of the workdir (like creating the workdir itself).
2794 @item alwaysUseLatest
2795 if True, bypass the usual ``update to the last Change'' behavior, and
2796 always update to the latest changes instead.
2798 @item retry
2799 If set, this specifies a tuple of @code{(delay, repeats)} which means
2800 that when a full VC checkout fails, it should be retried up to
2801 @var{repeats} times, waiting @var{delay} seconds between attempts. If
2802 you don't provide this, it defaults to @code{None}, which means VC
2803 operations should not be retried. This is provided to make life easier
2804 for buildslaves which are stuck behind poor network connections.
2806 @end table
2809 My habit as a developer is to do a @code{cvs update} and @code{make} each
2810 morning. Problems can occur, either because of bad code being checked in, or
2811 by incomplete dependencies causing a partial rebuild to fail where a
2812 complete from-scratch build might succeed. A quick Builder which emulates
2813 this incremental-build behavior would use the @code{mode='update'}
2814 setting.
2816 On the other hand, other kinds of dependency problems can cause a clean
2817 build to fail where a partial build might succeed. This frequently results
2818 from a link step that depends upon an object file that was removed from a
2819 later version of the tree: in the partial tree, the object file is still
2820 around (even though the Makefiles no longer know how to create it).
2822 ``official'' builds (traceable builds performed from a known set of
2823 source revisions) are always done as clean builds, to make sure it is
2824 not influenced by any uncontrolled factors (like leftover files from a
2825 previous build). A ``full'' Builder which behaves this way would want
2826 to use the @code{mode='clobber'} setting.
2828 Each VC system has a corresponding source checkout class: their
2829 arguments are described on the following pages.
2832 @menu
2833 * CVS::                         
2834 * SVN::                         
2835 * Darcs::                       
2836 * Mercurial::                   
2837 * Arch::                        
2838 * Bazaar::                      
2839 * P4::                          
2840 @end menu
2842 @node CVS, SVN, Source Checkout, Source Checkout
2843 @subsubsection CVS
2845 @cindex CVS Checkout
2847 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
2848 CVS} checkout or update. It takes the following arguments:
2850 @table @code
2851 @item cvsroot
2852 (required): specify the CVSROOT value, which points to a CVS
2853 repository, probably on a remote machine. For example, the cvsroot
2854 value you would use to get a copy of the Buildbot source code is
2855 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
2857 @item cvsmodule
2858 (required): specify the cvs @code{module}, which is generally a
2859 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
2860 code is @code{buildbot}.
2862 @item branch
2863 a string which will be used in a @code{-r} argument. This is most
2864 useful for specifying a branch to work on. Defaults to @code{HEAD}.
2866 @item global_options
2867 a list of flags to be put before the verb in the CVS command.
2869 @item checkoutDelay
2870 if set, the number of seconds to put between the timestamp of the last
2871 known Change and the value used for the @code{-D} option. Defaults to
2872 half of the parent Build's treeStableTimer.
2874 @end table
2877 @node SVN, Darcs, CVS, Source Checkout
2878 @subsubsection SVN
2880 @cindex SVN Checkout
2882 The @code{SVN} build step performs a
2883 @uref{http://subversion.tigris.org, Subversion} checkout or update.
2884 There are two basic ways of setting up the checkout step, depending
2885 upon whether you are using multiple branches or not.
2887 If all of your builds use the same branch, then you should create the
2888 @code{SVN} step with the @code{svnurl} argument:
2890 @table @code
2891 @item svnurl
2892 (required): this specifies the @code{URL} argument that will be given
2893 to the @code{svn checkout} command. It dictates both where the
2894 repository is located and which sub-tree should be extracted. In this
2895 respect, it is like a combination of the CVS @code{cvsroot} and
2896 @code{cvsmodule} arguments. For example, if you are using a remote
2897 Subversion repository which is accessible through HTTP at a URL of
2898 @code{http://svn.example.com/repos}, and you wanted to check out the
2899 @code{trunk/calc} sub-tree, you would use
2900 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
2901 to your @code{SVN} step.
2902 @end table
2904 If, on the other hand, you are building from multiple branches, then
2905 you should create the @code{SVN} step with the @code{baseURL} and
2906 @code{defaultBranch} arguments instead:
2908 @table @code
2909 @item baseURL
2910 (required): this specifies the base repository URL, to which a branch
2911 name will be appended. It should probably end in a slash.
2913 @item defaultBranch
2914 this specifies the name of the branch to use when a Build does not
2915 provide one of its own. This will be appended to @code{baseURL} to
2916 create the string that will be passed to the @code{svn checkout}
2917 command.
2918 @end table
2920 If you are using branches, you must also make sure your
2921 @code{ChangeSource} will report the correct branch names.
2923 @heading branch example
2925 Let's suppose that the ``MyProject'' repository uses branches for the
2926 trunk, for various users' individual development efforts, and for
2927 several new features that will require some amount of work (involving
2928 multiple developers) before they are ready to merge onto the trunk.
2929 Such a repository might be organized as follows:
2931 @example
2932 svn://svn.example.org/MyProject/trunk
2933 svn://svn.example.org/MyProject/branches/User1/foo
2934 svn://svn.example.org/MyProject/branches/User1/bar
2935 svn://svn.example.org/MyProject/branches/User2/baz
2936 svn://svn.example.org/MyProject/features/newthing
2937 svn://svn.example.org/MyProject/features/otherthing
2938 @end example
2940 Further assume that we want the Buildbot to run tests against the
2941 trunk and against all the feature branches (i.e., do a
2942 checkout/compile/build of branch X when a file has been changed on
2943 branch X, when X is in the set [trunk, features/newthing,
2944 features/otherthing]). We do not want the Buildbot to automatically
2945 build any of the user branches, but it should be willing to build a
2946 user branch when explicitly requested (most likely by the user who
2947 owns that branch).
2949 There are three things that need to be set up to accomodate this
2950 system. The first is a ChangeSource that is capable of identifying the
2951 branch which owns any given file. This depends upon a user-supplied
2952 function, in an external program that runs in the SVN commit hook and
2953 connects to the buildmaster's @code{PBChangeSource} over a TCP
2954 connection. (you can use the ``@code{buildbot sendchange}'' utility
2955 for this purpose, but you will still need an external program to
2956 decide what value should be passed to the @code{--branch=} argument).
2957 For example, a change to a file with the SVN url of
2958 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
2959 be broken down into a Change instance with
2960 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
2962 The second piece is an @code{AnyBranchScheduler} which will pay
2963 attention to the desired branches. It will not pay attention to the
2964 user branches, so it will not automatically start builds in response
2965 to changes there. The AnyBranchScheduler class requires you to
2966 explicitly list all the branches you want it to use, but it would not
2967 be difficult to write a subclass which used
2968 @code{branch.startswith('features/'} to remove the need for this
2969 explicit list. Or, if you want to build user branches too, you can use
2970 AnyBranchScheduler with @code{branches=None} to indicate that you want
2971 it to pay attention to all branches.
2973 The third piece is an @code{SVN} checkout step that is configured to
2974 handle the branches correctly, with a @code{baseURL} value that
2975 matches the way the ChangeSource splits each file's URL into base,
2976 branch, and file.
2978 @example
2979 from buildbot.changes.pb import PBChangeSource
2980 from buildbot.scheduler import AnyBranchScheduler
2981 from buildbot.process import step, factory
2982 from buildbot.process.factory import s
2984 c['sources'] = [PBChangeSource()]
2985 s1 = AnyBranchScheduler('main',
2986                         ['trunk', 'features/newthing', 'features/otherthing'],
2987                         10*60, ['test-i386', 'test-ppc'])
2988 c['schedulers'] = [s1]
2989 source = s(step.SVN, mode='update',
2990            baseURL='svn://svn.example.org/MyProject/',
2991            defaultBranch='trunk')
2992 f = factory.BuildFactory([source,
2993                           s(step.Compile, command="make all"),
2994                           s(step.Test, command="make test")])
2995 c['builders'] = [
2996   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
2997                        'factory':f @},
2998   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
2999                       'factory':f @},
3001 @end example
3003 In this example, when a change arrives with a @code{branch} attribute
3004 of ``trunk'', the resulting build will have an SVN step that
3005 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
3006 ``trunk'' (the branch name) to get the correct svn command. If the
3007 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
3008 will concatenate ``svn://svn.example.org/MyProject/'' with
3009 ``features/newthing'' to get the svnurl for checkout.
3011 @node Darcs, Mercurial, SVN, Source Checkout
3012 @subsubsection Darcs
3014 @cindex Darcs Checkout
3016 The @code{Darcs} build step performs a
3017 @uref{http://abridgegame.org/darcs/, Darcs} checkout or update.
3019 Like @xref{SVN}, this step can either be configured to always check
3020 out a specific tree, or set up to pull from a particular branch that
3021 gets specified separately for each build. Also like SVN, the
3022 repository URL given to Darcs is created by concatenating a
3023 @code{baseURL} with the branch name, and if no particular branch is
3024 requested, it uses a @code{defaultBranch}. The only difference in
3025 usage is that each potential Darcs repository URL must point to a
3026 fully-fledged repository, whereas SVN URLs usually point to sub-trees
3027 of the main Subversion repository. In other words, doing an SVN
3028 checkout of @code{baseURL} is legal, but silly, since you'd probably
3029 wind up with a copy of every single branch in the whole repository.
3030 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
3031 the parent directory of a collection of Darcs repositories is not
3032 itself a valid repository.
3034 The Darcs step takes the following arguments:
3036 @table @code
3037 @item repourl
3038 (required unless @code{baseURL} is provided): the URL at which the
3039 Darcs source repository is available.
3041 @item baseURL
3042 (required unless @code{repourl} is provided): the base repository URL,
3043 to which a branch name will be appended. It should probably end in a
3044 slash.
3046 @item defaultBranch
3047 (allowed if and only if @code{baseURL} is provided): this specifies
3048 the name of the branch to use when a Build does not provide one of its
3049 own. This will be appended to @code{baseURL} to create the string that
3050 will be passed to the @code{darcs get} command.
3051 @end table
3053 @node Mercurial, Arch, Darcs, Source Checkout
3054 @subsubsection Mercurial
3056 @cindex Mercurial Checkout
3058 The @code{Mercurial} build step performs a
3059 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
3060 or update.
3062 Branches are handled just like @xref{Darcs}.
3064 The Mercurial step takes the following arguments:
3066 @table @code
3067 @item repourl
3068 (required unless @code{baseURL} is provided): the URL at which the
3069 Mercurial source repository is available.
3071 @item baseURL
3072 (required unless @code{repourl} is provided): the base repository URL,
3073 to which a branch name will be appended. It should probably end in a
3074 slash.
3076 @item defaultBranch
3077 (allowed if and only if @code{baseURL} is provided): this specifies
3078 the name of the branch to use when a Build does not provide one of its
3079 own. This will be appended to @code{baseURL} to create the string that
3080 will be passed to the @code{hg clone} command.
3081 @end table
3084 @node Arch, Bazaar, Mercurial, Source Checkout
3085 @subsubsection Arch
3087 @cindex Arch Checkout
3089 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
3090 Arch} checkout or update using the @code{tla} client. It takes the
3091 following arguments:
3093 @table @code
3094 @item url
3095 (required): this specifies the URL at which the Arch source archive is
3096 available.
3098 @item version
3099 (required): this specifies which ``development line'' (like a branch)
3100 should be used. This provides the default branch name, but individual
3101 builds may specify a different one.
3103 @item archive
3104 (optional): Each repository knows its own archive name. If this
3105 parameter is provided, it must match the repository's archive name.
3106 The parameter is accepted for compatibility with the @code{Bazaar}
3107 step, below.
3109 @end table
3111 @node Bazaar, P4, Arch, Source Checkout
3112 @subsubsection Bazaar
3114 @cindex Bazaar Checkout
3116 @code{Bazaar} is an alternate implementation of the Arch VC system,
3117 which uses a client named @code{baz}. The checkout semantics are just
3118 different enough from @code{tla} that there is a separate BuildStep for
3121 It takes exactly the same arguments as @code{Arch}, except that the
3122 @code{archive=} parameter is required. (baz does not emit the archive
3123 name when you do @code{baz register-archive}, so we must provide it
3124 ourselves).
3127 @node P4,  , Bazaar, Source Checkout
3128 @subsubsection P4
3130 @cindex Perforce Update
3132 The @code{P4} build step creates a @uref{http://www.perforce.com/,
3133 Perforce} client specification and performs an update.
3135 @table @code
3136 @item p4base
3137 A view into the Perforce depot without branch name or trailing "...".
3138 Typically "//depot/proj/".
3139 @item defaultBranch
3140 A branch name to append on build requests if none is specified.
3141 Typically "trunk".
3142 @item p4port
3143 (optional): the host:port string describing how to get to the P4 Depot
3144 (repository), used as the -p argument for all p4 commands.
3145 @item p4user
3146 (optional): the Perforce user, used as the -u argument to all p4
3147 commands.
3148 @item p4passwd
3149 (optional): the Perforce password, used as the -p argument to all p4
3150 commands.
3151 @item p4extra_views
3152 (optional): a list of (depotpath, clientpath) tuples containing extra
3153 views to be mapped into the client specification. Both will have
3154 "/..." appended automatically. The client name and source directory
3155 will be prepended to the client path.
3156 @item p4client
3157 (optional): The name of the client to use. In mode='copy' and
3158 mode='update', it's particularly important that a unique name is used
3159 for each checkout directory to avoid incorrect synchronization. For
3160 this reason, Python percent substitution will be performed on this value
3161 to replace %(slave)s with the slave name and %(builder)s with the
3162 builder name. The default is "buildbot_%(slave)s_%(build)s".
3163 @end table
3165 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
3166 @subsection ShellCommand
3168 This is a useful base class for just about everything you might want
3169 to do during a build (except for the initial source checkout). It runs
3170 a single command in a child shell on the buildslave. All stdout/stderr
3171 is recorded into a LogFile. The step finishes with a status of FAILURE
3172 if the command's exit code is non-zero, otherwise it has a status of
3173 SUCCESS.
3175 The preferred way to specify the command is with a list of argv strings,
3176 since this allows for spaces in filenames and avoids doing any fragile
3177 shell-escaping. You can also specify the command with a single string, in
3178 which case the string is given to '/bin/sh -c COMMAND' for parsing.
3180 All ShellCommands are run by default in the ``workdir'', which
3181 defaults to the ``@file{build}'' subdirectory of the slave builder's
3182 base directory. The absolute path of the workdir will thus be the
3183 slave's basedir (set as an option to @code{buildbot slave},
3184 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
3185 builder's @code{c['builddir']} key in master.cfg) plus the workdir
3186 itself (a class-level attribute of the BuildFactory, defaults to
3187 ``@file{build}'').
3189 @code{ShellCommand} arguments:
3191 @table @code
3192 @item command
3193 a list of strings (preferred) or single string (discouraged) which
3194 specifies the command to be run
3196 @item env
3197 a dictionary of environment strings which will be added to the child
3198 command's environment.
3200 @item want_stdout
3201 if False, stdout from the child process is discarded rather than being
3202 sent to the buildmaster for inclusion in the step's LogFile.
3204 @item want_stderr
3205 like @code{want_stdout} but for stderr. Note that commands run through
3206 a PTY do not have separate stdout/stderr streams: both are merged into
3207 stdout.
3209 @item logfiles
3210 Sometimes commands will log interesting data to a local file, rather
3211 than emitting everything to stdout or stderr. For example, Twisted's
3212 ``trial'' command (which runs unit tests) only presents summary
3213 information to stdout, and puts the rest into a file named
3214 @file{_trial_temp/test.log}. It is often useful to watch these files
3215 as the command runs, rather than using @command{/bin/cat} to dump
3216 their contents afterwards.
3218 The @code{logfiles=} argument allows you to collect data from these
3219 secondary logfiles in near-real-time, as the step is running. It
3220 accepts a dictionary which maps from a local Log name (which is how
3221 the log data is presented in the build results) to a remote filename
3222 (interpreted relative to the build's working directory). Each named
3223 file will be polled on a regular basis (every couple of seconds) as
3224 the build runs, and any new text will be sent over to the buildmaster.
3226 @example
3227 s(ShellCommand, command=["make", "test"],
3228   logfiles=@{"triallog": "_trial_temp/test.log"@})
3229 @end example
3232 @item timeout
3233 if the command fails to produce any output for this many seconds, it
3234 is assumed to be locked up and will be killed.
3236 @item description
3237 This will be used to describe the command (on the Waterfall display)
3238 while the command is still running. It should be a single
3239 imperfect-tense verb, like ``compiling'' or ``testing''.
3241 @item descriptionDone
3242 This will be used to describe the command once it has finished. A
3243 simple noun like ``compile'' or ``tests'' should be used.
3245 If neither @code{description} nor @code{descriptionDone} are set, the
3246 actual command arguments will be used to construct the description.
3247 This may be a bit too wide to fit comfortably on the Waterfall
3248 display.
3250 @end table
3252 @node Simple ShellCommand Subclasses, Writing New BuildSteps, ShellCommand, Build Steps
3253 @subsection Simple ShellCommand Subclasses
3255 Several subclasses of ShellCommand are provided as starting points for
3256 common build steps. These are all very simple: they just override a few
3257 parameters so you don't have to specify them yourself, making the master.cfg
3258 file less verbose.
3260 @menu
3261 * Configure::                   
3262 * Compile::                     
3263 * Test::                        
3264 * Build Properties::            
3265 @end menu
3267 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
3268 @subsubsection Configure
3270 This is intended to handle the @code{./configure} step from
3271 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
3272 MakeMaker.pm-style modules. The default command is @code{./configure}
3273 but you can change this by providing a @code{command=} parameter.
3275 @node Compile, Test, Configure, Simple ShellCommand Subclasses
3276 @subsubsection Compile
3278 This is meant to handle compiling or building a project written in C. The
3279 default command is @code{make all}. When the compile is finished, the
3280 log file is scanned for GCC error/warning messages and a summary log is
3281 created with any problems that were seen (TODO: the summary is not yet
3282 created).
3284 @node Test, Build Properties, Compile, Simple ShellCommand Subclasses
3285 @subsubsection Test
3287 This is meant to handle unit tests. The default command is @code{make
3288 test}, and the @code{warnOnFailure} flag is set.
3292 @node Build Properties,  , Test, Simple ShellCommand Subclasses
3293 @subsubsection Build Properties
3295 @cindex build properties
3297 Each build has a set of ``Build Properties'', which can be used by its
3298 BuildStep to modify their actions. For example, the SVN revision
3299 number of the source code being built is available as a build
3300 property, and a ShellCommand step could incorporate this number into a
3301 command which create a numbered release tarball.
3303 Some build properties are set when the build starts, such as the
3304 SourceStamp information. Other properties can be set by BuildSteps as
3305 they run, for example the various Source steps will set the
3306 @code{got_revision} property to the source revision that was actually
3307 checked out (which can be useful when the SourceStamp in use merely
3308 requested the ``latest revision'': @code{got_revision} will tell you
3309 what was actually built).
3311 In custom BuildSteps, you can get and set the build properties with
3312 the @code{getProperty}/@code{setProperty} methods. Each takes a string
3313 for the name of the property, and returns or accepts an
3314 arbitrary@footnote{Build properties are serialized along with the
3315 build results, so they must be serializable. For this reason, the
3316 value of any build property should be simple inert data: strings,
3317 numbers, lists, tuples, and dictionaries. They should not contain
3318 class instances.} object. For example:
3320 @example
3321 class MakeTarball(step.ShellCommand):
3322     def start(self):
3323         self.setCommand(["tar", "czf",
3324                          "build-%s.tar.gz" % self.getProperty("revision"),
3325                          "source"])
3326         step.ShellCommand.start(self)
3327 @end example
3329 @cindex WithProperties
3331 You can use build properties in ShellCommands by using the
3332 @code{WithProperties} wrapper when setting the arguments of the
3333 ShellCommand. This interpolates the named build properties into the
3334 generated shell command.
3336 @example
3337 from buildbot.process.step import ShellCommand, WithProperties
3339 s(ShellCommand,
3340   command=["tar", "czf",
3341            WithProperties("build-%s.tar.gz", "revision"),
3342            "source"],
3344 @end example
3346 If this BuildStep were used in a tree obtained from Subversion, it
3347 would create a tarball with a name like @file{build-1234.tar.gz}.
3349 The @code{WithProperties} function does @code{printf}-style string
3350 interpolation, using strings obtained by calling
3351 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
3352 @code{%d}, etc), you must have exactly one additional argument to
3353 indicate which build property you want to insert.
3356 You can also use python dictionary-style string interpolation by using
3357 the @code{%(propname)s} syntax. In this form, the property name goes
3358 in the parentheses, and WithProperties takes @emph{no} additional
3359 arguments:
3361 @example
3362 s(ShellCommand,
3363   command=["tar", "czf",
3364            WithProperties("build-%(revision)s.tar.gz"),
3365            "source"],
3367 @end example
3369 Don't forget the extra ``s'' after the closing parenthesis! This is
3370 the cause of many confusing errors.
3372 Note that, like python, you can either do positional-argument
3373 interpolation @emph{or} keyword-argument interpolation, not both. Thus
3374 you cannot use a string like
3375 @code{WithProperties("foo-%(revision)s-%s", "branch")}.
3377 At the moment, the only way to set build properties is by writing a
3378 custom BuildStep.
3380 @heading Common Build Properties
3382 The following build properties are set when the build is started, and
3383 are available to all steps.
3385 @table @code
3386 @item branch
3388 This comes from the build's SourceStamp, and describes which branch is
3389 being checked out. This will be @code{None} (which interpolates into
3390 @code{WithProperties} as an empty string) if the build is on the
3391 default branch, which is generally the trunk. Otherwise it will be a
3392 string like ``branches/beta1.4''. The exact syntax depends upon the VC
3393 system being used.
3395 @item revision
3397 This also comes from the SourceStamp, and is the revision of the
3398 source code tree that was requested from the VC system. When a build
3399 is requested of a specific revision (as is generally the case when the
3400 build is triggered by Changes), this will contain the revision
3401 specification. The syntax depends upon the VC system in use: for SVN
3402 it is an integer, for Mercurial it is a short string, for Darcs it is
3403 a rather large string, etc.
3405 If the ``force build'' button was pressed, the revision will be
3406 @code{None}, which means to use the most recent revision available.
3407 This is a ``trunk build''. This will be interpolated as an empty
3408 string.
3410 @item got_revision
3412 This is set when a Source step checks out the source tree, and
3413 provides the revision that was actually obtained from the VC system.
3414 In general this should be the same as @code{revision}, except for
3415 trunk builds, where @code{got_revision} indicates what revision was
3416 current when the checkout was performed. This can be used to rebuild
3417 the same source code later.
3419 Note that for some VC systems (Darcs in particular), the revision is a
3420 large string containing newlines, and is not suitable for
3421 interpolation into a filename.
3423 @item buildername
3425 This is a string that indicates which Builder the build was a part of.
3426 The combination of buildername and buildnumber uniquely identify a
3427 build.
3429 @item buildnumber
3431 Each build gets a number, scoped to the Builder (so the first build
3432 performed on any given Builder will have a build number of 0). This
3433 integer property contains the build's number.
3435 @item slavename
3437 This is a string which identifies which buildslave the build is
3438 running on.
3440 @end table
3443 @node Writing New BuildSteps,  , Simple ShellCommand Subclasses, Build Steps
3444 @subsection Writing New BuildSteps
3446 While it is a good idea to keep your build process self-contained in
3447 the source code tree, sometimes it is convenient to put more
3448 intelligence into your Buildbot configuration. One was to do this is
3449 to write a custom BuildStep. Once written, this Step can be used in
3450 the @file{master.cfg} file.
3452 The best reason for writing a custom BuildStep is to better parse the
3453 results of the command being run. For example, a BuildStep that knows
3454 about JUnit could look at the logfiles to determine which tests had
3455 been run, how many passed and how many failed, and then report more
3456 detailed information than a simple @code{rc==0} -based ``good/bad''
3457 decision.
3459 TODO: add more description of BuildSteps.
3461 @menu
3462 * Adding LogObservers::         
3463 @end menu
3465 @node Adding LogObservers,  , Writing New BuildSteps, Writing New BuildSteps
3466 @subsubsection Adding LogObservers
3468 @cindex LogObserver
3469 @cindex LogLineObserver
3471 Most shell commands emit messages to stdout or stderr as they operate,
3472 especially if you ask them nicely with a @code{--verbose} flag of some
3473 sort. They may also write text to a log file while they run. Your
3474 BuildStep can watch this output as it arrives, to keep track of how
3475 much progress the command has made. You can get a better measure of
3476 progress by counting the number of source files compiled or test cases
3477 run than by merely tracking the number of bytes that have been written
3478 to stdout. This improves the accuracy and the smoothness of the ETA
3479 display.
3481 To accomplish this, you will need to attach a @code{LogObserver} to
3482 one of the log channels, most commonly to the ``stdio'' channel but
3483 perhaps to another one which tracks a log file. This observer is given
3484 all text as it is emitted from the command, and has the opportunity to
3485 parse that output incrementally. Once the observer has decided that
3486 some event has occurred (like a source file being compiled), it can
3487 use the @code{setProgress} method to tell the BuildStep about the
3488 progress that this event represents.
3490 There are a number of pre-built @code{LogObserver} classes that you
3491 can choose from, and of course you can subclass them to add further
3492 customization. The @code{LogLineObserver} class handles the grunt work
3493 of buffering and scanning for end-of-line delimiters, allowing your
3494 parser to operate on complete stdout/stderr lines.
3496 For example, let's take a look at the @code{TrialTestCaseCounter},
3497 which is used by the Trial step to count test cases as they are run.
3498 As Trial executes, it emits lines like the following:
3500 @example
3501 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
3502 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
3503 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
3504 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
3505 @end example
3507 When the tests are finished, trial emits a long line of ``======'' and
3508 then some lines which summarize the tests that failed. We want to
3509 avoid parsing these trailing lines, because their format is less
3510 well-defined than the ``[OK]'' lines.
3512 The parser class looks like this:
3514 @example
3515 class TrialTestCaseCounter(step.LogLineObserver):
3516     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
3517     numTests = 0
3518     finished = False
3520     def outLineReceived(self, line):
3521         if self.finished:
3522             return
3523         if line.startswith("=" * 40):
3524             self.finished = True
3525             return
3527         m = self._line_re.search(line.strip())
3528         if m:
3529             testname, result = m.groups()
3530             self.numTests += 1
3531             self.step.setProgress('tests', self.numTests)
3532 @end example
3534 This parser only pays attention to stdout, since that's where trial
3535 writes the progress lines. It has a mode flag named @code{finished} to
3536 ignore everything after the ``===='' marker, and a scary-looking
3537 regular expression to match each line while hopefully ignoring other
3538 messages that might get displayed as the test runs.
3540 Each time it identifies a test has been completed, it increments its
3541 counter and delivers the new progress value to the step with
3542 @code{self.step.setProgress}. This class is specifically measuring
3543 progress along the ``tests'' metric, in units of test cases (as
3544 opposed to other kinds of progress like the ``output'' metric, which
3545 measures in units of bytes). The Progress-tracking code uses each
3546 progress metric separately to come up with an overall completion
3547 percentage and an ETA value.
3549 To connect this parser into the @code{Trial} BuildStep,
3550 @code{Trial.__init__} ends with the following clause:
3552 @example
3553         # this counter will feed Progress along the 'test cases' metric
3554         counter = TrialTestCaseCounter()
3555         self.addLogObserver('stdio', counter)
3556 @end example
3558 This creates a TrialTestCaseCounter and tells the step to attach it to
3559 the ``stdio'' log. The observer is automatically given a reference to
3560 the step in its @code{.step} attribute.
3563 @node Interlocks, Build Factories, Build Steps, Build Process
3564 @section Interlocks
3566 @cindex locks
3568 For various reasons, you may want to prevent certain Steps (or perhaps
3569 entire Builds) from running simultaneously. Limited CPU speed or
3570 network bandwidth to the VC server, problems with simultaneous access
3571 to a database server used by unit tests, or multiple Builds which
3572 access shared state may all require some kind of interlock to prevent
3573 corruption, confusion, or resource overload.
3575 @code{Locks} are the mechanism used to express these kinds of
3576 constraints on when Builds or Steps can be run. There are two kinds of
3577 @code{Locks}, each with their own scope: @code{SlaveLock}s are scoped
3578 to a single buildslave, while @code{MasterLock} instances are scoped
3579 to the buildbot as a whole. Each @code{Lock} is created with a unique
3580 name.
3582 To use a lock, simply include it in the @code{locks=} argument of the
3583 @code{BuildStep} object that should obtain the lock before it runs.
3584 This argument accepts a list of @code{Lock} objects: the Step will
3585 acquire all of them before it runs.
3587 To claim a lock for the whole Build, add a @code{'locks'} key to the
3588 builder specification dictionary with the same list of @code{Lock}
3589 objects. (This is the dictionary that has the @code{'name'},
3590 @code{'slavename'}, @code{'builddir'}, and @code{'factory'} keys). The
3591 @code{Build} object also accepts a @code{locks=} argument, but unless
3592 you are writing your own @code{BuildFactory} subclass then it will be
3593 easier to set the locks in the builder dictionary.
3595 Note that there are no partial-acquire or partial-release semantics:
3596 this prevents deadlocks caused by two Steps each waiting for a lock
3597 held by the other@footnote{Also note that a clever buildmaster admin
3598 could still create the opportunity for deadlock: Build A obtains Lock
3599 1, inside which Step A.two tries to acquire Lock 2 at the Step level.
3600 Meanwhile Build B obtains Lock 2, and has a Step B.two which wants to
3601 acquire Lock 1 at the Step level. Don't Do That.}. This also means
3602 that waiting to acquire a @code{Lock} can take an arbitrarily long
3603 time: if the buildmaster is very busy, a Step or Build which requires
3604 only one @code{Lock} may starve another that is waiting for that
3605 @code{Lock} plus some others.
3608 In the following example, we run the same build on three different
3609 platforms. The unit-test steps of these builds all use a common
3610 database server, and would interfere with each other if allowed to run
3611 simultaneously. The @code{Lock} prevents more than one of these builds
3612 from happening at the same time.
3614 @example
3615 from buildbot import locks
3616 from buildbot.process import s, step, factory
3618 db_lock = locks.MasterLock("database")
3619 steps = [s(step.SVN, svnurl="http://example.org/svn/Trunk"),
3620          s(step.ShellCommand, command="make all"),
3621          s(step.ShellCommand, command="make test", locks=[db_lock]),
3622         ]
3623 f = factory.BuildFactory(steps)
3624 b1 = @{'name': 'full1', 'slavename': 'bot-1', builddir='f1', 'factory': f@}
3625 b2 = @{'name': 'full2', 'slavename': 'bot-2', builddir='f2', 'factory': f@}
3626 b3 = @{'name': 'full3', 'slavename': 'bot-3', builddir='f3', 'factory': f@}
3627 c['builders'] = [b1, b2, b3]
3628 @end example
3630 In the next example, we have one buildslave hosting three separate
3631 Builders (each running tests against a different version of Python).
3632 The machine which hosts this buildslave is not particularly fast, so
3633 we want to prevent the builds from all happening at the same time. We
3634 use a @code{SlaveLock} because the builds happening on the slow slave
3635 do not affect builds running on other slaves, and we use the lock on
3636 the build as a whole because the slave is so slow that even multiple
3637 SVN checkouts would be taxing.
3639 @example
3640 from buildbot import locks
3641 from buildbot.process import s, step, factory
3643 slow_lock = locks.SlaveLock("cpu")
3644 source = s(step.SVN, svnurl="http://example.org/svn/Trunk")
3645 f22 = factory.Trial(source, trialpython=["python2.2"])
3646 f23 = factory.Trial(source, trialpython=["python2.3"])
3647 f24 = factory.Trial(source, trialpython=["python2.4"])
3648 b1 = @{'name': 'p22', 'slavename': 'bot-1', builddir='p22', 'factory': f22,
3649                      'locks': [slow_lock] @}
3650 b2 = @{'name': 'p23', 'slavename': 'bot-1', builddir='p23', 'factory': f23,
3651                      'locks': [slow_lock] @}
3652 b3 = @{'name': 'p24', 'slavename': 'bot-1', builddir='p24', 'factory': f24,
3653                      'locks': [slow_lock] @}
3654 c['builders'] = [b1, b2, b3]
3655 @end example
3657 In the last example, we use two Locks at the same time. In this case,
3658 we're concerned about both of the previous constraints, but we'll say
3659 that only the tests are computationally intensive, and that they have
3660 been split into those which use the database and those which do not.
3661 In addition, two of the Builds run on a fast machine which does not
3662 need to worry about the cpu lock, but which still must be prevented
3663 from simultaneous database access.
3665 @example
3666 from buildbot import locks
3667 from buildbot.process import s, step, factory
3669 db_lock = locks.MasterLock("database")
3670 cpu_lock = locks.SlaveLock("cpu")
3671 slow_steps = [s(step.SVN, svnurl="http://example.org/svn/Trunk"),
3672               s(step.ShellCommand, command="make all", locks=[cpu_lock]),
3673               s(step.ShellCommand, command="make test", locks=[cpu_lock]),
3674               s(step.ShellCommand, command="make db-test",
3675                                    locks=[db_lock, cpu_lock]),
3676              ]
3677 slow_f = factory.BuildFactory(slow_steps)
3678 fast_steps = [s(step.SVN, svnurl="http://example.org/svn/Trunk"),
3679               s(step.ShellCommand, command="make all", locks=[]),
3680               s(step.ShellCommand, command="make test", locks=[]),
3681               s(step.ShellCommand, command="make db-test",
3682                                    locks=[db_lock]),
3683              ]
3684 fast_factory = factory.BuildFactory(fast_steps)
3685 b1 = @{'name': 'full1', 'slavename': 'bot-slow', builddir='full1',
3686                        'factory': slow_factory@}
3687 b2 = @{'name': 'full2', 'slavename': 'bot-slow', builddir='full2',
3688                        'factory': slow_factory@}
3689 b3 = @{'name': 'full3', 'slavename': 'bot-fast', builddir='full3',
3690                        'factory': fast_factory@}
3691 b4 = @{'name': 'full4', 'slavename': 'bot-fast', builddir='full4',
3692                        'factory': fast_factory@}
3693 c['builders'] = [b1, b2, b3, b4]
3694 @end example
3696 As a final note, remember that a unit test system which breaks when
3697 multiple people run it at the same time is fragile and should be
3698 fixed. Asking your human developers to serialize themselves when
3699 running unit tests will just discourage them from running the unit
3700 tests at all. Find a way to fix this: change the database tests to
3701 create a new (uniquely-named) user or table for each test run, don't
3702 use fixed listening TCP ports for network tests (instead listen on
3703 port 0 to let the kernel choose a port for you and then query the
3704 socket to find out what port was allocated). @code{MasterLock}s can be
3705 used to accomodate broken test systems like this, but are really
3706 intended for other purposes: build processes that store or retrieve
3707 products in shared directories, or which do things that human
3708 developers would not (or which might slow down or break in ways that
3709 require human attention to deal with).
3711 @code{SlaveLocks}s can be used to keep automated performance tests
3712 from interfering with each other, when there are multiple Builders all
3713 using the same buildslave. But they can't prevent other users from
3714 running CPU-intensive jobs on that host while the tests are running.
3716 @node Build Factories,  , Interlocks, Build Process
3717 @section Build Factories
3720 Each Builder is equipped with a ``build factory'', which is
3721 responsible for producing the actual @code{Build} objects that perform
3722 each build. This factory is created in the configuration file, and
3723 attached to a Builder through the @code{factory} element of its
3724 dictionary.
3726 The standard @code{BuildFactory} object creates @code{Build} objects
3727 by default. These Builds will each execute a collection of BuildSteps
3728 in a fixed sequence. Each step can affect the results of the build,
3729 but in general there is little intelligence to tie the different steps
3730 together. You can create subclasses of @code{Build} to implement more
3731 sophisticated build processes, and then use a subclass of
3732 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
3733 create instances of your new Build subclass.
3736 @menu
3737 * BuildStep Objects::           
3738 * BuildFactory::                
3739 * Process-Specific build factories::  
3740 @end menu
3742 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
3743 @subsection BuildStep Objects
3745 The steps used by these builds are all subclasses of @code{BuildStep}.
3746 The standard ones provided with Buildbot are documented later,
3747 @xref{Build Steps}. You can also write your own subclasses to use in
3748 builds.
3750 The basic behavior for a @code{BuildStep} is to:
3752 @itemize @bullet
3753 @item
3754 run for a while, then stop
3755 @item
3756 possibly invoke some RemoteCommands on the attached build slave
3757 @item
3758 possibly produce a set of log files
3759 @item
3760 finish with a status described by one of four values defined in
3761 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
3762 @item
3763 provide a list of short strings to describe the step
3764 @item
3765 define a color (generally green, orange, or red) with which the
3766 step should be displayed
3767 @end itemize
3770 More sophisticated steps may produce additional information and
3771 provide it to later build steps, or store it in the factory to provide
3772 to later builds.
3775 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
3776 @subsection BuildFactory
3778 The default @code{BuildFactory}, provided in the
3779 @code{buildbot.process.factory} module, is constructed with a list of
3780 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
3781 tuples for each. When asked to create a Build, it loads the list of
3782 steps into the new Build object. When the Build is actually started,
3783 these step specifications are used to create the actual set of
3784 BuildSteps, which are then executed one at a time. For example, a
3785 build which consists of a CVS checkout followed by a @code{make build}
3786 would be constructed as follows:
3788 @example
3789 from buildbot.process import step, factory
3790 from buildbot.factory import s
3791 # s is a convenience function, defined with:
3792 # def s(steptype, **kwargs): return (steptype, kwargs)
3794 f = factory.BuildFactory([s(step.CVS,
3795                             cvsroot=CVSROOT, cvsmodule="project",
3796                             mode="update"),
3797                           s(step.Compile, command=["make", "build"])])
3798 @end example
3800 Each step can affect the build process in the following ways:
3802 @itemize @bullet
3803 @item
3804 If the step's @code{haltOnFailure} attribute is True, then a failure
3805 in the step (i.e. if it completes with a result of FAILURE) will cause
3806 the whole build to be terminated immediately: no further steps will be
3807 executed. This is useful for setup steps upon which the rest of the
3808 build depends: if the CVS checkout or @code{./configure} process
3809 fails, there is no point in trying to compile or test the resulting
3810 tree.
3812 @item
3813 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
3814 then a result of FAILURE or WARNINGS will mark the build as a whole as
3815 FAILED. However, the remaining steps will still be executed. This is
3816 appropriate for things like multiple testing steps: a failure in any
3817 one of them will indicate that the build has failed, however it is
3818 still useful to run them all to completion.
3820 @item
3821 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
3822 is set, then a result of FAILURE or WARNINGS will mark the build as
3823 having WARNINGS, and the remaining steps will still be executed. This
3824 may be appropriate for certain kinds of optional build or test steps.
3825 For example, a failure experienced while building documentation files
3826 should be made visible with a WARNINGS result but not be serious
3827 enough to warrant marking the whole build with a FAILURE.
3829 @end itemize
3831 In addition, each Step produces its own results, may create logfiles,
3832 etc. However only the flags described above have any effect on the
3833 build as a whole.
3835 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
3836 reasonably appropriate flags set on them already. For example, without
3837 a source tree there is no point in continuing the build, so the
3838 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
3839 in @file{buildbot/process/step.py} to see how the other Steps are
3840 marked.
3842 Each Step is created with an additional @code{workdir} argument that
3843 indicates where its actions should take place. This is specified as a
3844 subdirectory of the slave builder's base directory, with a default
3845 value of @code{build}. This is only implemented as a step argument (as
3846 opposed to simply being a part of the base directory) because the
3847 CVS/SVN steps need to perform their checkouts from the parent
3848 directory.
3850 @menu
3851 * BuildFactory Attributes::     
3852 * Quick builds::                
3853 @end menu
3855 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
3856 @subsubsection BuildFactory Attributes
3858 Some attributes from the BuildFactory are copied into each Build.
3860 @cindex treeStableTimer
3862 @table @code
3863 @item useProgress
3864 (defaults to True): if True, the buildmaster keeps track of how long
3865 each step takes, so it can provide estimates of how long future builds
3866 will take. If builds are not expected to take a consistent amount of
3867 time (such as incremental builds in which a random set of files are
3868 recompiled or tested each time), this should be set to False to
3869 inhibit progress-tracking.
3871 @end table
3874 @node Quick builds,  , BuildFactory Attributes, BuildFactory
3875 @subsubsection Quick builds
3877 The difference between a ``full build'' and a ``quick build'' is that
3878 quick builds are generally done incrementally, starting with the tree
3879 where the previous build was performed. That simply means that the
3880 source-checkout step should be given a @code{mode='update'} flag, to
3881 do the source update in-place.
3883 In addition to that, the @code{useProgress} flag should be set to
3884 False. Incremental builds will (or at least the ought to) compile as
3885 few files as necessary, so they will take an unpredictable amount of
3886 time to run. Therefore it would be misleading to claim to predict how
3887 long the build will take.
3890 @node Process-Specific build factories,  , BuildFactory, Build Factories
3891 @subsection Process-Specific build factories
3893 Many projects use one of a few popular build frameworks to simplify
3894 the creation and maintenance of Makefiles or other compilation
3895 structures. Buildbot provides several pre-configured BuildFactory
3896 subclasses which let you build these projects with a minimum of fuss.
3898 @menu
3899 * GNUAutoconf::                 
3900 * CPAN::                        
3901 * Python distutils::            
3902 * Python/Twisted/trial projects::  
3903 @end menu
3905 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
3906 @subsubsection GNUAutoconf
3908 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
3909 software portability tool, intended to make it possible to write
3910 programs in C (and other languages) which will run on a variety of
3911 UNIX-like systems. Most GNU software is built using autoconf. It is
3912 frequently used in combination with GNU automake. These tools both
3913 encourage a build process which usually looks like this:
3915 @example
3916 % CONFIG_ENV=foo ./configure --with-flags
3917 % make all
3918 % make check
3919 # make install
3920 @end example
3922 (except of course the Buildbot always skips the @code{make install}
3923 part).
3925 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
3926 designed to build projects which use GNU autoconf and/or automake. The
3927 configuration environment variables, the configure flags, and command
3928 lines used for the compile and test are all configurable, in general
3929 the default values will be suitable.
3931 Example:
3933 @example
3934 # use the s() convenience function defined earlier
3935 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
3936                         flags=["--disable-nls"])
3937 @end example
3939 Required Arguments:
3941 @table @code
3942 @item source
3943 This argument must be a step specification tuple that provides a
3944 BuildStep to generate the source tree.
3945 @end table
3947 Optional Arguments:
3949 @table @code
3950 @item configure
3951 The command used to configure the tree. Defaults to
3952 @code{./configure}. Accepts either a string or a list of shell argv
3953 elements.
3955 @item configureEnv
3956 The environment used for the initial configuration step. This accepts
3957 a dictionary which will be merged into the buildslave's normal
3958 environment. This is commonly used to provide things like
3959 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
3960 Defaults to an empty dictionary.
3962 @item configureFlags
3963 A list of flags to be appended to the argument list of the configure
3964 command. This is commonly used to enable or disable specific features
3965 of the autoconf-controlled package, like @code{["--without-x"]} to
3966 disable windowing support. Defaults to an empty list.
3968 @item compile
3969 this is a shell command or list of argv values which is used to
3970 actually compile the tree. It defaults to @code{make all}. If set to
3971 None, the compile step is skipped.
3973 @item test
3974 this is a shell command or list of argv values which is used to run
3975 the tree's self-tests. It defaults to @code{make check}. If set to
3976 None, the test step is skipped.
3978 @end table
3981 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
3982 @subsubsection CPAN
3984 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
3985 archive use the @code{MakeMaker} module to provide configuration,
3986 build, and test services. The standard build routine for these modules
3987 looks like:
3989 @example
3990 % perl Makefile.PL
3991 % make
3992 % make test
3993 # make install
3994 @end example
3996 (except again Buildbot skips the install step)
3998 Buildbot provides a @code{CPAN} factory to compile and test these
3999 projects.
4002 Arguments:
4003 @table @code
4004 @item source
4005 (required): A step specification tuple, that that used by GNUAutoconf.
4007 @item perl
4008 A string which specifies the @code{perl} executable to use. Defaults
4009 to just @code{perl}.
4011 @end table
4014 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
4015 @subsubsection Python distutils
4017 Most Python modules use the @code{distutils} package to provide
4018 configuration and build services. The standard build process looks
4019 like:
4021 @example
4022 % python ./setup.py build
4023 % python ./setup.py install
4024 @end example
4026 Unfortunately, although Python provides a standard unit-test framework
4027 named @code{unittest}, to the best of my knowledge @code{distutils}
4028 does not provide a standardized target to run such unit tests. (please
4029 let me know if I'm wrong, and I will update this factory).
4031 The @code{Distutils} factory provides support for running the build
4032 part of this process. It accepts the same @code{source=} parameter as
4033 the other build factories.
4036 Arguments:
4037 @table @code
4038 @item source
4039 (required): A step specification tuple, that that used by GNUAutoconf.
4040   
4041 @item python
4042 A string which specifies the @code{python} executable to use. Defaults
4043 to just @code{python}.
4045 @item test
4046 Provides a shell command which runs unit tests. This accepts either a
4047 string or a list. The default value is None, which disables the test
4048 step (since there is no common default command to run unit tests in
4049 distutils modules).
4051 @end table
4054 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
4055 @subsubsection Python/Twisted/trial projects
4057 Twisted provides a unit test tool named @code{trial} which provides a
4058 few improvements over Python's built-in @code{unittest} module. Many
4059 python projects which use Twisted for their networking or application
4060 services also use trial for their unit tests. These modules are
4061 usually built and tested with something like the following:
4063 @example
4064 % python ./setup.py build
4065 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
4066 % python ./setup.py install
4067 @end example
4069 Unfortunately, the @file{build/lib} directory into which the
4070 built/copied .py files are placed is actually architecture-dependent,
4071 and I do not yet know of a simple way to calculate its value. For many
4072 projects it is sufficient to import their libraries ``in place'' from
4073 the tree's base directory (@code{PYTHONPATH=.}).
4075 In addition, the @var{PROJECTNAME} value where the test files are
4076 located is project-dependent: it is usually just the project's
4077 top-level library directory, as common practice suggests the unit test
4078 files are put in the @code{test} sub-module. This value cannot be
4079 guessed, the @code{Trial} class must be told where to find the test
4080 files.
4082 The @code{Trial} class provides support for building and testing
4083 projects which use distutils and trial. If the test module name is
4084 specified, trial will be invoked. The library path used for testing
4085 can also be set.
4087 One advantage of trial is that the Buildbot happens to know how to
4088 parse trial output, letting it identify which tests passed and which
4089 ones failed. The Buildbot can then provide fine-grained reports about
4090 how many tests have failed, when individual tests fail when they had
4091 been passing previously, etc.
4093 Another feature of trial is that you can give it a series of source
4094 .py files, and it will search them for special @code{test-case-name}
4095 tags that indicate which test cases provide coverage for that file.
4096 Trial can then run just the appropriate tests. This is useful for
4097 quick builds, where you want to only run the test cases that cover the
4098 changed functionality.
4100 Arguments:
4101 @table @code
4102 @item source
4103 (required): A step specification tuple, like that used by GNUAutoconf.
4105 @item buildpython
4106 A list (argv array) of strings which specifies the @code{python}
4107 executable to use when building the package. Defaults to just
4108 @code{['python']}. It may be useful to add flags here, to supress
4109 warnings during compilation of extension modules. This list is
4110 extended with @code{['./setup.py', 'build']} and then executed in a
4111 ShellCommand.
4113 @item testpath
4114 Provides a directory to add to @code{PYTHONPATH} when running the unit
4115 tests, if tests are being run. Defaults to @code{.} to include the
4116 project files in-place. The generated build library is frequently
4117 architecture-dependent, but may simply be @file{build/lib} for
4118 pure-python modules.
4120 @item trialpython
4121 Another list of strings used to build the command that actually runs
4122 trial. This is prepended to the contents of the @code{trial} argument
4123 below. It may be useful to add @code{-W} flags here to supress
4124 warnings that occur while tests are being run. Defaults to an empty
4125 list, meaning @code{trial} will be run without an explicit
4126 interpreter, which is generally what you want if you're using
4127 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
4128 lives in the Twisted source tree.
4130 @item trial
4131 provides the name of the @code{trial} command. It is occasionally
4132 useful to use an alternate executable, such as @code{trial2.2} which
4133 might run the tests under an older version of Python. Defaults to
4134 @code{trial}.
4136 @item tests
4137 Provides a module name or names which contain the unit tests for this
4138 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
4139 list of strings. Defaults to None, indicating that no tests should be
4140 run. You must either set this or @code{useTestCaseNames} to do anyting
4141 useful with the Trial factory.
4143 @item useTestCaseNames
4144 Tells the Step to provide the names of all changed .py files to trial,
4145 so it can look for test-case-name tags and run just the matching test
4146 cases. Suitable for use in quick builds. Defaults to False.
4148 @item randomly
4149 If @code{True}, tells Trial (with the @code{--random=0} argument) to
4150 run the test cases in random order, which sometimes catches subtle
4151 inter-test dependency bugs. Defaults to @code{False}.
4153 @item recurse
4154 If @code{True}, tells Trial (with the @code{--recurse} argument) to
4155 look in all subdirectories for additional test cases. It isn't clear
4156 to me how this works, but it may be useful to deal with the
4157 unknown-PROJECTNAME problem described above, and is currently used in
4158 the Twisted buildbot to accomodate the fact that test cases are now
4159 distributed through multiple twisted.SUBPROJECT.test directories.
4161 @end table  
4163 Unless one of @code{trialModule} or @code{useTestCaseNames}
4164 are set, no tests will be run.
4166 Some quick examples follow. Most of these examples assume that the
4167 target python code (the ``code under test'') can be reached directly
4168 from the root of the target tree, rather than being in a @file{lib/}
4169 subdirectory.
4171 @example
4172 #  Trial(source, tests="toplevel.test") does:
4173 #   python ./setup.py build
4174 #   PYTHONPATH=. trial -to toplevel.test
4176 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
4177 #   python ./setup.py build
4178 #   PYTHONPATH=. trial -to toplevel.test other.test
4180 #  Trial(source, useTestCaseNames=True) does:
4181 #   python ./setup.py build
4182 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
4184 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
4185 #   python2.3 -Wall ./setup.py build
4186 #   PYTHONPATH=. trial -to foo.tests
4188 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
4189 #        tests="foo.tests") does:
4190 #   python2.3 -Wall ./setup.py build
4191 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
4193 # For running trial out of the tree being tested (only useful when the
4194 # tree being built is Twisted itself):
4195 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
4196 #        tests="foo.tests") does:
4197 #   python2.3 -Wall ./setup.py build
4198 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
4199 @end example
4201 If the output directory of @code{./setup.py build} is known, you can
4202 pull the python code from the built location instead of the source
4203 directories. This should be able to handle variations in where the
4204 source comes from, as well as accomodating binary extension modules:
4206 @example
4207 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
4208 # does:
4209 #  python ./setup.py build
4210 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
4211 @end example
4214 @node Status Delivery, Command-line tool, Build Process, Top
4215 @chapter Status Delivery
4217 More details are available in the docstrings for each class, use
4218 @code{pydoc buildbot.status.html.Waterfall} to see them. Most status
4219 delivery objects take a @code{categories=} argument, which can contain
4220 a list of ``category'' names: in this case, it will only show status
4221 for Builders that are in one of the named categories.
4223 (implementor's note: each of these objects should be a
4224 service.MultiService which will be attached to the BuildMaster object
4225 when the configuration is processed. They should use
4226 @code{self.parent.getStatus()} to get access to the top-level IStatus
4227 object, either inside @code{startService} or later. They may call
4228 @code{status.subscribe()} in @code{startService} to receive
4229 notifications of builder events, in which case they must define
4230 @code{builderAdded} and related methods. See the docstrings in
4231 @file{buildbot/interfaces.py} for full details.)
4233 @menu
4234 * HTML Waterfall::              
4235 * IRC Bot::                     
4236 * PBListener::                  
4237 * Writing New Status Plugins::  
4238 @end menu
4240 @node HTML Waterfall, IRC Bot, Status Delivery, Status Delivery
4241 @section HTML Waterfall
4243 @cindex Waterfall
4245 @example
4246 from buildbot.status import html
4247 w = html.Waterfall(http_port=8080)
4248 c['status'].append(w)
4249 @end example
4251 The @code{buildbot.status.html.Waterfall} status target creates an
4252 HTML ``waterfall display'', which shows a time-based chart of events.
4253 This display provides detailed information about all steps of all
4254 recent builds, and provides hyperlinks to look at individual build
4255 logs and source changes. If the @code{http_port} argument is provided,
4256 it provides a strports specification for the port that the web server
4257 should listen on. This can be a simple port number, or a string like
4258 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
4259 loopback interface, and therefore to clients running on the same
4260 host)@footnote{It may even be possible to provide SSL access by using
4261 a specification like
4262 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
4263 completely untested}.
4265 If instead (or in addition) you provide the @code{distrib_port}
4266 argument, a twisted.web distributed server will be started either on a
4267 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
4268 likely on a UNIX socket (if @code{distrib_port} is like
4269 @code{"unix:/path/to/socket"}).
4271 The @code{distrib_port} option means that, on a host with a
4272 suitably-configured twisted-web server, you do not need to consume a
4273 separate TCP port for the buildmaster's status web page. When the web
4274 server is constructed with @code{mktap web --user}, URLs that point to
4275 @code{http://host/~username/} are dispatched to a sub-server that is
4276 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
4277 such a system, it is convenient to create a dedicated @code{buildbot}
4278 user, then set @code{distrib_port} to
4279 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
4280 configuration will make the HTML status page available at
4281 @code{http://host/~buildbot/} . Suitable URL remapping can make it
4282 appear at @code{http://host/buildbot/}, and the right virtual host
4283 setup can even place it at @code{http://buildbot.host/} .
4285 Other arguments:
4287 @table @code
4288 @item allowForce
4289 If set to True (the default), then the web page will provide a ``Force
4290 Build'' button that allows visitors to manually trigger builds. This
4291 is useful for developers to re-run builds that have failed because of
4292 intermittent problems in the test suite, or because of libraries that
4293 were not installed at the time of the previous build. You may not wish
4294 to allow strangers to cause a build to run: in that case, set this to
4295 False to remove these buttons.
4297 @item favicon
4298 If set to a string, this will be interpreted as a filename containing
4299 a ``favicon'': a small image that contains an icon for the web site.
4300 This is returned to browsers that request the @code{favicon.ico} file,
4301 and should point to a .png or .ico image file. The default value uses
4302 the buildbot/buildbot.png image (a small hex nut) contained in the
4303 buildbot distribution. You can set this to None to avoid using a
4304 favicon at all.
4306 @item robots_txt
4307 If set to a string, this will be interpreted as a filename containing
4308 the contents of ``robots.txt''. Many search engine spiders request
4309 this file before indexing the site. Setting it to a file which
4310 contains:
4311 @example
4312 User-agent: *
4313 Disallow: /
4314 @end example
4315 will prevent most search engines from trawling the (voluminous)
4316 generated status pages.
4318 @end table
4321 @node IRC Bot, PBListener, HTML Waterfall, Status Delivery
4322 @section IRC Bot
4324 @cindex IRC
4326 The @code{buildbot.status.words.IRC} status target creates an IRC bot
4327 which will attach to certain channels and be available for status
4328 queries. It can also be asked to announce builds as they occur, or be
4329 told to shut up.
4331 @example
4332 from twisted.status import words
4333 irc = words.IRC("irc.example.org", "botnickname", 
4334                 channels=["channel1", "channel2"],
4335                 password="mysecretpassword")
4336 c['status'].append(irc)
4337 @end example
4339 Take a look at the docstring for @code{words.IRC} for more details on
4340 configuring this service. The @code{password} argument, if provided,
4341 will be sent to Nickserv to claim the nickname: some IRC servers will
4342 not allow clients to send private messages until they have logged in
4343 with a password.
4345 To use the service, you address messages at the buildbot, either
4346 normally (@code{botnickname: status}) or with private messages
4347 (@code{/msg botnickname status}). The buildbot will respond in kind.
4349 Some of the commands currently available:
4351 @table @code
4353 @item list builders
4354 Emit a list of all configured builders
4355 @item status BUILDER
4356 Announce the status of a specific Builder: what it is doing right now.
4357 @item status all
4358 Announce the status of all Builders
4359 @item watch BUILDER
4360 If the given Builder is currently running, wait until the Build is
4361 finished and then announce the results.
4362 @item last BUILDER
4363 Return the results of the last build to run on the given Builder.
4365 @item help COMMAND
4366 Describe a command. Use @code{help commands} to get a list of known
4367 commands.
4368 @item source
4369 Announce the URL of the Buildbot's home page.
4370 @item version
4371 Announce the version of this Buildbot.
4372 @end table
4374 If the @code{allowForce=True} option was used, some addtional commands
4375 will be available:
4377 @table @code
4378 @item force build BUILDER REASON
4379 Tell the given Builder to start a build of the latest code. The user
4380 requesting the build and REASON are recorded in the Build status. The
4381 buildbot will announce the build's status when it finishes.
4383 @item stop build BUILDER REASON
4384 Terminate any running build in the given Builder. REASON will be added
4385 to the build status to explain why it was stopped. You might use this
4386 if you committed a bug, corrected it right away, and don't want to
4387 wait for the first build (which is destined to fail) to complete
4388 before starting the second (hopefully fixed) build.
4389 @end table
4391 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
4392 @section PBListener
4394 @cindex PBListener
4396 @example
4397 import buildbot.status.client
4398 pbl = buildbot.status.client.PBListener(port=int, user=str,
4399                                         passwd=str)
4400 c['status'].append(pbl)
4401 @end example
4403 This sets up a PB listener on the given TCP port, to which a PB-based
4404 status client can connect and retrieve status information.
4405 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
4406 status client. The @code{port} argument can also be a strports
4407 specification string.
4409 @node Writing New Status Plugins,  , PBListener, Status Delivery
4410 @section Writing New Status Plugins
4412 TODO: this needs a lot more examples
4414 Each status plugin is an object which provides the
4415 @code{twisted.application.service.IService} interface, which creates a
4416 tree of Services with the buildmaster at the top [not strictly true].
4417 The status plugins are all children of an object which implements
4418 @code{buildbot.interfaces.IStatus}, the main status object. From this
4419 object, the plugin can retrieve anything it wants about current and
4420 past builds. It can also subscribe to hear about new and upcoming
4421 builds.
4423 Status plugins which only react to human queries (like the Waterfall
4424 display) never need to subscribe to anything: they are idle until
4425 someone asks a question, then wake up and extract the information they
4426 need to answer it, then they go back to sleep. Plugins which need to
4427 act spontaneously when builds complete (like the Mail plugin) need to
4428 subscribe to hear about new builds.
4430 If the status plugin needs to run network services (like the HTTP
4431 server used by the Waterfall plugin), they can be attached as Service
4432 children of the plugin itself, using the @code{IServiceCollection}
4433 interface.
4437 @node Command-line tool, Resources, Status Delivery, Top
4438 @chapter Command-line tool
4440 The @command{buildbot} command-line tool can be used to start or stop a
4441 buildmaster or buildbot, and to interact with a running buildmaster.
4442 Some of its subcommands are intended for buildmaster admins, while
4443 some are for developers who are editing the code that the buildbot is
4444 monitoring.
4446 @menu
4447 * Administrator Tools::         
4448 * Developer Tools::             
4449 * Other Tools::                 
4450 * .buildbot config directory::  
4451 @end menu
4453 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
4454 @section Administrator Tools
4456 The following @command{buildbot} sub-commands are intended for
4457 buildmaster administrators:
4459 @heading master
4461 This creates a new directory and populates it with files that allow it
4462 to be used as a buildmaster's base directory.
4464 @example
4465 buildbot master BASEDIR
4466 @end example
4468 @heading slave
4470 This creates a new directory and populates it with files that let it
4471 be used as a buildslave's base directory. You must provide several
4472 arguments, which are used to create the initial @file{buildbot.tac}
4473 file.
4475 @example
4476 buildbot slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
4477 @end example
4479 @heading start
4481 This starts a buildmaster or buildslave which was already created in
4482 the given base directory. The daemon is launched in the background,
4483 with events logged to a file named @file{twistd.log}.
4485 @example
4486 buildbot start BASEDIR
4487 @end example
4489 @heading stop
4491 This terminates the daemon (either buildmaster or buildslave) running
4492 in the given directory.
4494 @example
4495 buildbot stop BASEDIR
4496 @end example
4498 @heading sighup
4500 This sends a SIGHUP to the buildmaster running in the given directory,
4501 which causes it to re-read its @file{master.cfg} file.
4503 @example
4504 buildbot sighup BASEDIR
4505 @end example
4507 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
4508 @section Developer Tools
4510 These tools are provided for use by the developers who are working on
4511 the code that the buildbot is monitoring.
4513 @menu
4514 * statuslog::                   
4515 * statusgui::                   
4516 * try::                         
4517 @end menu
4519 @node statuslog, statusgui, Developer Tools, Developer Tools
4520 @subsection statuslog
4522 @example
4523 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
4524 @end example
4526 This command starts a simple text-based status client, one which just
4527 prints out a new line each time an event occurs on the buildmaster.
4529 The @option{--master} option provides the location of the
4530 @code{client.PBListener} status port, used to deliver build
4531 information to realtime status clients. The option is always in the
4532 form of a string, with hostname and port number separated by a colon
4533 (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the same
4534 as the slaveport (although a future version may allow the same port
4535 number to be used for both purposes).
4537 The @option{--master} option can also be provided by the
4538 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
4539 config directory}).
4541 @node statusgui, try, statuslog, Developer Tools
4542 @subsection statusgui
4544 @cindex statusgui
4546 If you have set up a PBListener (@pxref{PBListener}), you will be able
4547 to monitor your Buildbot using a simple Gtk+ application invoked with
4548 the @code{buildbot statusgui} command:
4550 @example
4551 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
4552 @end example
4554 This command starts a simple Gtk+-based status client, which contains
4555 a few boxes for each Builder that change color as events occur. It
4556 uses the same @option{--master} argument as the @command{buildbot
4557 statuslog} command (@pxref{statuslog}).
4559 @node try,  , statusgui, Developer Tools
4560 @subsection try
4562 This lets a developer to ask the question ``What would happen if I
4563 committed this patch right now?''. It runs the unit test suite (across
4564 multiple build platforms) on the developer's current code, allowing
4565 them to make sure they will not break the tree when they finally
4566 commit their changes.
4568 The @command{buildbot try} command is meant to be run from within a
4569 developer's local tree, and starts by figuring out the base revision
4570 of that tree (what revision was current the last time the tree was
4571 updated), and a patch that can be applied to that revision of the tree
4572 to make it match the developer's copy. This (revision, patch) pair is
4573 then sent to the buildmaster, which runs a build with that
4574 SourceStamp. If you want, the tool will emit status messages as the
4575 builds run, and will not terminate until the first failure has been
4576 detected (or the last success).
4578 For this command to work, several pieces must be in place:
4581 @heading TryScheduler
4583 The buildmaster must have a @code{scheduler.Try} instance in
4584 the config file's @code{c['schedulers']} list. This lets the
4585 administrator control who may initiate these ``trial'' builds, which
4586 branches are eligible for trial builds, and which Builders should be
4587 used for them.
4589 The @code{TryScheduler} has various means to accept build requests:
4590 all of them enforce more security than the usual buildmaster ports do.
4591 Any source code being built can be used to compromise the buildslave
4592 accounts, but in general that code must be checked out from the VC
4593 repository first, so only people with commit privileges can get
4594 control of the buildslaves. The usual force-build control channels can
4595 waste buildslave time but do not allow arbitrary commands to be
4596 executed by people who don't have those commit privileges. However,
4597 the source code patch that is provided with the trial build does not
4598 have to go through the VC system first, so it is important to make
4599 sure these builds cannot be abused by a non-committer to acquire as
4600 much control over the buildslaves as a committer has. Ideally, only
4601 developers who have commit access to the VC repository would be able
4602 to start trial builds, but unfortunately the buildmaster does not, in
4603 general, have access to VC system's user list.
4605 As a result, the @code{TryScheduler} requires a bit more
4606 configuration. There are currently two ways to set this up:
4608 @table @strong
4609 @item jobdir (ssh)
4611 This approach creates a command queue directory, called the
4612 ``jobdir'', in the buildmaster's working directory. The buildmaster
4613 admin sets the ownership and permissions of this directory to only
4614 grant write access to the desired set of developers, all of whom must
4615 have accounts on the machine. The @code{buildbot try} command creates
4616 a special file containing the source stamp information and drops it in
4617 the jobdir, just like a standard maildir. When the buildmaster notices
4618 the new file, it unpacks the information inside and starts the builds.
4620 The config file entries used by 'buildbot try' either specify a local
4621 queuedir (for which write and mv are used) or a remote one (using scp
4622 and ssh).
4624 The advantage of this scheme is that it is quite secure, the
4625 disadvantage is that it requires fiddling outside the buildmaster
4626 config (to set the permissions on the jobdir correctly). If the
4627 buildmaster machine happens to also house the VC repository, then it
4628 can be fairly easy to keep the VC userlist in sync with the
4629 trial-build userlist. If they are on different machines, this will be
4630 much more of a hassle. It may also involve granting developer accounts
4631 on a machine that would not otherwise require them.
4633 To implement this, the buildslave invokes 'ssh -l username host
4634 buildbot tryserver ARGS', passing the patch contents over stdin. The
4635 arguments must include the inlet directory and the revision
4636 information.
4638 @item user+password (PB)
4640 In this approach, each developer gets a username/password pair, which
4641 are all listed in the buildmaster's configuration file. When the
4642 developer runs @code{buildbot try}, their machine connects to the
4643 buildmaster via PB and authenticates themselves using that username
4644 and password, then sends a PB command to start the trial build.
4646 The advantage of this scheme is that the entire configuration is
4647 performed inside the buildmaster's config file. The disadvantages are
4648 that it is less secure (while the ``cred'' authentication system does
4649 not expose the password in plaintext over the wire, it does not offer
4650 most of the other security properties that SSH does). In addition, the
4651 buildmaster admin is responsible for maintaining the username/password
4652 list, adding and deleting entries as developers come and go.
4654 @end table
4657 For example, to set up the ``jobdir'' style of trial build, using a
4658 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
4659 all your project developers were members of the @code{developers} unix
4660 group), you would first create that directory (with @command{mkdir
4661 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
4662 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
4663 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
4664 MASTERDIR/jobdir/*}), and then use the following scheduler in the
4665 buildmaster's config file:
4667 @example
4668 from buildbot.scheduler import Try_Jobdir
4669 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
4670                jobdir="jobdir")
4671 c['schedulers'] = [s]
4672 @end example
4674 Note that you must create the jobdir before telling the buildmaster to
4675 use this configuration, otherwise you will get an error. Also remember
4676 that the buildmaster must be able to read and write to the jobdir as
4677 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
4678 as you start using the jobdir, to make sure the buildmaster is happy
4679 with it.
4681 To use the username/password form of authentication, create a
4682 @code{Try_Userpass} instance instead. It takes the same
4683 @code{builderNames} argument as the @code{Try_Jobdir} form, but
4684 accepts an addtional @code{port} argument (to specify the TCP port to
4685 listen on) and a @code{userpass} list of username/password pairs to
4686 accept. Remember to use good passwords for this: the security of the
4687 buildslave accounts depends upon it:
4689 @example
4690 from buildbot.scheduler import Try_Userpass
4691 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
4692                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
4693 c['schedulers'] = [s]
4694 @end example
4696 Like most places in the buildbot, the @code{port} argument takes a
4697 strports specification. See @code{twisted.application.strports} for
4698 details.
4701 @heading locating the master
4703 The @command{try} command needs to be told how to connect to the
4704 @code{TryScheduler}, and must know which of the authentication
4705 approaches described above is in use by the buildmaster. You specify
4706 the approach by using @option{--connect=ssh} or @option{--connect=pb}
4707 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
4708 @file{.buildbot/options}).
4710 For the PB approach, the command must be given a @option{--master}
4711 argument (in the form HOST:PORT) that points to TCP port that you
4712 picked in the @code{Try_Userpass} scheduler. It also takes a
4713 @option{--username} and @option{--passwd} pair of arguments that match
4714 one of the entries in the buildmaster's @code{userpass} list. These
4715 arguments can also be provided as @code{try_master},
4716 @code{try_username}, and @code{try_password} entries in the
4717 @file{.buildbot/options} file.
4719 For the SSH approach, the command must be given @option{--tryhost},
4720 @option{--username}, and optionally @option{--password} (TODO:
4721 really?) to get to the buildmaster host. It must also be given
4722 @option{--trydir}, which points to the inlet directory configured
4723 above. The trydir can be relative to the user's home directory, but
4724 most of the time you will use an explicit path like
4725 @file{~buildbot/project/trydir}. These arguments can be provided in
4726 @file{.buildbot/options} as @code{try_host}, @code{try_username},
4727 @code{try_password}, and @code{try_dir}.
4729 In addition, the SSH approach needs to connect to a PBListener status
4730 port, so it can retrieve and report the results of the build (the PB
4731 approach uses the existing connection to retrieve status information,
4732 so this step is not necessary). This requires a @option{--master}
4733 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
4734 in the form of a HOSTNAME:PORT string.
4737 @heading choosing the Builders
4739 A trial build is performed on multiple Builders at the same time, and
4740 the developer gets to choose which Builders are used (limited to a set
4741 selected by the buildmaster admin with the TryScheduler's
4742 @code{builderNames=} argument). The set you choose will depend upon
4743 what your goals are: if you are concerned about cross-platform
4744 compatibility, you should use multiple Builders, one from each
4745 platform of interest. You might use just one builder if that platform
4746 has libraries or other facilities that allow better test coverage than
4747 what you can accomplish on your own machine, or faster test runs.
4749 The set of Builders to use can be specified with multiple
4750 @option{--builder} arguments on the command line. It can also be
4751 specified with a single @code{try_builders} option in
4752 @file{.buildbot/options} that uses a list of strings to specify all
4753 the Builder names:
4755 @example
4756 try_builders = ["full-OSX", "full-win32", "full-linux"]
4757 @end example
4759 @heading specifying the VC system
4761 The @command{try} command also needs to know how to take the
4762 developer's current tree and extract the (revision, patch)
4763 source-stamp pair. Each VC system uses a different process, so you
4764 start by telling the @command{try} command which VC system you are
4765 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
4766 This can also be provided as @code{try_vc} in
4767 @file{.buildbot/options}.
4769 The following names are recognized: @code{cvs} @code{svn} @code{baz}
4770 @code{tla} @code{hg} @code{darcs}
4773 @heading finding the top of the tree
4775 Some VC systems (notably CVS and SVN) track each directory
4776 more-or-less independently, which means the @command{try} command
4777 needs to move up to the top of the project tree before it will be able
4778 to construct a proper full-tree patch. To accomplish this, the
4779 @command{try} command will crawl up through the parent directories
4780 until it finds a marker file. The default name for this marker file is
4781 @file{.buildbot-top}, so when you are using CVS or SVN you should
4782 @code{touch .buildbot-top} from the top of your tree before running
4783 @command{buildbot try}. Alternatively, you can use a filename like
4784 @file{ChangeLog} or @file{README}, since many projects put one of
4785 these files in their top-most directory (and nowhere else). To set
4786 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
4787 options file with @code{try_topfile = 'ChangeLog'}.
4789 You can also manually set the top of the tree with
4790 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
4791 '~/trees/mytree'}. If you use @code{try_topdir}, in a
4792 @file{.buildbot/options} file, you will need a separate options file
4793 for each tree you use, so it may be more convenient to use the
4794 @code{try_topfile} approach instead.
4796 Other VC systems which work on full projects instead of individual
4797 directories (tla, baz, darcs, monotone, mercurial) do not require
4798 @command{try} to know the top directory, so the @option{--try-topfile}
4799 and @option{--try-topdir} arguments will be ignored.
4800 @c is this true? I think I currently require topdirs all the time.
4802 If the @command{try} command cannot find the top directory, it will
4803 abort with an error message.
4805 @heading determining the branch name
4807 Some VC systems record the branch information in a way that ``try''
4808 can locate it, in particular Arch (both @command{tla} and
4809 @command{baz}). For the others, if you are using something other than
4810 the default branch, you will have to tell the buildbot which branch
4811 your tree is using. You can do this with either the @option{--branch}
4812 argument, or a @option{try_branch} entry in the
4813 @file{.buildbot/options} file.
4815 @heading determining the revision and patch
4817 Each VC system has a separate approach for determining the tree's base
4818 revision and computing a patch.
4820 @table @code
4822 @item CVS
4824 @command{try} pretends that the tree is up to date. It converts the
4825 current time into a @code{-D} time specification, uses it as the base
4826 revision, and computes the diff between the upstream tree as of that
4827 point in time versus the current contents. This works, more or less,
4828 but requires that the local clock be in reasonably good sync with the
4829 repository.
4831 @item SVN
4832 @command{try} does a @code{svn status -u} to find the latest
4833 repository revision number (emitted on the last line in the ``Status
4834 against revision: NN'' message). It then performs an @code{svn diff
4835 -rNN} to find out how your tree differs from the repository version,
4836 and sends the resulting patch to the buildmaster. If your tree is not
4837 up to date, this will result in the ``try'' tree being created with
4838 the latest revision, then @emph{backwards} patches applied to bring it
4839 ``back'' to the version you actually checked out (plus your actual
4840 code changes), but this will still result in the correct tree being
4841 used for the build.
4843 @item baz
4844 @command{try} does a @code{baz tree-id} to determine the
4845 fully-qualified version and patch identifier for the tree
4846 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
4847 as the base revision. It then does a @code{baz diff} to obtain the
4848 patch.
4850 @item tla
4851 @command{try} does a @code{tla tree-version} to get the
4852 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
4853 first line of @code{tla logs --reverse} to figure out the base
4854 revision. Then it does @code{tla changes --diffs} to obtain the patch.
4856 @item Darcs
4857 @code{darcs changes --context} emits a text file that contains a list
4858 of all patches back to and including the last tag was made. This text
4859 file (plus the location of a repository that contains all these
4860 patches) is sufficient to re-create the tree. Therefore the contents
4861 of this ``context'' file @emph{are} the revision stamp for a
4862 Darcs-controlled source tree.
4864 So @command{try} does a @code{darcs changes --context} to determine
4865 what your tree's base revision is, and then does a @code{darcs diff
4866 -u} to compute the patch relative to that revision.
4868 @item Mercurial
4869 @code{hg identify} emits a short revision ID (basically a truncated
4870 SHA1 hash of the current revision's contents), which is used as the
4871 base revision. @code{hg diff} then provides the patch relative to that
4872 revision. For @command{try} to work, your working directory must only
4873 have patches that are available from the same remotely-available
4874 repository that the build process' @code{step.Mercurial} will use.
4876 @c TODO: monotone, git
4877 @end table
4879 @heading waiting for results
4881 If you provide the @option{--wait} option (or @code{try_wait = True}
4882 in @file{.buildbot/options}), the @command{buildbot try} command will
4883 wait until your changes have either been proven good or bad before
4884 exiting. Unless you use the @option{--quiet} option (or
4885 @code{try_quiet=True}), it will emit a progress message every 60
4886 seconds until the builds have completed.
4889 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
4890 @section Other Tools
4892 These tools are generally used by buildmaster administrators.
4894 @menu
4895 * sendchange::                  
4896 * debugclient::                 
4897 @end menu
4899 @node sendchange, debugclient, Other Tools, Other Tools
4900 @subsection sendchange
4902 This command is used to tell the buildmaster about source changes. It
4903 is intended to be used from within a commit script, installed on the
4904 VC server.
4906 @example
4907 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
4908 @end example
4910 There are other (optional) arguments which can influence the
4911 @code{Change} that gets submitted:
4913 @table @code
4914 @item --branch
4915 This provides the (string) branch specifier. If omitted, it defaults
4916 to None, indicating the ``default branch''. All files included in this
4917 Change must be on the same branch.
4919 @item --revision_number
4920 This provides a (numeric) revision number for the change, used for VC systems
4921 that use numeric transaction numbers (like Subversion).
4923 @item --revision
4924 This provides a (string) revision specifier, for VC systems that use
4925 strings (Arch would use something like patch-42 etc).
4927 @item --revision_file
4928 This provides a filename which will be opened and the contents used as
4929 the revision specifier. This is specifically for Darcs, which uses the
4930 output of @command{darcs changes --context} as a revision specifier.
4931 This context file can be a couple of kilobytes long, spanning a couple
4932 lines per patch, and would be a hassle to pass as a command-line
4933 argument.
4935 @item --comments
4936 This provides the change comments as a single argument. You may want
4937 to use @option{--logfile} instead.
4939 @item --logfile
4940 This instructs the tool to read the change comments from the given
4941 file. If you use @code{-} as the filename, the tool will read the
4942 change comments from stdin.
4943 @end table
4946 @node debugclient,  , sendchange, Other Tools
4947 @subsection debugclient
4949 @example
4950 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
4951 @end example
4953 This launches a small Gtk+/Glade-based debug tool, connecting to the
4954 buildmaster's ``debug port''. This debug port shares the same port
4955 number as the slaveport (@pxref{Setting the slaveport}), but the
4956 @code{debugPort} is only enabled if you set a debug password in the
4957 buildmaster's config file (@pxref{Debug options}). The
4958 @option{--passwd} option must match the @code{c['debugPassword']}
4959 value.
4961 @option{--master} can also be provided in @file{.debug/options} by the
4962 @code{master} key. @option{--passwd} can be provided by the
4963 @code{debugPassword} key.
4965 The @code{Connect} button must be pressed before any of the other
4966 buttons will be active. This establishes the connection to the
4967 buildmaster. The other sections of the tool are as follows:
4969 @table @code
4970 @item Reload .cfg
4971 Forces the buildmaster to reload its @file{master.cfg} file. This is
4972 equivalent to sending a SIGHUP to the buildmaster, but can be done
4973 remotely through the debug port. Note that it is a good idea to be
4974 watching the buildmaster's @file{twistd.log} as you reload the config
4975 file, as any errors which are detected in the config file will be
4976 announced there.
4978 @item Rebuild .py
4979 (not yet implemented). The idea here is to use Twisted's ``rebuild''
4980 facilities to replace the buildmaster's running code with a new
4981 version. Even if this worked, it would only be used by buildbot
4982 developers.
4984 @item poke IRC
4985 This locates a @code{words.IRC} status target and causes it to emit a
4986 message on all the channels to which it is currently connected. This
4987 was used to debug a problem in which the buildmaster lost the
4988 connection to the IRC server and did not attempt to reconnect.
4990 @item Commit
4991 This allows you to inject a Change, just as if a real one had been
4992 delivered by whatever VC hook you are using. You can set the name of
4993 the committed file and the name of the user who is doing the commit.
4994 Optionally, you can also set a revision for the change. If the
4995 revision you provide looks like a number, it will be sent as an
4996 integer, otherwise it will be sent as a string.
4998 @item Force Build
4999 This lets you force a Builder (selected by name) to start a build of
5000 the current source tree.
5002 @item Currently
5003 (obsolete). This was used to manually set the status of the given
5004 Builder, but the status-assignment code was changed in an incompatible
5005 way and these buttons are no longer meaningful.
5007 @end table
5010 @node .buildbot config directory,  , Other Tools, Command-line tool
5011 @section .buildbot config directory
5013 Many of the @command{buildbot} tools must be told how to contact the
5014 buildmaster that they interact with. This specification can be
5015 provided as a command-line argument, but most of the time it will be
5016 easier to set them in an ``options'' file. The @command{buildbot}
5017 command will look for a special directory named @file{.buildbot},
5018 starting from the current directory (where the command was run) and
5019 crawling upwards, eventually looking in the user's home directory. It
5020 will look for a file named @file{options} in this directory, and will
5021 evaluate it as a python script, looking for certain names to be set.
5022 You can just put simple @code{name = 'value'} pairs in this file to
5023 set the options.
5025 For a description of the names used in this file, please see the
5026 documentation for the individual @command{buildbot} sub-commands. The
5027 following is a brief sample of what this file's contents could be.
5029 @example
5030 # for status-reading tools
5031 masterstatus = 'buildbot.example.org:12345'
5032 # for 'sendchange' or the debug port
5033 master = 'buildbot.example.org:18990'
5034 debugPassword = 'eiv7Po'
5035 @end example
5037 @table @code
5038 @item masterstatus
5039 Location of the @code{client.PBListener} status port, used by
5040 @command{statuslog} and @command{statusgui}.
5042 @item master
5043 Location of the @code{debugPort} (for @command{debugclient}). Also the
5044 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
5045 Usually shares the slaveport, but a future version may make it
5046 possible to have these listen on a separate port number.
5048 @item debugPassword
5049 Must match the value of @code{c['debugPassword']}, used to protect the
5050 debug port, for the @command{debugclient} command.
5052 @item username
5053 Provides a default username for the @command{sendchange} command.
5055 @end table
5059 @node Resources, Developer's Appendix, Command-line tool, Top
5060 @chapter Resources
5062 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
5064 For configuration questions and general discussion, please use the
5065 @code{buildbot-devel} mailing list. The subscription instructions and
5066 archives are available at
5067 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
5069 @node Developer's Appendix, Index, Resources, Top
5070 @unnumbered Developer's Appendix
5072 This appendix contains random notes about the implementation of the
5073 Buildbot, and is likely to only be of use to people intending to
5074 extend the Buildbot's internals.
5076 The buildmaster consists of a tree of Service objects, which is shaped
5077 as follows:
5079 @example
5080 BuildMaster
5081  ChangeMaster  (in .change_svc)
5082   [IChangeSource instances]
5083  [IScheduler instances]  (in .schedulers)
5084  BotMaster  (in .botmaster)
5085  [IStatusTarget instances]  (in .statusTargets)
5086 @end example
5088 The BotMaster has a collection of Builder objects as values of its
5089 @code{.builders} dictionary.
5092 @node Index,  , Developer's Appendix, Top
5093 @unnumbered Index
5095 @printindex cp
5097 @bye