(fixes #313) update documentation for locks
[buildbot.git] / docs / buildbot.texinfo
blob13c808ef0d297faa208d958c09d47dd9ab327a11
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.9
5 @defcodeindex cs
6 @defcodeindex sl
7 @defcodeindex bf
8 @defcodeindex bs
9 @defcodeindex st
10 @defcodeindex bc
11 @c %**end of header
13 @c these indices are for classes useful in a master.cfg config file
14 @c @csindex : Change Sources
15 @c @slindex : Schedulers and Locks
16 @c @bfindex : Build Factories
17 @c @bsindex : Build Steps
18 @c @stindex : Status Targets
20 @c @bcindex : keys that make up BuildmasterConfig
22 @copying
23 This is the BuildBot manual.
25 Copyright (C) 2005,2006 Brian Warner
27 Copying and distribution of this file, with or without
28 modification, are permitted in any medium without royalty
29 provided the copyright notice and this notice are preserved.
31 @end copying
33 @titlepage
34 @title BuildBot
35 @page
36 @vskip 0pt plus 1filll
37 @insertcopying
38 @end titlepage
40 @c Output the table of the contents at the beginning.
41 @contents
43 @ifnottex
44 @node Top, Introduction, (dir), (dir)
45 @top BuildBot
47 @insertcopying
48 @end ifnottex
50 @menu
51 * Introduction::                What the BuildBot does.
52 * Installation::                Creating a buildmaster and buildslaves,
53                                 running them.
54 * Concepts::                    What goes on in the buildbot's little mind.
55 * Configuration::               Controlling the buildbot.
56 * Getting Source Code Changes::  Discovering when to run a build.
57 * Build Process::               Controlling how each build is run.
58 * Status Delivery::             Telling the world about the build's results.
59 * Command-line tool::           
60 * Resources::                   Getting help.
61 * Developer's Appendix::        
62 * Index of Useful Classes::     
63 * Index of master.cfg keys::    
64 * Index::                       Complete index.
66 @detailmenu
67  --- The Detailed Node Listing ---
69 Introduction
71 * History and Philosophy::      
72 * System Architecture::         
73 * Control Flow::                
75 System Architecture
77 * BuildSlave Connections::      
78 * Buildmaster Architecture::    
79 * Status Delivery Architecture::  
81 Installation
83 * Requirements::                
84 * Installing the code::         
85 * Creating a buildmaster::      
86 * Upgrading an Existing Buildmaster::  
87 * Creating a buildslave::       
88 * Launching the daemons::       
89 * Logfiles::                    
90 * Shutdown::                    
91 * Maintenance::                 
92 * Troubleshooting::             
94 Creating a buildslave
96 * Buildslave Options::          
98 Troubleshooting
100 * Starting the buildslave::     
101 * Connecting to the buildmaster::  
102 * Forcing Builds::              
104 Concepts
106 * Version Control Systems::     
107 * Schedulers::                  
108 * BuildSet::                    
109 * BuildRequest::                
110 * Builder::                     
111 * Users::                       
112 * Build Properties::            
114 Version Control Systems
116 * Generalizing VC Systems::     
117 * Source Tree Specifications::  
118 * How Different VC Systems Specify Sources::  
119 * Attributes of Changes::       
121 Users
123 * Doing Things With Users::     
124 * Email Addresses::             
125 * IRC Nicknames::               
126 * Live Status Clients::         
128 Configuration
130 * Config File Format::          
131 * Loading the Config File::     
132 * Testing the Config File::     
133 * Defining the Project::        
134 * Change Sources and Schedulers::  
135 * Setting the slaveport::       
136 * Buildslave Specifiers::       
137 * Defining Global Properties::  
138 * Defining Builders::           
139 * Defining Status Targets::     
140 * Debug options::               
142 Change Sources and Schedulers
144 * Scheduler Scheduler::         
145 * AnyBranchScheduler::          
146 * Dependent Scheduler::         
147 * Periodic Scheduler::          
148 * Nightly Scheduler::           
149 * Try Schedulers::              
150 * Triggerable Scheduler::       
152 Buildslave Specifiers
154 * When Buildslaves Go Missing::  
156 Getting Source Code Changes
158 * Change Sources::              
159 * Choosing ChangeSources::      
160 * CVSToys - PBService::         
161 * Mail-parsing ChangeSources::  
162 * PBChangeSource::              
163 * P4Source::                    
164 * BonsaiPoller::                
165 * SVNPoller::                   
166 * MercurialHook::               
168 Mail-parsing ChangeSources
170 * Subscribing the Buildmaster::  
171 * Using Maildirs::              
172 * Parsing Email Change Messages::  
174 Parsing Email Change Messages
176 * FCMaildirSource::             
177 * SyncmailMaildirSource::       
178 * BonsaiMaildirSource::         
179 * SVNCommitEmailMaildirSource::  
181 Build Process
183 * Build Steps::                 
184 * Interlocks::                  
185 * Build Factories::             
187 Build Steps
189 * Common Parameters::           
190 * Using Build Properties::      
191 * Source Checkout::             
192 * ShellCommand::                
193 * Simple ShellCommand Subclasses::  
194 * Python BuildSteps::           
195 * Transferring Files::          
196 * Triggering Schedulers::       
197 * Writing New BuildSteps::      
199 Source Checkout
201 * CVS::                         
202 * SVN::                         
203 * Darcs::                       
204 * Mercurial::                   
205 * Arch::                        
206 * Bazaar::                      
207 * Bzr::                         
208 * P4::                          
209 * Git::                         
211 Simple ShellCommand Subclasses
213 * Configure::                   
214 * Compile::                     
215 * Test::                        
216 * TreeSize::                    
217 * PerlModuleTest::              
218 * SetProperty::                 
220 Python BuildSteps
222 * BuildEPYDoc::                 
223 * PyFlakes::                    
225 Writing New BuildSteps
227 * BuildStep LogFiles::          
228 * Reading Logfiles::            
229 * Adding LogObservers::         
230 * BuildStep URLs::              
232 Build Factories
234 * BuildStep Objects::           
235 * BuildFactory::                
236 * Process-Specific build factories::  
238 BuildStep Objects
240 * BuildFactory Attributes::     
241 * Quick builds::                
243 BuildFactory
245 * BuildFactory Attributes::     
246 * Quick builds::                
248 Process-Specific build factories
250 * GNUAutoconf::                 
251 * CPAN::                        
252 * Python distutils::            
253 * Python/Twisted/trial projects::  
255 Status Delivery
257 * WebStatus::                   
258 * MailNotifier::                
259 * IRC Bot::                     
260 * PBListener::                  
261 * Writing New Status Plugins::  
263 WebStatus
265 * WebStatus Configuration Parameters::  
266 * Buildbot Web Resources::      
267 * XMLRPC server::               
268 * HTML Waterfall::              
270 Command-line tool
272 * Administrator Tools::         
273 * Developer Tools::             
274 * Other Tools::                 
275 * .buildbot config directory::  
277 Developer Tools
279 * statuslog::                   
280 * statusgui::                   
281 * try::                         
283 waiting for results
285 * try --diff::                  
287 Other Tools
289 * sendchange::                  
290 * debugclient::                 
292 @end detailmenu
293 @end menu
295 @node Introduction, Installation, Top, Top
296 @chapter Introduction
298 @cindex introduction
300 The BuildBot is a system to automate the compile/test cycle required by most
301 software projects to validate code changes. By automatically rebuilding and
302 testing the tree each time something has changed, build problems are
303 pinpointed quickly, before other developers are inconvenienced by the
304 failure. The guilty developer can be identified and harassed without human
305 intervention. By running the builds on a variety of platforms, developers
306 who do not have the facilities to test their changes everywhere before
307 checkin will at least know shortly afterwards whether they have broken the
308 build or not. Warning counts, lint checks, image size, compile time, and
309 other build parameters can be tracked over time, are more visible, and
310 are therefore easier to improve.
312 The overall goal is to reduce tree breakage and provide a platform to
313 run tests or code-quality checks that are too annoying or pedantic for
314 any human to waste their time with. Developers get immediate (and
315 potentially public) feedback about their changes, encouraging them to
316 be more careful about testing before checkin.
318 Features:
320 @itemize @bullet
321 @item
322 run builds on a variety of slave platforms
323 @item
324 arbitrary build process: handles projects using C, Python, whatever
325 @item
326 minimal host requirements: python and Twisted
327 @item
328 slaves can be behind a firewall if they can still do checkout
329 @item
330 status delivery through web page, email, IRC, other protocols
331 @item
332 track builds in progress, provide estimated completion time
333 @item
334 flexible configuration by subclassing generic build process classes
335 @item
336 debug tools to force a new build, submit fake Changes, query slave status
337 @item
338 released under the GPL
339 @end itemize
341 @menu
342 * History and Philosophy::      
343 * System Architecture::         
344 * Control Flow::                
345 @end menu
348 @node History and Philosophy, System Architecture, Introduction, Introduction
349 @section History and Philosophy
351 @cindex Philosophy of operation
353 The Buildbot was inspired by a similar project built for a development
354 team writing a cross-platform embedded system. The various components
355 of the project were supposed to compile and run on several flavors of
356 unix (linux, solaris, BSD), but individual developers had their own
357 preferences and tended to stick to a single platform. From time to
358 time, incompatibilities would sneak in (some unix platforms want to
359 use @code{string.h}, some prefer @code{strings.h}), and then the tree
360 would compile for some developers but not others. The buildbot was
361 written to automate the human process of walking into the office,
362 updating a tree, compiling (and discovering the breakage), finding the
363 developer at fault, and complaining to them about the problem they had
364 introduced. With multiple platforms it was difficult for developers to
365 do the right thing (compile their potential change on all platforms);
366 the buildbot offered a way to help.
368 Another problem was when programmers would change the behavior of a
369 library without warning its users, or change internal aspects that
370 other code was (unfortunately) depending upon. Adding unit tests to
371 the codebase helps here: if an application's unit tests pass despite
372 changes in the libraries it uses, you can have more confidence that
373 the library changes haven't broken anything. Many developers
374 complained that the unit tests were inconvenient or took too long to
375 run: having the buildbot run them reduces the developer's workload to
376 a minimum.
378 In general, having more visibility into the project is always good,
379 and automation makes it easier for developers to do the right thing.
380 When everyone can see the status of the project, developers are
381 encouraged to keep the tree in good working order. Unit tests that
382 aren't run on a regular basis tend to suffer from bitrot just like
383 code does: exercising them on a regular basis helps to keep them
384 functioning and useful.
386 The current version of the Buildbot is additionally targeted at
387 distributed free-software projects, where resources and platforms are
388 only available when provided by interested volunteers. The buildslaves
389 are designed to require an absolute minimum of configuration, reducing
390 the effort a potential volunteer needs to expend to be able to
391 contribute a new test environment to the project. The goal is for
392 anyone who wishes that a given project would run on their favorite
393 platform should be able to offer that project a buildslave, running on
394 that platform, where they can verify that their portability code
395 works, and keeps working.
397 @node System Architecture, Control Flow, History and Philosophy, Introduction
398 @comment  node-name,  next,  previous,  up
399 @section System Architecture
401 The Buildbot consists of a single @code{buildmaster} and one or more
402 @code{buildslaves}, connected in a star topology. The buildmaster
403 makes all decisions about what, when, and how to build. It sends
404 commands to be run on the build slaves, which simply execute the
405 commands and return the results. (certain steps involve more local
406 decision making, where the overhead of sending a lot of commands back
407 and forth would be inappropriate, but in general the buildmaster is
408 responsible for everything).
410 The buildmaster is usually fed @code{Changes} by some sort of version
411 control system (@pxref{Change Sources}), which may cause builds to be
412 run. As the builds are performed, various status messages are
413 produced, which are then sent to any registered Status Targets
414 (@pxref{Status Delivery}).
416 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
417 @image{images/overview,,,Overview Diagram,}
419 The buildmaster is configured and maintained by the ``buildmaster
420 admin'', who is generally the project team member responsible for
421 build process issues. Each buildslave is maintained by a ``buildslave
422 admin'', who do not need to be quite as involved. Generally slaves are
423 run by anyone who has an interest in seeing the project work well on
424 their favorite platform.
426 @menu
427 * BuildSlave Connections::      
428 * Buildmaster Architecture::    
429 * Status Delivery Architecture::  
430 @end menu
432 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
433 @subsection BuildSlave Connections
435 The buildslaves are typically run on a variety of separate machines,
436 at least one per platform of interest. These machines connect to the
437 buildmaster over a TCP connection to a publically-visible port. As a
438 result, the buildslaves can live behind a NAT box or similar
439 firewalls, as long as they can get to buildmaster. The TCP connections
440 are initiated by the buildslave and accepted by the buildmaster, but
441 commands and results travel both ways within this connection. The
442 buildmaster is always in charge, so all commands travel exclusively
443 from the buildmaster to the buildslave.
445 To perform builds, the buildslaves must typically obtain source code
446 from a CVS/SVN/etc repository. Therefore they must also be able to
447 reach the repository. The buildmaster provides instructions for
448 performing builds, but does not provide the source code itself.
450 @image{images/slaves,,,BuildSlave Connections,}
452 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
453 @subsection Buildmaster Architecture
455 The Buildmaster consists of several pieces:
457 @image{images/master,,,BuildMaster Architecture,}
459 @itemize @bullet
461 @item
462 Change Sources, which create a Change object each time something is
463 modified in the VC repository. Most ChangeSources listen for messages
464 from a hook script of some sort. Some sources actively poll the
465 repository on a regular basis. All Changes are fed to the Schedulers.
467 @item
468 Schedulers, which decide when builds should be performed. They collect
469 Changes into BuildRequests, which are then queued for delivery to
470 Builders until a buildslave is available.
472 @item
473 Builders, which control exactly @emph{how} each build is performed
474 (with a series of BuildSteps, configured in a BuildFactory). Each
475 Build is run on a single buildslave.
477 @item
478 Status plugins, which deliver information about the build results
479 through protocols like HTTP, mail, and IRC.
481 @end itemize
483 @image{images/slavebuilder,,,SlaveBuilders,}
485 Each Builder is configured with a list of BuildSlaves that it will use
486 for its builds. These buildslaves are expected to behave identically:
487 the only reason to use multiple BuildSlaves for a single Builder is to
488 provide a measure of load-balancing.
490 Within a single BuildSlave, each Builder creates its own SlaveBuilder
491 instance. These SlaveBuilders operate independently from each other.
492 Each gets its own base directory to work in. It is quite common to
493 have many Builders sharing the same buildslave. For example, there
494 might be two buildslaves: one for i386, and a second for PowerPC.
495 There may then be a pair of Builders that do a full compile/test run,
496 one for each architecture, and a lone Builder that creates snapshot
497 source tarballs if the full builders complete successfully. The full
498 builders would each run on a single buildslave, whereas the tarball
499 creation step might run on either buildslave (since the platform
500 doesn't matter when creating source tarballs). In this case, the
501 mapping would look like:
503 @example
504 Builder(full-i386)  ->  BuildSlaves(slave-i386)
505 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
506 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
507 @end example
509 and each BuildSlave would have two SlaveBuilders inside it, one for a
510 full builder, and a second for the source-tarball builder.
512 Once a SlaveBuilder is available, the Builder pulls one or more
513 BuildRequests off its incoming queue. (It may pull more than one if it
514 determines that it can merge the requests together; for example, there
515 may be multiple requests to build the current HEAD revision). These
516 requests are merged into a single Build instance, which includes the
517 SourceStamp that describes what exact version of the source code
518 should be used for the build. The Build is then randomly assigned to a
519 free SlaveBuilder and the build begins.
522 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
523 @subsection Status Delivery Architecture
525 The buildmaster maintains a central Status object, to which various
526 status plugins are connected. Through this Status object, a full
527 hierarchy of build status objects can be obtained.
529 @image{images/status,,,Status Delivery,}
531 The configuration file controls which status plugins are active. Each
532 status plugin gets a reference to the top-level Status object. From
533 there they can request information on each Builder, Build, Step, and
534 LogFile. This query-on-demand interface is used by the html.Waterfall
535 plugin to create the main status page each time a web browser hits the
536 main URL.
538 The status plugins can also subscribe to hear about new Builds as they
539 occur: this is used by the MailNotifier to create new email messages
540 for each recently-completed Build.
542 The Status object records the status of old builds on disk in the
543 buildmaster's base directory. This allows it to return information
544 about historical builds.
546 There are also status objects that correspond to Schedulers and
547 BuildSlaves. These allow status plugins to report information about
548 upcoming builds, and the online/offline status of each buildslave.
551 @node Control Flow,  , System Architecture, Introduction
552 @comment  node-name,  next,  previous,  up
553 @section Control Flow
555 A day in the life of the buildbot:
557 @itemize @bullet
559 @item
560 A developer commits some source code changes to the repository. A hook
561 script or commit trigger of some sort sends information about this
562 change to the buildmaster through one of its configured Change
563 Sources. This notification might arrive via email, or over a network
564 connection (either initiated by the buildmaster as it ``subscribes''
565 to changes, or by the commit trigger as it pushes Changes towards the
566 buildmaster). The Change contains information about who made the
567 change, what files were modified, which revision contains the change,
568 and any checkin comments.
570 @item
571 The buildmaster distributes this change to all of its configured
572 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
573 to be started, and the Change is added to a list of those that will go
574 into a new Build. When the timer expires, a Build is started on each
575 of a set of configured Builders, all compiling/testing the same source
576 code. Unless configured otherwise, all Builds run in parallel on the
577 various buildslaves.
579 @item
580 The Build consists of a series of Steps. Each Step causes some number
581 of commands to be invoked on the remote buildslave associated with
582 that Builder. The first step is almost always to perform a checkout of
583 the appropriate revision from the same VC system that produced the
584 Change. The rest generally perform a compile and run unit tests. As
585 each Step runs, the buildslave reports back command output and return
586 status to the buildmaster.
588 @item
589 As the Build runs, status messages like ``Build Started'', ``Step
590 Started'', ``Build Finished'', etc, are published to a collection of
591 Status Targets. One of these targets is usually the HTML ``Waterfall''
592 display, which shows a chronological list of events, and summarizes
593 the results of the most recent build at the top of each column.
594 Developers can periodically check this page to see how their changes
595 have fared. If they see red, they know that they've made a mistake and
596 need to fix it. If they see green, they know that they've done their
597 duty and don't need to worry about their change breaking anything.
599 @item
600 If a MailNotifier status target is active, the completion of a build
601 will cause email to be sent to any developers whose Changes were
602 incorporated into this Build. The MailNotifier can be configured to
603 only send mail upon failing builds, or for builds which have just
604 transitioned from passing to failing. Other status targets can provide
605 similar real-time notification via different communication channels,
606 like IRC.
608 @end itemize
611 @node Installation, Concepts, Introduction, Top
612 @chapter Installation
614 @menu
615 * Requirements::                
616 * Installing the code::         
617 * Creating a buildmaster::      
618 * Upgrading an Existing Buildmaster::  
619 * Creating a buildslave::       
620 * Launching the daemons::       
621 * Logfiles::                    
622 * Shutdown::                    
623 * Maintenance::                 
624 * Troubleshooting::             
625 @end menu
627 @node Requirements, Installing the code, Installation, Installation
628 @section Requirements
630 At a bare minimum, you'll need the following (for both the buildmaster
631 and a buildslave):
633 @itemize @bullet
634 @item
635 Python: http://www.python.org
637 Buildbot requires python-2.3 or later, and is primarily developed
638 against python-2.4. It is also tested against python-2.5 .
640 @item
641 Twisted: http://twistedmatrix.com
643 Both the buildmaster and the buildslaves require Twisted-2.0.x or
644 later. It has been tested against all releases of Twisted up to
645 Twisted-2.5.0 (the most recent as of this writing). As always, the
646 most recent version is recommended.
648 Twisted is delivered as a collection of subpackages. You'll need at
649 least "Twisted" (the core package), and you'll also want TwistedMail,
650 TwistedWeb, and TwistedWords (for sending email, serving a web status
651 page, and delivering build status via IRC, respectively). You might
652 also want TwistedConch (for the encrypted Manhole debug port). Note
653 that Twisted requires ZopeInterface to be installed as well.
655 @end itemize
657 Certain other packages may be useful on the system running the
658 buildmaster:
660 @itemize @bullet
661 @item
662 CVSToys: http://purl.net/net/CVSToys
664 If your buildmaster uses FreshCVSSource to receive change notification
665 from a cvstoys daemon, it will require CVSToys be installed (tested
666 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
667 only use a mail-parsing change source, or the SVN notification
668 script), you will not need CVSToys.
670 @end itemize
672 And of course, your project's build process will impose additional
673 requirements on the buildslaves. These hosts must have all the tools
674 necessary to compile and test your project's source code.
677 @node Installing the code, Creating a buildmaster, Requirements, Installation
678 @section Installing the code
680 @cindex installation
682 The Buildbot is installed using the standard python @code{distutils}
683 module. After unpacking the tarball, the process is:
685 @example
686 python setup.py build
687 python setup.py install
688 @end example
690 where the install step may need to be done as root. This will put the
691 bulk of the code in somewhere like
692 /usr/lib/python2.3/site-packages/buildbot . It will also install the
693 @code{buildbot} command-line tool in /usr/bin/buildbot.
695 To test this, shift to a different directory (like /tmp), and run:
697 @example
698 buildbot --version
699 @end example
701 If it shows you the versions of Buildbot and Twisted, the install went
702 ok. If it says @code{no such command} or it gets an @code{ImportError}
703 when it tries to load the libaries, then something went wrong.
704 @code{pydoc buildbot} is another useful diagnostic tool.
706 Windows users will find these files in other places. You will need to
707 make sure that python can find the libraries, and will probably find
708 it convenient to have @code{buildbot} on your PATH.
710 If you wish, you can run the buildbot unit test suite like this:
712 @example
713 PYTHONPATH=. trial buildbot.test
714 @end example
716 This should run up to 192 tests, depending upon what VC tools you have
717 installed. On my desktop machine it takes about five minutes to
718 complete. Nothing should fail, a few might be skipped. If any of the
719 tests fail, you should stop and investigate the cause before
720 continuing the installation process, as it will probably be easier to
721 track down the bug early.
723 If you cannot or do not wish to install the buildbot into a site-wide
724 location like @file{/usr} or @file{/usr/local}, you can also install
725 it into the account's home directory. Do the install command like
726 this:
728 @example
729 python setup.py install --home=~
730 @end example
732 That will populate @file{~/lib/python} and create
733 @file{~/bin/buildbot}. Make sure this lib directory is on your
734 @code{PYTHONPATH}.
737 @node Creating a buildmaster, Upgrading an Existing Buildmaster, Installing the code, Installation
738 @section Creating a buildmaster
740 As you learned earlier (@pxref{System Architecture}), the buildmaster
741 runs on a central host (usually one that is publically visible, so
742 everybody can check on the status of the project), and controls all
743 aspects of the buildbot system. Let us call this host
744 @code{buildbot.example.org}.
746 You may wish to create a separate user account for the buildmaster,
747 perhaps named @code{buildmaster}. This can help keep your personal
748 configuration distinct from that of the buildmaster and is useful if
749 you have to use a mail-based notification system (@pxref{Change
750 Sources}). However, the Buildbot will work just fine with your regular
751 user account.
753 You need to choose a directory for the buildmaster, called the
754 @code{basedir}. This directory will be owned by the buildmaster, which
755 will use configuration files therein, and create status files as it
756 runs. @file{~/Buildbot} is a likely value. If you run multiple
757 buildmasters in the same account, or if you run both masters and
758 slaves, you may want a more distinctive name like
759 @file{~/Buildbot/master/gnomovision} or
760 @file{~/Buildmasters/fooproject}. If you are using a separate user
761 account, this might just be @file{~buildmaster/masters/fooproject}.
763 Once you've picked a directory, use the @command{buildbot
764 create-master} command to create the directory and populate it with
765 startup files:
767 @example
768 buildbot create-master @var{basedir}
769 @end example
771 You will need to create a configuration file (@pxref{Configuration})
772 before starting the buildmaster. Most of the rest of this manual is
773 dedicated to explaining how to do this. A sample configuration file is
774 placed in the working directory, named @file{master.cfg.sample}, which
775 can be copied to @file{master.cfg} and edited to suit your purposes.
777 (Internal details: This command creates a file named
778 @file{buildbot.tac} that contains all the state necessary to create
779 the buildmaster. Twisted has a tool called @code{twistd} which can use
780 this .tac file to create and launch a buildmaster instance. twistd
781 takes care of logging and daemonization (running the program in the
782 background). @file{/usr/bin/buildbot} is a front end which runs twistd
783 for you.)
785 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
786 installed. This can be used as the basis for customized daemon startup,
787 @xref{Launching the daemons}.
789 @node Upgrading an Existing Buildmaster, Creating a buildslave, Creating a buildmaster, Installation
790 @section Upgrading an Existing Buildmaster
792 If you have just installed a new version of the Buildbot code, and you
793 have buildmasters that were created using an older version, you'll
794 need to upgrade these buildmasters before you can use them. The
795 upgrade process adds and modifies files in the buildmaster's base
796 directory to make it compatible with the new code.
798 @example
799 buildbot upgrade-master @var{basedir}
800 @end example
802 This command will also scan your @file{master.cfg} file for
803 incompatbilities (by loading it and printing any errors or deprecation
804 warnings that occur). Each buildbot release tries to be compatible
805 with configurations that worked cleanly (i.e. without deprecation
806 warnings) on the previous release: any functions or classes that are
807 to be removed will first be deprecated in a release, to give users a
808 chance to start using their replacement.
810 The 0.7.6 release introduced the @file{public_html/} directory, which
811 contains @file{index.html} and other files served by the
812 @code{WebStatus} and @code{Waterfall} status displays. The
813 @code{upgrade-master} command will create these files if they do not
814 already exist. It will not modify existing copies, but it will write a
815 new copy in e.g. @file{index.html.new} if the new version differs from
816 the version that already exists.
818 The @code{upgrade-master} command is idempotent. It is safe to run it
819 multiple times. After each upgrade of the buildbot code, you should
820 use @code{upgrade-master} on all your buildmasters.
823 @node Creating a buildslave, Launching the daemons, Upgrading an Existing Buildmaster, Installation
824 @section Creating a buildslave
826 Typically, you will be adding a buildslave to an existing buildmaster,
827 to provide additional architecture coverage. The buildbot
828 administrator will give you several pieces of information necessary to
829 connect to the buildmaster. You should also be somewhat familiar with
830 the project being tested, so you can troubleshoot build problems
831 locally.
833 The buildbot exists to make sure that the project's stated ``how to
834 build it'' process actually works. To this end, the buildslave should
835 run in an environment just like that of your regular developers.
836 Typically the project build process is documented somewhere
837 (@file{README}, @file{INSTALL}, etc), in a document that should
838 mention all library dependencies and contain a basic set of build
839 instructions. This document will be useful as you configure the host
840 and account in which the buildslave runs.
842 Here's a good checklist for setting up a buildslave:
844 @enumerate
845 @item
846 Set up the account
848 It is recommended (although not mandatory) to set up a separate user
849 account for the buildslave. This account is frequently named
850 @code{buildbot} or @code{buildslave}. This serves to isolate your
851 personal working environment from that of the slave's, and helps to
852 minimize the security threat posed by letting possibly-unknown
853 contributors run arbitrary code on your system. The account should
854 have a minimum of fancy init scripts.
856 @item
857 Install the buildbot code
859 Follow the instructions given earlier (@pxref{Installing the code}).
860 If you use a separate buildslave account, and you didn't install the
861 buildbot code to a shared location, then you will need to install it
862 with @code{--home=~} for each account that needs it.
864 @item
865 Set up the host
867 Make sure the host can actually reach the buildmaster. Usually the
868 buildmaster is running a status webserver on the same machine, so
869 simply point your web browser at it and see if you can get there.
870 Install whatever additional packages or libraries the project's
871 INSTALL document advises. (or not: if your buildslave is supposed to
872 make sure that building without optional libraries still works, then
873 don't install those libraries).
875 Again, these libraries don't necessarily have to be installed to a
876 site-wide shared location, but they must be available to your build
877 process. Accomplishing this is usually very specific to the build
878 process, so installing them to @file{/usr} or @file{/usr/local} is
879 usually the best approach.
881 @item
882 Test the build process
884 Follow the instructions in the INSTALL document, in the buildslave's
885 account. Perform a full CVS (or whatever) checkout, configure, make,
886 run tests, etc. Confirm that the build works without manual fussing.
887 If it doesn't work when you do it by hand, it will be unlikely to work
888 when the buildbot attempts to do it in an automated fashion.
890 @item
891 Choose a base directory
893 This should be somewhere in the buildslave's account, typically named
894 after the project which is being tested. The buildslave will not touch
895 any file outside of this directory. Something like @file{~/Buildbot}
896 or @file{~/Buildslaves/fooproject} is appropriate.
898 @item
899 Get the buildmaster host/port, botname, and password
901 When the buildbot admin configures the buildmaster to accept and use
902 your buildslave, they will provide you with the following pieces of
903 information:
905 @itemize @bullet
906 @item
907 your buildslave's name
908 @item
909 the password assigned to your buildslave
910 @item
911 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
912 @end itemize
914 @item
915 Create the buildslave
917 Now run the 'buildbot' command as follows:
919 @example
920 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
921 @end example
923 This will create the base directory and a collection of files inside,
924 including the @file{buildbot.tac} file that contains all the
925 information you passed to the @code{buildbot} command.
927 @item
928 Fill in the hostinfo files
930 When it first connects, the buildslave will send a few files up to the
931 buildmaster which describe the host that it is running on. These files
932 are presented on the web status display so that developers have more
933 information to reproduce any test failures that are witnessed by the
934 buildbot. There are sample files in the @file{info} subdirectory of
935 the buildbot's base directory. You should edit these to correctly
936 describe you and your host.
938 @file{BASEDIR/info/admin} should contain your name and email address.
939 This is the ``buildslave admin address'', and will be visible from the
940 build status page (so you may wish to munge it a bit if
941 address-harvesting spambots are a concern).
943 @file{BASEDIR/info/host} should be filled with a brief description of
944 the host: OS, version, memory size, CPU speed, versions of relevant
945 libraries installed, and finally the version of the buildbot code
946 which is running the buildslave.
948 If you run many buildslaves, you may want to create a single
949 @file{~buildslave/info} file and share it among all the buildslaves
950 with symlinks.
952 @end enumerate
954 @menu
955 * Buildslave Options::          
956 @end menu
958 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
959 @subsection Buildslave Options
961 There are a handful of options you might want to use when creating the
962 buildslave with the @command{buildbot create-slave <options> DIR <params>}
963 command. You can type @command{buildbot create-slave --help} for a summary.
964 To use these, just include them on the @command{buildbot create-slave}
965 command line, like this:
967 @example
968 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
969 @end example
971 @table @code
972 @item --usepty
973 This is a boolean flag that tells the buildslave whether to launch
974 child processes in a PTY (the default) or with regular pipes. The
975 advantage of using a PTY is that ``grandchild'' processes are more
976 likely to be cleaned up if the build is interrupted or times out
977 (since it enables the use of a ``process group'' in which all child
978 processes will be placed). The disadvantages: some forms of Unix have
979 problems with PTYs, some of your unit tests may behave differently
980 when run under a PTY (generally those which check to see if they are
981 being run interactively), and PTYs will merge the stdout and stderr
982 streams into a single output stream (which means the red-vs-black
983 coloring in the logfiles will be lost). If you encounter problems, you
984 can add @code{--usepty=0} to disable the use of PTYs. Note that
985 windows buildslaves never use PTYs.
987 @item --umask
988 This is a string (generally an octal representation of an integer)
989 which will cause the buildslave process' ``umask'' value to be set
990 shortly after initialization. The ``twistd'' daemonization utility
991 forces the umask to 077 at startup (which means that all files created
992 by the buildslave or its child processes will be unreadable by any
993 user other than the buildslave account). If you want build products to
994 be readable by other accounts, you can add @code{--umask=022} to tell
995 the buildslave to fix the umask after twistd clobbers it. If you want
996 build products to be @emph{writable} by other accounts too, use
997 @code{--umask=000}, but this is likely to be a security problem.
999 @item --keepalive
1000 This is a number that indicates how frequently ``keepalive'' messages
1001 should be sent from the buildslave to the buildmaster, expressed in
1002 seconds. The default (600) causes a message to be sent to the
1003 buildmaster at least once every 10 minutes. To set this to a lower
1004 value, use e.g. @code{--keepalive=120}.
1006 If the buildslave is behind a NAT box or stateful firewall, these
1007 messages may help to keep the connection alive: some NAT boxes tend to
1008 forget about a connection if it has not been used in a while. When
1009 this happens, the buildmaster will think that the buildslave has
1010 disappeared, and builds will time out. Meanwhile the buildslave will
1011 not realize than anything is wrong.
1013 @end table
1016 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
1017 @section Launching the daemons
1019 Both the buildmaster and the buildslave run as daemon programs. To
1020 launch them, pass the working directory to the @code{buildbot}
1021 command:
1023 @example
1024 buildbot start @var{BASEDIR}
1025 @end example
1027 This command will start the daemon and then return, so normally it
1028 will not produce any output. To verify that the programs are indeed
1029 running, look for a pair of files named @file{twistd.log} and
1030 @file{twistd.pid} that should be created in the working directory.
1031 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
1033 When the buildslave connects to the buildmaster, new directories will
1034 start appearing in its base directory. The buildmaster tells the slave
1035 to create a directory for each Builder which will be using that slave.
1036 All build operations are performed within these directories: CVS
1037 checkouts, compiles, and tests.
1039 Once you get everything running, you will want to arrange for the
1040 buildbot daemons to be started at boot time. One way is to use
1041 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
1042 @@reboot syntax is understood by Vixie cron, which is the flavor
1043 usually provided with linux systems. Other unices may have a cron that
1044 doesn't understand @@reboot}:
1046 @example
1047 @@reboot buildbot start @var{BASEDIR}
1048 @end example
1050 When you run @command{crontab} to set this up, remember to do it as
1051 the buildmaster or buildslave account! If you add this to your crontab
1052 when running as your regular account (or worse yet, root), then the
1053 daemon will run as the wrong user, quite possibly as one with more
1054 authority than you intended to provide.
1056 It is important to remember that the environment provided to cron jobs
1057 and init scripts can be quite different that your normal runtime.
1058 There may be fewer environment variables specified, and the PATH may
1059 be shorter than usual. It is a good idea to test out this method of
1060 launching the buildslave by using a cron job with a time in the near
1061 future, with the same command, and then check @file{twistd.log} to
1062 make sure the slave actually started correctly. Common problems here
1063 are for @file{/usr/local} or @file{~/bin} to not be on your
1064 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
1065 Sometimes @code{HOME} is messed up too.
1067 To modify the way the daemons are started (perhaps you want to set
1068 some environment variables first, or perform some cleanup each time),
1069 you can create a file named @file{Makefile.buildbot} in the base
1070 directory. When the @file{buildbot} front-end tool is told to
1071 @command{start} the daemon, and it sees this file (and
1072 @file{/usr/bin/make} exists), it will do @command{make -f
1073 Makefile.buildbot start} instead of its usual action (which involves
1074 running @command{twistd}). When the buildmaster or buildslave is
1075 installed, a @file{Makefile.sample} is created which implements the
1076 same behavior as the the @file{buildbot} tool uses, so if you want to
1077 customize the process, just copy @file{Makefile.sample} to
1078 @file{Makefile.buildbot} and edit it as necessary.
1080 @node Logfiles, Shutdown, Launching the daemons, Installation
1081 @section Logfiles
1083 @cindex logfiles
1085 While a buildbot daemon runs, it emits text to a logfile, named
1086 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1087 to watch the command output as it runs.
1089 The buildmaster will announce any errors with its configuration file
1090 in the logfile, so it is a good idea to look at the log at startup
1091 time to check for any problems. Most buildmaster activities will cause
1092 lines to be added to the log.
1094 @node Shutdown, Maintenance, Logfiles, Installation
1095 @section Shutdown
1097 To stop a buildmaster or buildslave manually, use:
1099 @example
1100 buildbot stop @var{BASEDIR}
1101 @end example
1103 This simply looks for the @file{twistd.pid} file and kills whatever
1104 process is identified within.
1106 At system shutdown, all processes are sent a @code{SIGKILL}. The
1107 buildmaster and buildslave will respond to this by shutting down
1108 normally.
1110 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1111 config file. Of course, this only works on unix-like systems with
1112 signal support, and won't work on Windows. The following shortcut is
1113 available:
1115 @example
1116 buildbot reconfig @var{BASEDIR}
1117 @end example
1119 When you update the Buildbot code to a new release, you will need to
1120 restart the buildmaster and/or buildslave before it can take advantage
1121 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1122 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1123 use the @code{restart} shortcut, which does both steps for you:
1125 @example
1126 buildbot restart @var{BASEDIR}
1127 @end example
1129 There are certain configuration changes that are not handled cleanly
1130 by @code{buildbot reconfig}. If this occurs, @code{buildbot restart}
1131 is a more robust tool to fully switch over to the new configuration.
1133 @code{buildbot restart} may also be used to start a stopped Buildbot
1134 instance. This behaviour is useful when writing scripts that stop, start
1135 and restart Buildbot.
1138 @node Maintenance, Troubleshooting, Shutdown, Installation
1139 @section Maintenance
1141 It is a good idea to check the buildmaster's status page every once in
1142 a while, to see if your buildslave is still online. Eventually the
1143 buildbot will probably be enhanced to send you email (via the
1144 @file{info/admin} email address) when the slave has been offline for
1145 more than a few hours.
1147 If you find you can no longer provide a buildslave to the project, please
1148 let the project admins know, so they can put out a call for a
1149 replacement.
1151 The Buildbot records status and logs output continually, each time a
1152 build is performed. The status tends to be small, but the build logs
1153 can become quite large. Each build and log are recorded in a separate
1154 file, arranged hierarchically under the buildmaster's base directory.
1155 To prevent these files from growing without bound, you should
1156 periodically delete old build logs. A simple cron job to delete
1157 anything older than, say, two weeks should do the job. The only trick
1158 is to leave the @file{buildbot.tac} and other support files alone, for
1159 which find's @code{-mindepth} argument helps skip everything in the
1160 top directory. You can use something like the following:
1162 @example
1163 @@weekly cd BASEDIR && find . -mindepth 2 -type f -mtime +14 -exec rm @{@} \;
1164 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1165 @end example
1167 @node Troubleshooting,  , Maintenance, Installation
1168 @section Troubleshooting
1170 Here are a few hints on diagnosing common problems.
1172 @menu
1173 * Starting the buildslave::     
1174 * Connecting to the buildmaster::  
1175 * Forcing Builds::              
1176 @end menu
1178 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1179 @subsection Starting the buildslave
1181 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1182 @file{/bin/bash}), and tilde expansion is not always performed in such
1183 commands. You may want to use explicit paths, because the @code{PATH}
1184 is usually quite short and doesn't include anything set by your
1185 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1186 you've installed buildbot (or other python libraries) to an unusual
1187 location, you may need to add a @code{PYTHONPATH} specification (note
1188 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1189 itself). Sometimes it is safer to fully-specify everything:
1191 @example
1192 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1193 @end example
1195 Take the time to get the @@reboot job set up. Otherwise, things will work
1196 fine for a while, but the first power outage or system reboot you have will
1197 stop the buildslave with nothing but the cries of sorrowful developers to
1198 remind you that it has gone away.
1200 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1201 @subsection Connecting to the buildmaster
1203 If the buildslave cannot connect to the buildmaster, the reason should
1204 be described in the @file{twistd.log} logfile. Some common problems
1205 are an incorrect master hostname or port number, or a mistyped bot
1206 name or password. If the buildslave loses the connection to the
1207 master, it is supposed to attempt to reconnect with an
1208 exponentially-increasing backoff. Each attempt (and the time of the
1209 next attempt) will be logged. If you get impatient, just manually stop
1210 and re-start the buildslave.
1212 When the buildmaster is restarted, all slaves will be disconnected,
1213 and will attempt to reconnect as usual. The reconnect time will depend
1214 upon how long the buildmaster is offline (i.e. how far up the
1215 exponential backoff curve the slaves have travelled). Again,
1216 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1217 speed up the process.
1219 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1220 @subsection Forcing Builds
1222 From the buildmaster's main status web page, you can force a build to
1223 be run on your build slave. Figure out which column is for a builder
1224 that runs on your slave, click on that builder's name, and the page
1225 that comes up will have a ``Force Build'' button. Fill in the form,
1226 hit the button, and a moment later you should see your slave's
1227 @file{twistd.log} filling with commands being run. Using @code{pstree}
1228 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1229 run by the buildslave. Note that the same web page should also show
1230 the @file{admin} and @file{host} information files that you configured
1231 earlier.
1233 @node Concepts, Configuration, Installation, Top
1234 @chapter Concepts
1236 This chapter defines some of the basic concepts that the Buildbot
1237 uses. You'll need to understand how the Buildbot sees the world to
1238 configure it properly.
1240 @menu
1241 * Version Control Systems::     
1242 * Schedulers::                  
1243 * BuildSet::                    
1244 * BuildRequest::                
1245 * Builder::                     
1246 * Users::                       
1247 * Build Properties::            
1248 @end menu
1250 @node Version Control Systems, Schedulers, Concepts, Concepts
1251 @section Version Control Systems
1253 @cindex Version Control
1255 These source trees come from a Version Control System of some kind.
1256 CVS and Subversion are two popular ones, but the Buildbot supports
1257 others. All VC systems have some notion of an upstream
1258 @code{repository} which acts as a server@footnote{except Darcs, but
1259 since the Buildbot never modifies its local source tree we can ignore
1260 the fact that Darcs uses a less centralized model}, from which clients
1261 can obtain source trees according to various parameters. The VC
1262 repository provides source trees of various projects, for different
1263 branches, and from various points in time. The first thing we have to
1264 do is to specify which source tree we want to get.
1266 @menu
1267 * Generalizing VC Systems::     
1268 * Source Tree Specifications::  
1269 * How Different VC Systems Specify Sources::  
1270 * Attributes of Changes::       
1271 @end menu
1273 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1274 @subsection Generalizing VC Systems
1276 For the purposes of the Buildbot, we will try to generalize all VC
1277 systems as having repositories that each provide sources for a variety
1278 of projects. Each project is defined as a directory tree with source
1279 files. The individual files may each have revisions, but we ignore
1280 that and treat the project as a whole as having a set of revisions
1281 (CVS is really the only VC system still in widespread use that has
1282 per-file revisions.. everything modern has moved to atomic tree-wide
1283 changesets). Each time someone commits a change to the project, a new
1284 revision becomes available. These revisions can be described by a
1285 tuple with two items: the first is a branch tag, and the second is
1286 some kind of revision stamp or timestamp. Complex projects may have
1287 multiple branch tags, but there is always a default branch. The
1288 timestamp may be an actual timestamp (such as the -D option to CVS),
1289 or it may be a monotonically-increasing transaction number (such as
1290 the change number used by SVN and P4, or the revision number used by
1291 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1292 systems provide more complexity than this: in particular the local
1293 views that P4 and ClearCase can assemble out of various source
1294 directories are more complex than we're prepared to take advantage of
1295 here}. The SHA1 revision ID used by Monotone, Mercurial, and Git is
1296 also a kind of revision stamp, in that it specifies a unique copy of
1297 the source tree, as does a Darcs ``context'' file.
1299 When we aren't intending to make any changes to the sources we check out
1300 (at least not any that need to be committed back upstream), there are two
1301 basic ways to use a VC system:
1303 @itemize @bullet
1304 @item
1305 Retrieve a specific set of source revisions: some tag or key is used
1306 to index this set, which is fixed and cannot be changed by subsequent
1307 developers committing new changes to the tree. Releases are built from
1308 tagged revisions like this, so that they can be rebuilt again later
1309 (probably with controlled modifications).
1310 @item
1311 Retrieve the latest sources along a specific branch: some tag is used
1312 to indicate which branch is to be used, but within that constraint we want
1313 to get the latest revisions.
1314 @end itemize
1316 Build personnel or CM staff typically use the first approach: the
1317 build that results is (ideally) completely specified by the two
1318 parameters given to the VC system: repository and revision tag. This
1319 gives QA and end-users something concrete to point at when reporting
1320 bugs. Release engineers are also reportedly fond of shipping code that
1321 can be traced back to a concise revision tag of some sort.
1323 Developers are more likely to use the second approach: each morning
1324 the developer does an update to pull in the changes committed by the
1325 team over the last day. These builds are not easy to fully specify: it
1326 depends upon exactly when you did a checkout, and upon what local
1327 changes the developer has in their tree. Developers do not normally
1328 tag each build they produce, because there is usually significant
1329 overhead involved in creating these tags. Recreating the trees used by
1330 one of these builds can be a challenge. Some VC systems may provide
1331 implicit tags (like a revision number), while others may allow the use
1332 of timestamps to mean ``the state of the tree at time X'' as opposed
1333 to a tree-state that has been explicitly marked.
1335 The Buildbot is designed to help developers, so it usually works in
1336 terms of @emph{the latest} sources as opposed to specific tagged
1337 revisions. However, it would really prefer to build from reproducible
1338 source trees, so implicit revisions are used whenever possible.
1340 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1341 @subsection Source Tree Specifications
1343 So for the Buildbot's purposes we treat each VC system as a server
1344 which can take a list of specifications as input and produce a source
1345 tree as output. Some of these specifications are static: they are
1346 attributes of the builder and do not change over time. Others are more
1347 variable: each build will have a different value. The repository is
1348 changed over time by a sequence of Changes, each of which represents a
1349 single developer making changes to some set of files. These Changes
1350 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1351 violates this assumption of cumulative Changes, but in most situations
1352 the changes don't occur frequently enough for this to be a significant
1353 problem}.
1355 For normal builds, the Buildbot wants to get well-defined source trees
1356 that contain specific Changes, and exclude other Changes that may have
1357 occurred after the desired ones. We assume that the Changes arrive at
1358 the buildbot (through one of the mechanisms described in @pxref{Change
1359 Sources}) in the same order in which they are committed to the
1360 repository. The Buildbot waits for the tree to become ``stable''
1361 before initiating a build, for two reasons. The first is that
1362 developers frequently make multiple related commits in quick
1363 succession, even when the VC system provides ways to make atomic
1364 transactions involving multiple files at the same time. Running a
1365 build in the middle of these sets of changes would use an inconsistent
1366 set of source files, and is likely to fail (and is certain to be less
1367 useful than a build which uses the full set of changes). The
1368 tree-stable-timer is intended to avoid these useless builds that
1369 include some of the developer's changes but not all. The second reason
1370 is that some VC systems (i.e. CVS) do not provide repository-wide
1371 transaction numbers, so that timestamps are the only way to refer to
1372 a specific repository state. These timestamps may be somewhat
1373 ambiguous, due to processing and notification delays. By waiting until
1374 the tree has been stable for, say, 10 minutes, we can choose a
1375 timestamp from the middle of that period to use for our source
1376 checkout, and then be reasonably sure that any clock-skew errors will
1377 not cause the build to be performed on an inconsistent set of source
1378 files.
1380 The Schedulers always use the tree-stable-timer, with a timeout that
1381 is configured to reflect a reasonable tradeoff between build latency
1382 and change frequency. When the VC system provides coherent
1383 repository-wide revision markers (such as Subversion's revision
1384 numbers, or in fact anything other than CVS's timestamps), the
1385 resulting Build is simply performed against a source tree defined by
1386 that revision marker. When the VC system does not provide this, a
1387 timestamp from the middle of the tree-stable period is used to
1388 generate the source tree@footnote{this @code{checkoutDelay} defaults
1389 to half the tree-stable timer, but it can be overridden with an
1390 argument to the Source Step}.
1392 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1393 @subsection How Different VC Systems Specify Sources
1395 For CVS, the static specifications are @code{repository} and
1396 @code{module}. In addition to those, each build uses a timestamp (or
1397 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1398 (which defaults to HEAD). These parameters collectively specify a set
1399 of sources from which a build may be performed.
1401 @uref{http://subversion.tigris.org, Subversion} combines the
1402 repository, module, and branch into a single @code{Subversion URL}
1403 parameter. Within that scope, source checkouts can be specified by a
1404 numeric @code{revision number} (a repository-wide
1405 monotonically-increasing marker, such that each transaction that
1406 changes the repository is indexed by a different revision number), or
1407 a revision timestamp. When branches are used, the repository and
1408 module form a static @code{baseURL}, while each build has a
1409 @code{revision number} and a @code{branch} (which defaults to a
1410 statically-specified @code{defaultBranch}). The @code{baseURL} and
1411 @code{branch} are simply concatenated together to derive the
1412 @code{svnurl} to use for the checkout.
1414 @uref{http://www.perforce.com/, Perforce} is similar. The server
1415 is specified through a @code{P4PORT} parameter. Module and branch
1416 are specified in a single depot path, and revisions are
1417 depot-wide. When branches are used, the @code{p4base} and
1418 @code{defaultBranch} are concatenated together to produce the depot
1419 path.
1421 @uref{http://wiki.gnuarch.org/, Arch} and
1422 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1423 URL, as well as a @code{version} which is kind of like a branch name.
1424 Arch uses the word @code{archive} to represent the repository. Arch
1425 lets you push changes from one archive to another, removing the strict
1426 centralization required by CVS and SVN. It retains the distinction
1427 between repository and working directory that most other VC systems
1428 use. For complex multi-module directory structures, Arch has a
1429 built-in @code{build config} layer with which the checkout process has
1430 two steps. First, an initial bootstrap checkout is performed to
1431 retrieve a set of build-config files. Second, one of these files is
1432 used to figure out which archives/modules should be used to populate
1433 subdirectories of the initial checkout.
1435 Builders which use Arch and Bazaar therefore have a static archive
1436 @code{url}, and a default ``branch'' (which is a string that specifies
1437 a complete category--branch--version triple). Each build can have its
1438 own branch (the category--branch--version string) to override the
1439 default, as well as a revision number (which is turned into a
1440 --patch-NN suffix when performing the checkout).
1443 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1444 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1445 sort of repository-vs-workspace model as Arch, but the repository data
1446 can either be stored inside the working directory or kept elsewhere
1447 (either on the same machine or on an entirely different machine). For
1448 the purposes of Buildbot (which never commits changes), the repository
1449 is specified with a URL and a revision number.
1451 The most common way to obtain read-only access to a bzr tree is via
1452 HTTP, simply by making the repository visible through a web server
1453 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1454 process has sufficient privileges to access them. Higher performance
1455 can be obtained by running a special Bazaar-specific server. None of
1456 these matter to the buildbot: the repository URL just has to match the
1457 kind of server being used. The @code{repoURL} argument provides the
1458 location of the repository.
1460 Branches are expressed as subdirectories of the main central
1461 repository, which means that if branches are being used, the BZR step
1462 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1463 the @code{repoURL} argument.
1466 @uref{http://darcs.net/, Darcs} doesn't really have the
1467 notion of a single master repository. Nor does it really have
1468 branches. In Darcs, each working directory is also a repository, and
1469 there are operations to push and pull patches from one of these
1470 @code{repositories} to another. For the Buildbot's purposes, all you
1471 need to do is specify the URL of a repository that you want to build
1472 from. The build slave will then pull the latest patches from that
1473 repository and build them. Multiple branches are implemented by using
1474 multiple repositories (possibly living on the same server).
1476 Builders which use Darcs therefore have a static @code{repourl} which
1477 specifies the location of the repository. If branches are being used,
1478 the source Step is instead configured with a @code{baseURL} and a
1479 @code{defaultBranch}, and the two strings are simply concatenated
1480 together to obtain the repository's URL. Each build then has a
1481 specific branch which replaces @code{defaultBranch}, or just uses the
1482 default one. Instead of a revision number, each build can have a
1483 ``context'', which is a string that records all the patches that are
1484 present in a given tree (this is the output of @command{darcs changes
1485 --context}, and is considerably less concise than, e.g. Subversion's
1486 revision number, but the patch-reordering flexibility of Darcs makes
1487 it impossible to provide a shorter useful specification).
1489 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1490 each branch is stored in a separate repository. The @code{repourl},
1491 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1492 same way as with Darcs. The ``revision'', however, is the hash
1493 identifier returned by @command{hg identify}.
1495 @uref{http://git.or.cz/, Git} also follows a decentralized model, and
1496 each repository can have several branches and tags. The source Step is
1497 configured with a static @code{repourl} which specifies the location
1498 of the repository. In addition, an optional @code{branch} parameter
1499 can be specified to check out code from a specific branch instead of
1500 the default ``master'' branch. The ``revision'' is specified as a SHA1
1501 hash as returned by e.g. @command{git rev-parse}. No attempt is made
1502 to ensure that the specified revision is actually a subset of the
1503 specified branch.
1506 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1507 @subsection Attributes of Changes
1509 @heading Who
1511 Each Change has a @code{who} attribute, which specifies which
1512 developer is responsible for the change. This is a string which comes
1513 from a namespace controlled by the VC repository. Frequently this
1514 means it is a username on the host which runs the repository, but not
1515 all VC systems require this (Arch, for example, uses a fully-qualified
1516 @code{Arch ID}, which looks like an email address, as does Darcs).
1517 Each StatusNotifier will map the @code{who} attribute into something
1518 appropriate for their particular means of communication: an email
1519 address, an IRC handle, etc.
1521 @heading Files
1523 It also has a list of @code{files}, which are just the tree-relative
1524 filenames of any files that were added, deleted, or modified for this
1525 Change. These filenames are used by the @code{isFileImportant}
1526 function (in the Scheduler) to decide whether it is worth triggering a
1527 new build or not, e.g. the function could use
1528 @code{filename.endswith(".c")} to only run a build if a C file were
1529 checked in. Certain BuildSteps can also use the list of changed files
1530 to run a more targeted series of tests, e.g. the
1531 @code{python_twisted.Trial} step can run just the unit tests that
1532 provide coverage for the modified .py files instead of running the
1533 full test suite.
1535 @heading Comments
1537 The Change also has a @code{comments} attribute, which is a string
1538 containing any checkin comments.
1540 @heading Revision
1542 Each Change can have a @code{revision} attribute, which describes how
1543 to get a tree with a specific state: a tree which includes this Change
1544 (and all that came before it) but none that come after it. If this
1545 information is unavailable, the @code{.revision} attribute will be
1546 @code{None}. These revisions are provided by the ChangeSource, and
1547 consumed by the @code{computeSourceRevision} method in the appropriate
1548 @code{step.Source} class.
1550 @table @samp
1551 @item CVS
1552 @code{revision} is an int, seconds since the epoch
1553 @item SVN
1554 @code{revision} is an int, a transation number (r%d)
1555 @item Darcs
1556 @code{revision} is a large string, the output of @code{darcs changes --context}
1557 @item Mercurial
1558 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1559 @item Arch/Bazaar
1560 @code{revision} is the full revision ID (ending in --patch-%d)
1561 @item P4
1562 @code{revision} is an int, the transaction number
1563 @item Git
1564 @code{revision} is a short string (a SHA1 hash), the output of e.g.
1565 @code{git rev-parse}
1566 @end table
1568 @heading Branches
1570 The Change might also have a @code{branch} attribute. This indicates
1571 that all of the Change's files are in the same named branch. The
1572 Schedulers get to decide whether the branch should be built or not.
1574 For VC systems like CVS, Arch, Monotone, and Git, the @code{branch}
1575 name is unrelated to the filename. (that is, the branch name and the
1576 filename inhabit unrelated namespaces). For SVN, branches are
1577 expressed as subdirectories of the repository, so the file's
1578 ``svnurl'' is a combination of some base URL, the branch name, and the
1579 filename within the branch. (In a sense, the branch name and the
1580 filename inhabit the same namespace). Darcs branches are
1581 subdirectories of a base URL just like SVN. Mercurial branches are the
1582 same as Darcs.
1584 @table @samp
1585 @item CVS
1586 branch='warner-newfeature', files=['src/foo.c']
1587 @item SVN
1588 branch='branches/warner-newfeature', files=['src/foo.c']
1589 @item Darcs
1590 branch='warner-newfeature', files=['src/foo.c']
1591 @item Mercurial
1592 branch='warner-newfeature', files=['src/foo.c']
1593 @item Arch/Bazaar
1594 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1595 @item Git
1596 branch='warner-newfeature', files=['src/foo.c']
1597 @end table
1599 @heading Links
1601 @c TODO: who is using 'links'? how is it being used?
1603 Finally, the Change might have a @code{links} list, which is intended
1604 to provide a list of URLs to a @emph{viewcvs}-style web page that
1605 provides more detail for this Change, perhaps including the full file
1606 diffs.
1609 @node Schedulers, BuildSet, Version Control Systems, Concepts
1610 @section Schedulers
1612 @cindex Scheduler
1614 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1615 gets a copy of every incoming Change. The Schedulers are responsible
1616 for deciding when Builds should be run. Some Buildbot installations
1617 might have a single Scheduler, while others may have several, each for
1618 a different purpose.
1620 For example, a ``quick'' scheduler might exist to give immediate
1621 feedback to developers, hoping to catch obvious problems in the code
1622 that can be detected quickly. These typically do not run the full test
1623 suite, nor do they run on a wide variety of platforms. They also
1624 usually do a VC update rather than performing a brand-new checkout
1625 each time. You could have a ``quick'' scheduler which used a 30 second
1626 timeout, and feeds a single ``quick'' Builder that uses a VC
1627 @code{mode='update'} setting.
1629 A separate ``full'' scheduler would run more comprehensive tests a
1630 little while later, to catch more subtle problems. This scheduler
1631 would have a longer tree-stable-timer, maybe 30 minutes, and would
1632 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1633 @code{'clobber'}, or @code{'export'}).
1635 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1636 made by the Scheduler. Dependencies are also implemented here.
1637 Periodic builds (those which are run every N seconds rather than after
1638 new Changes arrive) are triggered by a special @code{Periodic}
1639 Scheduler subclass. The default Scheduler class can also be told to
1640 watch for specific branches, ignoring Changes on other branches. This
1641 may be useful if you have a trunk and a few release branches which
1642 should be tracked, but when you don't want to have the Buildbot pay
1643 attention to several dozen private user branches.
1645 Some Schedulers may trigger builds for other reasons, other than
1646 recent Changes. For example, a Scheduler subclass could connect to a
1647 remote buildmaster and watch for builds of a library to succeed before
1648 triggering a local build that uses that library.
1650 Each Scheduler creates and submits @code{BuildSet} objects to the
1651 @code{BuildMaster}, which is then responsible for making sure the
1652 individual @code{BuildRequests} are delivered to the target
1653 @code{Builders}.
1655 @code{Scheduler} instances are activated by placing them in the
1656 @code{c['schedulers']} list in the buildmaster config file. Each
1657 Scheduler has a unique name.
1660 @node BuildSet, BuildRequest, Schedulers, Concepts
1661 @section BuildSet
1663 @cindex BuildSet
1665 A @code{BuildSet} is the name given to a set of Builds that all
1666 compile/test the same version of the tree on multiple Builders. In
1667 general, all these component Builds will perform the same sequence of
1668 Steps, using the same source code, but on different platforms or
1669 against a different set of libraries.
1671 The @code{BuildSet} is tracked as a single unit, which fails if any of
1672 the component Builds have failed, and therefore can succeed only if
1673 @emph{all} of the component Builds have succeeded. There are two kinds
1674 of status notification messages that can be emitted for a BuildSet:
1675 the @code{firstFailure} type (which fires as soon as we know the
1676 BuildSet will fail), and the @code{Finished} type (which fires once
1677 the BuildSet has completely finished, regardless of whether the
1678 overall set passed or failed).
1680 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1681 (branch, revision, changes, patch), some of which may be None, and a
1682 list of Builders on which it is to be run. They are then given to the
1683 BuildMaster, which is responsible for creating a separate
1684 @code{BuildRequest} for each Builder.
1686 There are a couple of different likely values for the
1687 @code{SourceStamp}:
1689 @table @code
1690 @item (revision=None, changes=[CHANGES], patch=None)
1691 This is a @code{SourceStamp} used when a series of Changes have
1692 triggered a build. The VC step will attempt to check out a tree that
1693 contains CHANGES (and any changes that occurred before CHANGES, but
1694 not any that occurred after them).
1696 @item (revision=None, changes=None, patch=None)
1697 This builds the most recent code on the default branch. This is the
1698 sort of @code{SourceStamp} that would be used on a Build that was
1699 triggered by a user request, or a Periodic scheduler. It is also
1700 possible to configure the VC Source Step to always check out the
1701 latest sources rather than paying attention to the Changes in the
1702 SourceStamp, which will result in same behavior as this.
1704 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1705 This builds the most recent code on the given BRANCH. Again, this is
1706 generally triggered by a user request or Periodic build.
1708 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1709 This checks out the tree at the given revision REV, then applies a
1710 patch (using @code{patch -pLEVEL <DIFF}). The @ref{try} feature uses
1711 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1712 step is bypassed.
1714 @end table
1716 The buildmaster is responsible for turning the @code{BuildSet} into a
1717 set of @code{BuildRequest} objects and queueing them on the
1718 appropriate Builders.
1721 @node BuildRequest, Builder, BuildSet, Concepts
1722 @section BuildRequest
1724 @cindex BuildRequest
1726 A @code{BuildRequest} is a request to build a specific set of sources
1727 on a single specific Builder. Each Builder runs the
1728 @code{BuildRequest} as soon as it can (i.e. when an associated
1729 buildslave becomes free).
1731 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1732 The actual process of running the build (the series of Steps that will
1733 be executed) is implemented by the @code{Build} object. In this future
1734 this might be changed, to have the @code{Build} define @emph{what}
1735 gets built, and a separate @code{BuildProcess} (provided by the
1736 Builder) to define @emph{how} it gets built.
1738 The @code{BuildRequest} may be mergeable with other compatible
1739 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1740 will generally be mergeable. Builds that are triggered by user
1741 requests are generally not, unless they are multiple requests to build
1742 the @emph{latest sources} of the same branch.
1744 @node Builder, Users, BuildRequest, Concepts
1745 @section Builder
1747 @cindex Builder
1749 The @code{Builder} is a long-lived object which controls all Builds of
1750 a given type. Each one is created when the config file is first
1751 parsed, and lives forever (or rather until it is removed from the
1752 config file). It mediates the connections to the buildslaves that do
1753 all the work, and is responsible for creating the @code{Build} objects
1754 that decide @emph{how} a build is performed (i.e., which steps are
1755 executed in what order).
1757 Each @code{Builder} gets a unique name, and the path name of a
1758 directory where it gets to do all its work (there is a
1759 buildmaster-side directory for keeping status information, as well as
1760 a buildslave-side directory where the actual checkout/compile/test
1761 commands are executed). It also gets a @code{BuildFactory}, which is
1762 responsible for creating new @code{Build} instances: because the
1763 @code{Build} instance is what actually performs each build, choosing
1764 the @code{BuildFactory} is the way to specify what happens each time a
1765 build is done.
1767 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1768 A @code{Builder} which is used to perform OS-X builds (as opposed to
1769 Linux or Solaris builds) should naturally be associated with an
1770 OS-X-based buildslave.
1772 A @code{Builder} may be given a set of environments variables to be used
1773 in its @pxref{ShellCommand}s. These variables will override anything in the
1774 buildslave's environment. Variables passed directly to a ShellCommand will
1775 override variables of the same name passed to the Builder.
1777 For example, if you a pool of identical slaves it is often easier to manage
1778 variables like PATH from Buildbot rather than manually editing it inside of
1779 the slaves' environment.
1781 @example
1782 f = factory.BuildFactory
1783 f.addStep(ShellCommand(
1784               command=['bash', './configure']))
1785 f.addStep(Compile())
1787 c['builders'] = [
1788   @{'name': 'test', 'slavenames': ['slave1', 'slave2', 'slave3', 'slave4',
1789                                    'slave5', 'slave6'],
1790     'builddir': 'test', 'factory': f',
1791     'env': {'PATH': '/opt/local/bin:/opt/app/bin:/usr/local/bin:/usr/bin'}}
1793 @end example
1795 @node Users, Build Properties, Builder, Concepts
1796 @section Users
1798 @cindex Users
1800 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1801 the world consists of a set of developers, each of whom can be
1802 described by a couple of simple attributes. These developers make
1803 changes to the source code, causing builds which may succeed or fail.
1805 Each developer is primarily known through the source control system. Each
1806 Change object that arrives is tagged with a @code{who} field that
1807 typically gives the account name (on the repository machine) of the user
1808 responsible for that change. This string is the primary key by which the
1809 User is known, and is displayed on the HTML status pages and in each Build's
1810 ``blamelist''.
1812 To do more with the User than just refer to them, this username needs to
1813 be mapped into an address of some sort. The responsibility for this mapping
1814 is left up to the status module which needs the address. The core code knows
1815 nothing about email addresses or IRC nicknames, just user names.
1817 @menu
1818 * Doing Things With Users::     
1819 * Email Addresses::             
1820 * IRC Nicknames::               
1821 * Live Status Clients::         
1822 @end menu
1824 @node Doing Things With Users, Email Addresses, Users, Users
1825 @subsection Doing Things With Users
1827 Each Change has a single User who is responsible for that Change. Most
1828 Builds have a set of Changes: the Build represents the first time these
1829 Changes have been built and tested by the Buildbot. The build has a
1830 ``blamelist'' that consists of a simple union of the Users responsible
1831 for all the Build's Changes.
1833 The Build provides (through the IBuildStatus interface) a list of Users
1834 who are ``involved'' in the build. For now this is equal to the
1835 blamelist, but in the future it will be expanded to include a ``build
1836 sheriff'' (a person who is ``on duty'' at that time and responsible for
1837 watching over all builds that occur during their shift), as well as
1838 per-module owners who simply want to keep watch over their domain (chosen by
1839 subdirectory or a regexp matched against the filenames pulled out of the
1840 Changes). The Involved Users are those who probably have an interest in the
1841 results of any given build.
1843 In the future, Buildbot will acquire the concept of ``Problems'',
1844 which last longer than builds and have beginnings and ends. For example, a
1845 test case which passed in one build and then failed in the next is a
1846 Problem. The Problem lasts until the test case starts passing again, at
1847 which point the Problem is said to be ``resolved''.
1849 If there appears to be a code change that went into the tree at the
1850 same time as the test started failing, that Change is marked as being
1851 resposible for the Problem, and the user who made the change is added
1852 to the Problem's ``Guilty'' list. In addition to this user, there may
1853 be others who share responsibility for the Problem (module owners,
1854 sponsoring developers). In addition to the Responsible Users, there
1855 may be a set of Interested Users, who take an interest in the fate of
1856 the Problem.
1858 Problems therefore have sets of Users who may want to be kept aware of
1859 the condition of the problem as it changes over time. If configured, the
1860 Buildbot can pester everyone on the Responsible list with increasing
1861 harshness until the problem is resolved, with the most harshness reserved
1862 for the Guilty parties themselves. The Interested Users may merely be told
1863 when the problem starts and stops, as they are not actually responsible for
1864 fixing anything.
1866 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1867 @subsection Email Addresses
1869 The @code{buildbot.status.mail.MailNotifier} class
1870 (@pxref{MailNotifier}) provides a status target which can send email
1871 about the results of each build. It accepts a static list of email
1872 addresses to which each message should be delivered, but it can also
1873 be configured to send mail to the Build's Interested Users. To do
1874 this, it needs a way to convert User names into email addresses.
1876 For many VC systems, the User Name is actually an account name on the
1877 system which hosts the repository. As such, turning the name into an
1878 email address is a simple matter of appending
1879 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1880 (for example the preferred email address may be at ``project.org''
1881 despite the repository host being named ``cvs.project.org''), and some
1882 VC systems have full separation between the concept of a user and that
1883 of an account on the repository host (like Perforce). Some systems
1884 (like Arch) put a full contact email address in every change.
1886 To convert these names to addresses, the MailNotifier uses an EmailLookup
1887 object. This provides a .getAddress method which accepts a name and
1888 (eventually) returns an address. The default @code{MailNotifier}
1889 module provides an EmailLookup which simply appends a static string,
1890 configurable when the notifier is created. To create more complex behaviors
1891 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1892 determine a preferred address for the developer), provide a different object
1893 as the @code{lookup} argument.
1895 In the future, when the Problem mechanism has been set up, the Buildbot
1896 will need to send mail to arbitrary Users. It will do this by locating a
1897 MailNotifier-like object among all the buildmaster's status targets, and
1898 asking it to send messages to various Users. This means the User-to-address
1899 mapping only has to be set up once, in your MailNotifier, and every email
1900 message the buildbot emits will take advantage of it.
1902 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1903 @subsection IRC Nicknames
1905 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1906 provides a status target which can announce the results of each build. It
1907 also provides an interactive interface by responding to online queries
1908 posted in the channel or sent as private messages.
1910 In the future, the buildbot can be configured map User names to IRC
1911 nicknames, to watch for the recent presence of these nicknames, and to
1912 deliver build status messages to the interested parties. Like
1913 @code{MailNotifier} does for email addresses, the @code{IRC} object
1914 will have an @code{IRCLookup} which is responsible for nicknames. The
1915 mapping can be set up statically, or it can be updated by online users
1916 themselves (by claiming a username with some kind of ``buildbot: i am
1917 user warner'' commands).
1919 Once the mapping is established, the rest of the buildbot can ask the
1920 @code{IRC} object to send messages to various users. It can report on
1921 the likelihood that the user saw the given message (based upon how long the
1922 user has been inactive on the channel), which might prompt the Problem
1923 Hassler logic to send them an email message instead.
1925 @node Live Status Clients,  , IRC Nicknames, Users
1926 @subsection Live Status Clients
1928 The Buildbot also offers a PB-based status client interface which can
1929 display real-time build status in a GUI panel on the developer's desktop.
1930 This interface is normally anonymous, but it could be configured to let the
1931 buildmaster know @emph{which} developer is using the status client. The
1932 status client could then be used as a message-delivery service, providing an
1933 alternative way to deliver low-latency high-interruption messages to the
1934 developer (like ``hey, you broke the build'').
1936 @node Build Properties,  , Users, Concepts
1937 @section Build Properties
1938 @cindex Properties
1940 Each build has a set of ``Build Properties'', which can be used by its
1941 BuildStep to modify their actions.  These properties, in the form of
1942 key-value pairs, provide a general framework for dynamically altering
1943 the behavior of a build based on its circumstances.
1945 Properties come from a number of places:
1946 @itemize
1947 @item global configuration --
1948 These properties apply to all builds.
1949 @item schedulers --
1950 A scheduler can specify properties available to all the builds it 
1951 starts.
1952 @item buildslaves --
1953 A buildslave can pass properties on to the builds it performs.
1954 @item builds --
1955 A build automatically sets a number of properties on itself.
1956 @item steps --
1957 Steps of a build can set properties that are available to subsequent
1958 steps.  In particular, source steps set a number of properties.
1959 @end itemize
1961 Properties are very flexible, and can be used to implement all manner
1962 of functionality.  Here are some examples:
1964 Most Source steps record the revision that they checked out in
1965 the @code{got_revision} property.  A later step could use this
1966 property to specify the name of a fully-built tarball, dropped in an
1967 easily-acessible directory for later testing.
1969 Some projects want to perform nightly builds as well as in response
1970 to committed changes.  Such a project would run two schedulers,
1971 both pointing to the same set of builders, but could provide an
1972 @code{is_nightly} property so that steps can distinguish the nightly
1973 builds, perhaps to run more resource-intensive tests.
1975 Some projects have different build processes on different systems.
1976 Rather than create a build factory for each slave, the steps can use
1977 buildslave properties to identify the unique aspects of each slave
1978 and adapt the build process dynamically.
1980 @node Configuration, Getting Source Code Changes, Concepts, Top
1981 @chapter Configuration
1983 @cindex Configuration
1985 The buildbot's behavior is defined by the ``config file'', which
1986 normally lives in the @file{master.cfg} file in the buildmaster's base
1987 directory (but this can be changed with an option to the
1988 @code{buildbot create-master} command). This file completely specifies
1989 which Builders are to be run, which slaves they should use, how
1990 Changes should be tracked, and where the status information is to be
1991 sent. The buildmaster's @file{buildbot.tac} file names the base
1992 directory; everything else comes from the config file.
1994 A sample config file was installed for you when you created the
1995 buildmaster, but you will need to edit it before your buildbot will do
1996 anything useful.
1998 This chapter gives an overview of the format of this file and the
1999 various sections in it. You will need to read the later chapters to
2000 understand how to fill in each section properly.
2002 @menu
2003 * Config File Format::          
2004 * Loading the Config File::     
2005 * Testing the Config File::     
2006 * Defining the Project::        
2007 * Change Sources and Schedulers::  
2008 * Setting the slaveport::       
2009 * Buildslave Specifiers::       
2010 * Defining Global Properties::  
2011 * Defining Builders::           
2012 * Defining Status Targets::     
2013 * Debug options::               
2014 @end menu
2016 @node Config File Format, Loading the Config File, Configuration, Configuration
2017 @section Config File Format
2019 The config file is, fundamentally, just a piece of Python code which
2020 defines a dictionary named @code{BuildmasterConfig}, with a number of
2021 keys that are treated specially. You don't need to know Python to do
2022 basic configuration, though, you can just copy the syntax of the
2023 sample file. If you @emph{are} comfortable writing Python code,
2024 however, you can use all the power of a full programming language to
2025 achieve more complicated configurations.
2027 The @code{BuildmasterConfig} name is the only one which matters: all
2028 other names defined during the execution of the file are discarded.
2029 When parsing the config file, the Buildmaster generally compares the
2030 old configuration with the new one and performs the minimum set of
2031 actions necessary to bring the buildbot up to date: Builders which are
2032 not changed are left untouched, and Builders which are modified get to
2033 keep their old event history.
2035 Basic Python syntax: comments start with a hash character (``#''),
2036 tuples are defined with @code{(parenthesis, pairs)}, arrays are
2037 defined with @code{[square, brackets]}, tuples and arrays are mostly
2038 interchangeable. Dictionaries (data structures which map ``keys'' to
2039 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
2040 'key2': 'value2'@} }. Function calls (and object instantiation) can use
2041 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
2043 The config file starts with a series of @code{import} statements,
2044 which make various kinds of Steps and Status targets available for
2045 later use. The main @code{BuildmasterConfig} dictionary is created,
2046 then it is populated with a variety of keys. These keys are broken
2047 roughly into the following sections, each of which is documented in
2048 the rest of this chapter:
2050 @itemize @bullet
2051 @item
2052 Project Definitions
2053 @item
2054 Change Sources / Schedulers
2055 @item
2056 Slaveport
2057 @item
2058 Buildslave Configuration
2059 @item
2060 Builders / Interlocks
2061 @item
2062 Status Targets
2063 @item
2064 Debug options
2065 @end itemize
2067 The config file can use a few names which are placed into its namespace:
2069 @table @code
2070 @item basedir
2071 the base directory for the buildmaster. This string has not been
2072 expanded, so it may start with a tilde. It needs to be expanded before
2073 use. The config file is located in
2074 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
2076 @end table
2079 @node Loading the Config File, Testing the Config File, Config File Format, Configuration
2080 @section Loading the Config File
2082 The config file is only read at specific points in time. It is first
2083 read when the buildmaster is launched. Once it is running, there are
2084 various ways to ask it to reload the config file. If you are on the
2085 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
2086 it: the @command{buildbot} tool has a shortcut for this:
2088 @example
2089 buildbot reconfig @var{BASEDIR}
2090 @end example
2092 This command will show you all of the lines from @file{twistd.log}
2093 that relate to the reconfiguration. If there are any problems during
2094 the config-file reload, they will be displayed in these lines.
2096 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
2097 ``Reload .cfg'' button which will also trigger a reload. In the
2098 future, there will be other ways to accomplish this step (probably a
2099 password-protected button on the web page, as well as a privileged IRC
2100 command).
2102 When reloading the config file, the buildmaster will endeavor to
2103 change as little as possible about the running system. For example,
2104 although old status targets may be shut down and new ones started up,
2105 any status targets that were not changed since the last time the
2106 config file was read will be left running and untouched. Likewise any
2107 Builders which have not been changed will be left running. If a
2108 Builder is modified (say, the build process is changed) while a Build
2109 is currently running, that Build will keep running with the old
2110 process until it completes. Any previously queued Builds (or Builds
2111 which get queued after the reconfig) will use the new process.
2113 @node Testing the Config File, Defining the Project, Loading the Config File, Configuration
2114 @section Testing the Config File
2116 To verify that the config file is well-formed and contains no
2117 deprecated or invalid elements, use the ``checkconfig'' command:
2119 @example
2120 % buildbot checkconfig master.cfg
2121 Config file is good!
2122 @end example
2124 If the config file has deprecated features (perhaps because you've
2125 upgraded the buildmaster and need to update the config file to match),
2126 they will be announced by checkconfig. In this case, the config file
2127 will work, but you should really remove the deprecated items and use
2128 the recommended replacements instead:
2130 @example
2131 % buildbot checkconfig master.cfg
2132 /usr/lib/python2.4/site-packages/buildbot/master.py:559: DeprecationWarning: c['sources'] is
2133 deprecated as of 0.7.6 and will be removed by 0.8.0 . Please use c['change_source'] instead.
2134   warnings.warn(m, DeprecationWarning)
2135 Config file is good!
2136 @end example
2138 If the config file is simply broken, that will be caught too:
2140 @example
2141 % buildbot checkconfig master.cfg
2142 Traceback (most recent call last):
2143   File "/usr/lib/python2.4/site-packages/buildbot/scripts/runner.py", line 834, in doCheckConfig
2144     ConfigLoader(configFile)
2145   File "/usr/lib/python2.4/site-packages/buildbot/scripts/checkconfig.py", line 31, in __init__
2146     self.loadConfig(configFile)
2147   File "/usr/lib/python2.4/site-packages/buildbot/master.py", line 480, in loadConfig
2148     exec f in localDict
2149   File "/home/warner/BuildBot/master/foolscap/master.cfg", line 90, in ?
2150     c[bogus] = "stuff"
2151 NameError: name 'bogus' is not defined
2152 @end example
2155 @node Defining the Project, Change Sources and Schedulers, Testing the Config File, Configuration
2156 @section Defining the Project
2158 There are a couple of basic settings that you use to tell the buildbot
2159 what project it is working on. This information is used by status
2160 reporters to let users find out more about the codebase being
2161 exercised by this particular Buildbot installation.
2163 @example
2164 c['projectName'] = "Buildbot"
2165 c['projectURL'] = "http://buildbot.sourceforge.net/"
2166 c['buildbotURL'] = "http://localhost:8010/"
2167 @end example
2169 @bcindex c['projectName']
2170 @code{projectName} is a short string will be used to describe the
2171 project that this buildbot is working on. For example, it is used as
2172 the title of the waterfall HTML page. 
2174 @bcindex c['projectURL']
2175 @code{projectURL} is a string that gives a URL for the project as a
2176 whole. HTML status displays will show @code{projectName} as a link to
2177 @code{projectURL}, to provide a link from buildbot HTML pages to your
2178 project's home page.
2180 @bcindex c['buildbotURL']
2181 The @code{buildbotURL} string should point to the location where the
2182 buildbot's internal web server (usually the @code{html.Waterfall}
2183 page) is visible. This typically uses the port number set when you
2184 create the @code{Waterfall} object: the buildbot needs your help to
2185 figure out a suitable externally-visible host name.
2187 When status notices are sent to users (either by email or over IRC),
2188 @code{buildbotURL} will be used to create a URL to the specific build
2189 or problem that they are being notified about. It will also be made
2190 available to queriers (over IRC) who want to find out where to get
2191 more information about this buildbot.
2194 @node Change Sources and Schedulers, Setting the slaveport, Defining the Project, Configuration
2195 @section Change Sources and Schedulers
2197 @bcindex c['sources']
2198 @bcindex c['change_source']
2200 The @code{c['change_source']} key is the ChangeSource
2201 instance@footnote{To be precise, it is an object or a list of objects
2202 which all implement the @code{buildbot.interfaces.IChangeSource}
2203 Interface. It is unusual to have multiple ChangeSources, so this key
2204 accepts either a single ChangeSource or a sequence of them.} that
2205 defines how the buildmaster learns about source code changes. More
2206 information about what goes here is available in @xref{Getting Source
2207 Code Changes}.
2209 @example
2210 from buildbot.changes.pb import PBChangeSource
2211 c['change_source'] = PBChangeSource()
2212 @end example
2213 @bcindex c['schedulers']
2215 (note: in buildbot-0.7.5 and earlier, this key was named
2216 @code{c['sources']}, and required a list. @code{c['sources']} is
2217 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2218 future release).
2220 @code{c['schedulers']} is a list of Scheduler instances, each
2221 of which causes builds to be started on a particular set of
2222 Builders. The two basic Scheduler classes you are likely to start
2223 with are @code{Scheduler} and @code{Periodic}, but you can write a
2224 customized subclass to implement more complicated build scheduling.
2226 Scheduler arguments
2227 should always be specified by name (as keyword arguments), to allow
2228 for future expansion:
2230 @example
2231 sched = Scheduler(name="quick", builderNames=['lin', 'win'])
2232 @end example
2234 All schedulers have several arguments in common:  
2236 @table @code
2237 @item name
2239 Each Scheduler must have a unique name. This is used in status
2240 displays, and is also available in the build property @code{scheduler}.
2242 @item builderNames
2244 This is the set of builders which this scheduler should trigger, specified
2245 as a list of names (strings).
2247 @item properties
2248 @cindex Properties
2250 This is a dictionary specifying properties that will be transmitted
2251 to all builds started by this scheduler.
2253 @end table
2255 Here is a brief catalog of the available Scheduler types. All these
2256 Schedulers are classes in @code{buildbot.scheduler}, and the
2257 docstrings there are the best source of documentation on the arguments
2258 taken by each one.
2260 @menu
2261 * Scheduler Scheduler::         
2262 * AnyBranchScheduler::          
2263 * Dependent Scheduler::         
2264 * Periodic Scheduler::          
2265 * Nightly Scheduler::           
2266 * Try Schedulers::              
2267 * Triggerable Scheduler::       
2268 @end menu
2270 @node Scheduler Scheduler, AnyBranchScheduler, Change Sources and Schedulers, Change Sources and Schedulers
2271 @subsection Scheduler Scheduler
2272 @slindex buildbot.scheduler.Scheduler
2274 This is the original and still most popular Scheduler class. It follows
2275 exactly one branch, and starts a configurable tree-stable-timer after
2276 each change on that branch. When the timer expires, it starts a build
2277 on some set of Builders. The Scheduler accepts a @code{fileIsImportant}
2278 function which can be used to ignore some Changes if they do not
2279 affect any ``important'' files.
2281 The arguments to this scheduler are:
2283 @table @code
2284 @item name
2286 @item builderNames
2288 @item properties
2290 @item branch
2291 This Scheduler will pay attention to a single branch, ignoring Changes
2292 that occur on other branches. Setting @code{branch} equal to the
2293 special value of @code{None} means it should only pay attention to
2294 the default branch. Note that @code{None} is a keyword, not a string,
2295 so you want to use @code{None} and not @code{"None"}.
2297 @item treeStableTimer
2298 The Scheduler will wait for this many seconds before starting the
2299 build. If new changes are made during this interval, the timer will be
2300 restarted, so really the build will be started after a change and then
2301 after this many seconds of inactivity.
2303 @item fileIsImportant
2304 A callable which takes one argument, a Change instance, and returns
2305 @code{True} if the change is worth building, and @code{False} if
2306 it is not.  Unimportant Changes are accumulated until the build is
2307 triggered by an important change.  The default value of None means
2308 that all Changes are important.
2309 @end table
2311 Example:
2313 @example
2314 from buildbot import scheduler
2315 quick = scheduler.Scheduler(name="quick", 
2316                     branch=None, 
2317                     treeStableTimer=60,
2318                     builderNames=["quick-linux", "quick-netbsd"])
2319 full = scheduler.Scheduler(name="full", 
2320                     branch=None,
2321                     treeStableTimer=5*60,
2322                     builderNames=["full-linux", "full-netbsd", "full-OSX"])
2323 c['schedulers'] = [quick, full]
2324 @end example
2326 In this example, the two ``quick'' builders are triggered 60 seconds
2327 after the tree has been changed. The ``full'' builds do not run quite
2328 so quickly (they wait 5 minutes), so hopefully if the quick builds
2329 fail due to a missing file or really simple typo, the developer can
2330 discover and fix the problem before the full builds are started. Both
2331 Schedulers only pay attention to the default branch: any changes
2332 on other branches are ignored by these Schedulers. Each Scheduler
2333 triggers a different set of Builders, referenced by name.
2335 @node AnyBranchScheduler, Dependent Scheduler, Scheduler Scheduler, Change Sources and Schedulers
2336 @subsection AnyBranchScheduler
2337 @slindex buildbot.scheduler.AnyBranchScheduler
2339 This scheduler uses a tree-stable-timer like the default one, but
2340 follows multiple branches at once. Each branch gets a separate timer.
2342 The arguments to this scheduler are:
2344 @table @code
2345 @item name
2347 @item builderNames
2349 @item properties
2351 @item branches
2352 This Scheduler will pay attention to any number of branches, ignoring
2353 Changes that occur on other branches. Branches are specified just as
2354 for the @code{Scheduler} class.
2356 @item treeStableTimer
2357 The Scheduler will wait for this many seconds before starting the
2358 build. If new changes are made during this interval, the timer will be
2359 restarted, so really the build will be started after a change and then
2360 after this many seconds of inactivity.
2362 @item fileIsImportant
2363 A callable which takes one argument, a Change instance, and returns
2364 @code{True} if the change is worth building, and @code{False} if
2365 it is not.  Unimportant Changes are accumulated until the build is
2366 triggered by an important change.  The default value of None means
2367 that all Changes are important.
2368 @end table
2370 @node Dependent Scheduler, Periodic Scheduler, AnyBranchScheduler, Change Sources and Schedulers
2371 @subsection Dependent Scheduler
2372 @cindex Dependent
2373 @cindex Dependencies
2374 @slindex buildbot.scheduler.Dependent
2376 It is common to wind up with one kind of build which should only be
2377 performed if the same source code was successfully handled by some
2378 other kind of build first. An example might be a packaging step: you
2379 might only want to produce .deb or RPM packages from a tree that was
2380 known to compile successfully and pass all unit tests. You could put
2381 the packaging step in the same Build as the compile and testing steps,
2382 but there might be other reasons to not do this (in particular you
2383 might have several Builders worth of compiles/tests, but only wish to
2384 do the packaging once). Another example is if you want to skip the
2385 ``full'' builds after a failing ``quick'' build of the same source
2386 code. Or, if one Build creates a product (like a compiled library)
2387 that is used by some other Builder, you'd want to make sure the
2388 consuming Build is run @emph{after} the producing one.
2390 You can use ``Dependencies'' to express this relationship
2391 to the Buildbot. There is a special kind of Scheduler named
2392 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2393 for builds to complete successfully (on all of its Builders). Each time
2394 that happens, the same source code (i.e. the same @code{SourceStamp})
2395 will be used to start a new set of builds, on a different set of
2396 Builders. This ``downstream'' scheduler doesn't pay attention to
2397 Changes at all. It only pays attention to the upstream scheduler.
2399 If the build fails on any of the Builders in the upstream set,
2400 the downstream builds will not fire.  Note that, for SourceStamps
2401 generated by a ChangeSource, the @code{revision} is None, meaning HEAD.
2402 If any changes are committed between the time the upstream scheduler
2403 begins its build and the time the dependent scheduler begins its
2404 build, then those changes will be included in the downstream build.
2405 See the @pxref{Triggerable Scheduler} for a more flexible dependency
2406 mechanism that can avoid this problem.
2408 The arguments to this scheduler are:
2410 @table @code
2411 @item name
2413 @item builderNames
2415 @item properties
2417 @item upstream
2418 The upstream scheduler to watch.  Note that this is an ``instance'',
2419 not the name of the scheduler.
2420 @end table
2422 Example:
2424 @example
2425 from buildbot import scheduler
2426 tests = scheduler.Scheduler("just-tests", None, 5*60,
2427                             ["full-linux", "full-netbsd", "full-OSX"])
2428 package = scheduler.Dependent("build-package",
2429                               tests, # upstream scheduler -- no quotes!
2430                               ["make-tarball", "make-deb", "make-rpm"])
2431 c['schedulers'] = [tests, package]
2432 @end example
2434 @node Periodic Scheduler, Nightly Scheduler, Dependent Scheduler, Change Sources and Schedulers
2435 @subsection Periodic Scheduler
2436 @slindex buildbot.scheduler.Periodic
2438 This simple scheduler just triggers a build every N seconds.
2440 The arguments to this scheduler are:
2442 @table @code
2443 @item name
2445 @item builderNames
2447 @item properties
2449 @item periodicBuildTimer
2450 The time, in seconds, after which to start a build.
2451 @end table
2453 Example:
2455 @example
2456 from buildbot import scheduler
2457 nightly = scheduler.Periodic(name="nightly",
2458                 builderNames=["full-solaris"],
2459                 periodicBuildTimer=24*60*60)
2460 c['schedulers'] = [nightly]
2461 @end example
2463 The Scheduler in this example just runs the full solaris build once
2464 per day. Note that this Scheduler only lets you control the time
2465 between builds, not the absolute time-of-day of each Build, so this
2466 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2467 depending upon when it was first activated.
2469 @node Nightly Scheduler, Try Schedulers, Periodic Scheduler, Change Sources and Schedulers
2470 @subsection Nightly Scheduler
2471 @slindex buildbot.scheduler.Nightly
2473 This is highly configurable periodic build scheduler, which triggers
2474 a build at particular times of day, week, month, or year. The
2475 configuration syntax is very similar to the well-known @code{crontab}
2476 format, in which you provide values for minute, hour, day, and month
2477 (some of which can be wildcards), and a build is triggered whenever
2478 the current time matches the given constraints. This can run a build
2479 every night, every morning, every weekend, alternate Thursdays,
2480 on your boss's birthday, etc.
2482 Pass some subset of @code{minute}, @code{hour}, @code{dayOfMonth},
2483 @code{month}, and @code{dayOfWeek}; each may be a single number or
2484 a list of valid values. The builds will be triggered whenever the
2485 current time matches these values. Wildcards are represented by a
2486 '*' string. All fields default to a wildcard except 'minute', so
2487 with no fields this defaults to a build every hour, on the hour.
2488 The full list of parameters is:
2490 @table @code
2491 @item name
2493 @item builderNames
2495 @item properties
2497 @item branch
2498 The branch to build, just as for @code{Scheduler}.
2500 @item minute
2501 The minute of the hour on which to start the build.  This defaults
2502 to 0, meaning an hourly build.
2504 @item hour
2505 The hour of the day on which to start the build, in 24-hour notation.
2506 This defaults to *, meaning every hour.
2508 @item month
2509 The month in which to start the build, with January = 1.  This defaults
2510 to *, meaning every month.
2512 @item dayOfWeek
2513 The day of the week to start a build, with Monday = 0.  This defauls
2514 to *, meaning every day of the week.
2515 @end table
2517 For example, the following master.cfg clause will cause a build to be
2518 started every night at 3:00am:
2520 @example
2521 s = scheduler.Nightly(name='nightly',
2522         builderNames=['builder1', 'builder2'],
2523         hour=3, 
2524         minute=0)
2525 @end example
2527 This scheduler will perform a build each monday morning at 6:23am and
2528 again at 8:23am:
2530 @example
2531 s = scheduler.Nightly(name='BeforeWork',
2532          builderNames=['builder1'],
2533          dayOfWeek=0,
2534          hour=[6,8],
2535          minute=23)
2536 @end example
2538 The following runs a build every two hours, using Python's @code{range}
2539 function:
2541 @example
2542 s = Nightly(name='every2hours',
2543         builderNames=['builder1'],
2544         hour=range(0, 24, 2))
2545 @end example
2547 Finally, this example will run only on December 24th:
2549 @example
2550 s = Nightly(name='SleighPreflightCheck',
2551         builderNames=['flying_circuits', 'radar'],
2552         month=12,
2553         dayOfMonth=24,
2554         hour=12,
2555         minute=0)
2556 @end example
2558 @node Try Schedulers, Triggerable Scheduler, Nightly Scheduler, Change Sources and Schedulers
2559 @subsection Try Schedulers
2560 @slindex buildbot.scheduler.Try_Jobdir
2561 @slindex buildbot.scheduler.Try_Userpass
2563 This scheduler allows developers to use the @code{buildbot try}
2564 command to trigger builds of code they have not yet committed. See
2565 @ref{try} for complete details.
2567 Two implementations are available: @code{Try_Jobdir} and
2568 @code{Try_Userpass}.  The former monitors a job directory, specified
2569 by the @code{jobdir} parameter, while the latter listens for PB 
2570 connections on a specific @code{port}, and authenticates against
2571 @code{userport}.
2573 @node Triggerable Scheduler,  , Try Schedulers, Change Sources and Schedulers
2574 @subsection Triggerable Scheduler
2575 @cindex Triggers
2576 @slindex buildbot.scheduler.Triggerable
2578 The @code{Triggerable} scheduler waits to be triggered by a Trigger
2579 step (see @ref{Triggering Schedulers}) in another build. That step
2580 can optionally wait for the scheduler's builds to complete. This
2581 provides two advantages over Dependent schedulers. First, the same
2582 scheduler can be triggered from multiple builds. Second, the ability
2583 to wait for a Triggerable's builds to complete provides a form of
2584 "subroutine call", where one or more builds can "call" a scheduler
2585 to perform some work for them, perhaps on other buildslaves.
2587 The parameters are just the basics:
2589 @table @code
2590 @item name
2591 @item builderNames
2592 @item properties
2593 @end table
2595 This class is only useful in conjunction with the @code{Trigger} step.
2596 Here is a fully-worked example:
2598 @example
2599 from buildbot import scheduler
2600 from buildbot.steps import trigger
2602 checkin = scheduler.Scheduler(name="checkin",
2603             branch=None,
2604             treeStableTimer=5*60,
2605             builderNames=["checkin"])
2606 nightly = scheduler.Nightly(name='nightly',
2607             builderNames=['nightly'],
2608             hour=3, 
2609             minute=0)
2611 mktarball = scheduler.Triggerable(name="mktarball",
2612                 builderNames=["mktarball"])
2613 build = scheduler.Triggerable(name="build-all-platforms",
2614                 builderNames=["build-all-platforms"])
2615 test = scheduler.Triggerable(name="distributed-test",
2616                 builderNames=["distributed-test"])
2617 package = scheduler.Triggerable(name="package-all-platforms",
2618                 builderNames=["package-all-platforms"])
2620 c['schedulers'] = [checkin, nightly, build, test, package]
2622 # on checkin, make a tarball, build it, and test it
2623 checkin_factory = factory.BuildFactory()
2624 f.addStep(trigger.Trigger('mktarball', schedulers=['mktarball'],
2625                                        waitForFinish=True)
2626 f.addStep(trigger.Trigger('build', schedulers=['build-all-platforms'],
2627                                    waitForFinish=True)
2628 f.addStep(trigger.Trigger('test', schedulers=['distributed-test'],
2629                                   waitForFinish=True)
2631 # and every night, make a tarball, build it, and package it
2632 nightly_factory = factory.BuildFactory()
2633 f.addStep(trigger.Trigger('mktarball', schedulers=['mktarball'],
2634                                        waitForFinish=True)
2635 f.addStep(trigger.Trigger('build', schedulers=['build-all-platforms'],
2636                                    waitForFinish=True)
2637 f.addStep(trigger.Trigger('package', schedulers=['package-all-platforms'],
2638                                      waitForFinish=True)
2639 @end example
2641 @node Setting the slaveport, Buildslave Specifiers, Change Sources and Schedulers, Configuration
2642 @section Setting the slaveport
2644 @bcindex c['slavePortnum']
2646 The buildmaster will listen on a TCP port of your choosing for
2647 connections from buildslaves. It can also use this port for
2648 connections from remote Change Sources, status clients, and debug
2649 tools. This port should be visible to the outside world, and you'll
2650 need to tell your buildslave admins about your choice.
2652 It does not matter which port you pick, as long it is externally
2653 visible, however you should probably use something larger than 1024,
2654 since most operating systems don't allow non-root processes to bind to
2655 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2656 box of some sort, you may have to configure your firewall to permit
2657 inbound connections to this port.
2659 @example
2660 c['slavePortnum'] = 10000
2661 @end example
2663 @code{c['slavePortnum']} is a @emph{strports} specification string,
2664 defined in the @code{twisted.application.strports} module (try
2665 @command{pydoc twisted.application.strports} to get documentation on
2666 the format). This means that you can have the buildmaster listen on a
2667 localhost-only port by doing:
2669 @example
2670 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2671 @end example
2673 This might be useful if you only run buildslaves on the same machine,
2674 and they are all configured to contact the buildmaster at
2675 @code{localhost:10000}.
2678 @node Buildslave Specifiers, Defining Global Properties, Setting the slaveport, Configuration
2679 @section Buildslave Specifiers
2681 @bcindex c['slaves']
2683 The @code{c['slaves']} key is a list of known buildslaves. Each
2684 buildslave is defined by an instance of the BuildSlave class, created
2685 with two values: (slavename, slavepassword). These are the same two
2686 values that need to be provided to the buildslave administrator when
2687 they create the buildslave.
2689 The slavenames must be unique, of course. The password exists to
2690 prevent evildoers from interfering with the buildbot by inserting
2691 their own (broken) buildslaves into the system and thus displacing the
2692 real ones.
2694 Buildslaves with an unrecognized slavename or a non-matching password
2695 will be rejected when they attempt to connect, and a message
2696 describing the problem will be put in the log file (see @ref{Logfiles}).
2698 @example
2699 from buildbot.buildslave import BuildSlave
2700 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd')
2701                BuildSlave('bot-bsd', 'bsdpasswd')
2702               ]
2703 @end example
2705 @cindex Properties
2706 @code{BuildSlave} objects can also be created with an optional
2707 @code{properties} argument, a dictionary specifying properties that
2708 will be available to any builds performed on this slave.  For example:
2710 @example
2711 from buildbot.buildslave import BuildSlave
2712 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2713                     properties=@{'os':'solaris'@}),
2714               ]
2715 @end example
2717 The @code{BuildSlave} constructor can also take an optional
2718 @code{max_builds} parameter to limit the number of builds that it
2719 will execute simultaneously:
2721 @example
2722 from buildbot.buildslave import BuildSlave
2723 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2724 @end example
2726 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2727 key was used instead, and it took a list of (name, password) tuples.
2728 This key is accepted for backwards compatibility, but is deprecated as
2729 of 0.7.6 and will go away in some future release.
2731 @menu
2732 * When Buildslaves Go Missing::  
2733 @end menu
2735 @node When Buildslaves Go Missing,  , Buildslave Specifiers, Buildslave Specifiers
2736 @subsection When Buildslaves Go Missing
2738 Sometimes, the buildslaves go away. One very common reason for this is
2739 when the buildslave process is started once (manually) and left
2740 running, but then later the machine reboots and the process is not
2741 automatically restarted.
2743 If you'd like to have the administrator of the buildslave (or other
2744 people) be notified by email when the buildslave has been missing for
2745 too long, just add the @code{notify_on_missing=} argument to the
2746 @code{BuildSlave} definition:
2748 @example
2749 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2750                           notify_on_missing="bob@@example.com"),
2751               ]
2752 @end example
2754 By default, this will send email when the buildslave has been
2755 disconnected for more than one hour. Only one email per
2756 connection-loss event will be sent. To change the timeout, use
2757 @code{missing_timeout=} and give it a number of seconds (the default
2758 is 3600).
2760 You can have the buildmaster send email to multiple recipients: just
2761 provide a list of addresses instead of a single one:
2763 @example
2764 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2765                           notify_on_missing=["bob@@example.com",
2766                                              "alice@@example.org"],
2767                           missing_timeout=300, # notify after 10 minutes
2768                           ),
2769               ]
2770 @end example
2772 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2773 status target, if one is configured. This provides a way for you to
2774 control the ``from'' address of the email, as well as the relayhost
2775 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2776 configured on this buildmaster, the buildslave-missing emails will be
2777 sent using a default configuration.
2779 Note that if you want to have a MailNotifier for buildslave-missing
2780 emails but not for regular build emails, just create one with
2781 builders=[], as follows:
2783 @example
2784 from buildbot.status import mail
2785 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2786                       relayhost="smtp.example.org")
2787 c['status'].append(m)
2788 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2789                           notify_on_missing="bob@@example.com"),
2790               ]
2791 @end example
2793 @node Defining Global Properties, Defining Builders, Buildslave Specifiers, Configuration
2794 @section Defining Global Properties
2795 @bcindex c['properties']
2796 @cindex Properties
2798 The @code{'properties'} configuration key defines a dictionary
2799 of properties that will be available to all builds started by the
2800 buildmaster:
2802 @example
2803 c['properties'] = @{
2804     'Widget-version' : '1.2',
2805     'release-stage' : 'alpha'
2807 @end example
2809 @node Defining Builders, Defining Status Targets, Defining Global Properties, Configuration
2810 @section Defining Builders
2812 @bcindex c['builders']
2814 The @code{c['builders']} key is a list of dictionaries which specify
2815 the Builders. The Buildmaster runs a collection of Builders, each of
2816 which handles a single type of build (e.g. full versus quick), on a
2817 single build slave. A Buildbot which makes sure that the latest code
2818 (``HEAD'') compiles correctly across four separate architecture will
2819 have four Builders, each performing the same build but on different
2820 slaves (one per platform).
2822 Each Builder gets a separate column in the waterfall display. In
2823 general, each Builder runs independently (although various kinds of
2824 interlocks can cause one Builder to have an effect on another).
2826 Each Builder specification dictionary has several required keys:
2828 @table @code
2829 @item name
2830 This specifies the Builder's name, which is used in status
2831 reports.
2833 @item slavename
2834 This specifies which buildslave will be used by this Builder.
2835 @code{slavename} must appear in the @code{c['slaves']} list. Each
2836 buildslave can accomodate multiple Builders.
2838 @item slavenames
2839 If you provide @code{slavenames} instead of @code{slavename}, you can
2840 give a list of buildslaves which are capable of running this Builder.
2841 If multiple buildslaves are available for any given Builder, you will
2842 have some measure of redundancy: in case one slave goes offline, the
2843 others can still keep the Builder working. In addition, multiple
2844 buildslaves will allow multiple simultaneous builds for the same
2845 Builder, which might be useful if you have a lot of forced or ``try''
2846 builds taking place.
2848 If you use this feature, it is important to make sure that the
2849 buildslaves are all, in fact, capable of running the given build. The
2850 slave hosts should be configured similarly, otherwise you will spend a
2851 lot of time trying (unsuccessfully) to reproduce a failure that only
2852 occurs on some of the buildslaves and not the others. Different
2853 platforms, operating systems, versions of major programs or libraries,
2854 all these things mean you should use separate Builders.
2856 @item builddir
2857 This specifies the name of a subdirectory (under the base directory)
2858 in which everything related to this builder will be placed. On the
2859 buildmaster, this holds build status information. On the buildslave,
2860 this is where checkouts, compiles, and tests are run.
2862 @item factory
2863 This is a @code{buildbot.process.factory.BuildFactory} instance which
2864 controls how the build is performed. Full details appear in their own
2865 chapter, @xref{Build Process}. Parameters like the location of the CVS
2866 repository and the compile-time options used for the build are
2867 generally provided as arguments to the factory's constructor.
2869 @end table
2871 Other optional keys may be set on each Builder:
2873 @table @code
2875 @item category
2876 If provided, this is a string that identifies a category for the
2877 builder to be a part of. Status clients can limit themselves to a
2878 subset of the available categories. A common use for this is to add
2879 new builders to your setup (for a new module, or for a new buildslave)
2880 that do not work correctly yet and allow you to integrate them with
2881 the active builders. You can put these new builders in a test
2882 category, make your main status clients ignore them, and have only
2883 private status clients pick them up. As soon as they work, you can
2884 move them over to the active category.
2886 @end table
2889 @node Defining Status Targets, Debug options, Defining Builders, Configuration
2890 @section Defining Status Targets
2892 The Buildmaster has a variety of ways to present build status to
2893 various users. Each such delivery method is a ``Status Target'' object
2894 in the configuration's @code{status} list. To add status targets, you
2895 just append more objects to this list:
2897 @bcindex c['status']
2899 @example
2900 c['status'] = []
2902 from buildbot.status import html
2903 c['status'].append(html.Waterfall(http_port=8010))
2905 from buildbot.status import mail
2906 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
2907                       extraRecipients=["builds@@lists.example.com"],
2908                       sendToInterestedUsers=False)
2909 c['status'].append(m)
2911 from buildbot.status import words
2912 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
2913                              channels=["#example"]))
2914 @end example
2916 Status delivery has its own chapter, @xref{Status Delivery}, in which
2917 all the built-in status targets are documented.
2920 @node Debug options,  , Defining Status Targets, Configuration
2921 @section Debug options
2924 @bcindex c['debugPassword']
2925 If you set @code{c['debugPassword']}, then you can connect to the
2926 buildmaster with the diagnostic tool launched by @code{buildbot
2927 debugclient MASTER:PORT}. From this tool, you can reload the config
2928 file, manually force builds, and inject changes, which may be useful
2929 for testing your buildmaster without actually commiting changes to
2930 your repository (or before you have the Change Sources set up). The
2931 debug tool uses the same port number as the slaves do:
2932 @code{c['slavePortnum']}, and is authenticated with this password.
2934 @example
2935 c['debugPassword'] = "debugpassword"
2936 @end example
2938 @bcindex c['manhole']
2939 If you set @code{c['manhole']} to an instance of one of the classes in
2940 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
2941 and get an interactive Python shell, which may be useful for debugging
2942 buildbot internals. It is probably only useful for buildbot
2943 developers. It exposes full access to the buildmaster's account
2944 (including the ability to modify and delete files), so it should not
2945 be enabled with a weak or easily guessable password.
2947 There are three separate @code{Manhole} classes. Two of them use SSH,
2948 one uses unencrypted telnet. Two of them use a username+password
2949 combination to grant access, one of them uses an SSH-style
2950 @file{authorized_keys} file which contains a list of ssh public keys.
2952 @table @code
2953 @item manhole.AuthorizedKeysManhole
2954 You construct this with the name of a file that contains one SSH
2955 public key per line, just like @file{~/.ssh/authorized_keys}. If you
2956 provide a non-absolute filename, it will be interpreted relative to
2957 the buildmaster's base directory.
2959 @item manhole.PasswordManhole
2960 This one accepts SSH connections but asks for a username and password
2961 when authenticating. It accepts only one such pair.
2964 @item manhole.TelnetManhole
2965 This accepts regular unencrypted telnet connections, and asks for a
2966 username/password pair before providing access. Because this
2967 username/password is transmitted in the clear, and because Manhole
2968 access to the buildmaster is equivalent to granting full shell
2969 privileges to both the buildmaster and all the buildslaves (and to all
2970 accounts which then run code produced by the buildslaves), it is
2971 highly recommended that you use one of the SSH manholes instead.
2973 @end table
2975 @example
2976 # some examples:
2977 from buildbot import manhole
2978 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
2979 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
2980 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
2981 @end example
2983 The @code{Manhole} instance can be configured to listen on a specific
2984 port. You may wish to have this listening port bind to the loopback
2985 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
2986 restrict access to clients which are running on the same host.
2988 @example
2989 from buildbot.manhole import PasswordManhole
2990 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
2991 @end example
2993 To have the @code{Manhole} listen on all interfaces, use
2994 @code{"tcp:9999"} or simply 9999. This port specification uses
2995 @code{twisted.application.strports}, so you can make it listen on SSL
2996 or even UNIX-domain sockets if you want.
2998 Note that using any Manhole requires that the TwistedConch package be
2999 installed, and that you be using Twisted version 2.0 or later.
3001 The buildmaster's SSH server will use a different host key than the
3002 normal sshd running on a typical unix host. This will cause the ssh
3003 client to complain about a ``host key mismatch'', because it does not
3004 realize there are two separate servers running on the same host. To
3005 avoid this, use a clause like the following in your @file{.ssh/config}
3006 file:
3008 @example
3009 Host remotehost-buildbot
3010  HostName remotehost
3011  HostKeyAlias remotehost-buildbot
3012  Port 9999
3013  # use 'user' if you use PasswordManhole and your name is not 'admin'.
3014  # if you use AuthorizedKeysManhole, this probably doesn't matter.
3015  User admin
3016 @end example
3019 @node Getting Source Code Changes, Build Process, Configuration, Top
3020 @chapter Getting Source Code Changes
3022 The most common way to use the Buildbot is centered around the idea of
3023 @code{Source Trees}: a directory tree filled with source code of some form
3024 which can be compiled and/or tested. Some projects use languages that don't
3025 involve any compilation step: nevertheless there may be a @code{build} phase
3026 where files are copied or rearranged into a form that is suitable for
3027 installation. Some projects do not have unit tests, and the Buildbot is
3028 merely helping to make sure that the sources can compile correctly. But in
3029 all of these cases, the thing-being-tested is a single source tree.
3031 A Version Control System mantains a source tree, and tells the
3032 buildmaster when it changes. The first step of each Build is typically
3033 to acquire a copy of some version of this tree.
3035 This chapter describes how the Buildbot learns about what Changes have
3036 occurred. For more information on VC systems and Changes, see
3037 @ref{Version Control Systems}.
3040 @menu
3041 * Change Sources::              
3042 * Choosing ChangeSources::      
3043 * CVSToys - PBService::         
3044 * Mail-parsing ChangeSources::  
3045 * PBChangeSource::              
3046 * P4Source::                    
3047 * BonsaiPoller::                
3048 * SVNPoller::                   
3049 * MercurialHook::               
3050 @end menu
3054 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
3055 @section Change Sources
3057 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
3058 @c so narrow-minded anymore
3060 Each Buildmaster watches a single source tree. Changes can be provided
3061 by a variety of ChangeSource types, however any given project will
3062 typically have only a single ChangeSource active. This section
3063 provides a description of all available ChangeSource types and
3064 explains how to set up each of them.
3066 There are a variety of ChangeSources available, some of which are
3067 meant to be used in conjunction with other tools to deliver Change
3068 events from the VC repository to the buildmaster.
3070 @itemize @bullet
3072 @item CVSToys
3073 This ChangeSource opens a TCP connection from the buildmaster to a
3074 waiting FreshCVS daemon that lives on the repository machine, and
3075 subscribes to hear about Changes.
3077 @item MaildirSource
3078 This one watches a local maildir-format inbox for email sent out by
3079 the repository when a change is made. When a message arrives, it is
3080 parsed to create the Change object. A variety of parsing functions are
3081 available to accomodate different email-sending tools.
3083 @item PBChangeSource
3084 This ChangeSource listens on a local TCP socket for inbound
3085 connections from a separate tool. Usually, this tool would be run on
3086 the VC repository machine in a commit hook. It is expected to connect
3087 to the TCP socket and send a Change message over the network
3088 connection. The @command{buildbot sendchange} command is one example
3089 of a tool that knows how to send these messages, so you can write a
3090 commit script for your VC system that calls it to deliver the Change.
3091 There are other tools in the contrib/ directory that use the same
3092 protocol.
3094 @end itemize
3096 As a quick guide, here is a list of VC systems and the ChangeSources
3097 that might be useful with them. All of these ChangeSources are in the
3098 @code{buildbot.changes} module.
3100 @table @code
3101 @item CVS
3103 @itemize @bullet
3104 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
3105 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
3106 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
3107 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
3108 @item pb.PBChangeSource (listening for connections from @code{buildbot
3109 sendchange} run in a loginfo script)
3110 @item pb.PBChangeSource (listening for connections from a long-running
3111 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
3112 database directly
3113 @end itemize
3115 @item SVN
3116 @itemize @bullet
3117 @item pb.PBChangeSource (listening for connections from
3118 @code{contrib/svn_buildbot.py} run in a postcommit script)
3119 @item pb.PBChangeSource (listening for connections from a long-running
3120 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
3121 process
3122 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
3123 @item svnpoller.SVNPoller (polling the SVN repository)
3124 @end itemize
3126 @item Darcs
3127 @itemize @bullet
3128 @item pb.PBChangeSource (listening for connections from
3129 @code{contrib/darcs_buildbot.py} in a commit script
3130 @end itemize
3132 @item Mercurial
3133 @itemize @bullet
3134 @item pb.PBChangeSource (listening for connections from
3135 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
3136 @item pb.PBChangeSource (listening for connections from
3137 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
3138 hook)
3139 @end itemize
3141 @item Arch/Bazaar
3142 @itemize @bullet
3143 @item pb.PBChangeSource (listening for connections from
3144 @code{contrib/arch_buildbot.py} run in a commit hook)
3145 @end itemize
3147 @item Git
3148 @itemize @bullet
3149 @item pb.PBChangeSource (listening for connections from
3150 @code{contrib/git_buildbot.py} run in the post-receive hook)
3151 @end itemize
3153 @end table
3155 All VC systems can be driven by a PBChangeSource and the
3156 @code{buildbot sendchange} tool run from some form of commit script.
3157 If you write an email parsing function, they can also all be driven by
3158 a suitable @code{MaildirSource}.
3161 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
3162 @section Choosing ChangeSources
3164 The @code{master.cfg} configuration file has a dictionary key named
3165 @code{BuildmasterConfig['change_source']}, which holds the active
3166 @code{IChangeSource} object. The config file will typically create an
3167 object from one of the classes described below and stuff it into this
3168 key.
3170 Each buildmaster typically has just a single ChangeSource, since it is
3171 only watching a single source tree. But if, for some reason, you need
3172 multiple sources, just set @code{c['change_source']} to a list of
3173 ChangeSources.. it will accept that too.
3175 @example
3176 s = FreshCVSSourceNewcred(host="host", port=4519,
3177                           user="alice", passwd="secret",
3178                           prefix="Twisted")
3179 BuildmasterConfig['change_source'] = [s]
3180 @end example
3182 Each source tree has a nominal @code{top}. Each Change has a list of
3183 filenames, which are all relative to this top location. The
3184 ChangeSource is responsible for doing whatever is necessary to
3185 accomplish this. Most sources have a @code{prefix} argument: a partial
3186 pathname which is stripped from the front of all filenames provided to
3187 that @code{ChangeSource}. Files which are outside this sub-tree are
3188 ignored by the changesource: it does not generate Changes for those
3189 files.
3192 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
3193 @section CVSToys - PBService
3195 @csindex buildbot.changes.freshcvs.FreshCVSSource
3197 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
3198 server which runs on the machine that hosts the CVS repository it
3199 watches. It has a variety of ways to distribute commit notifications,
3200 and offers a flexible regexp-based way to filter out uninteresting
3201 changes. One of the notification options is named @code{PBService} and
3202 works by listening on a TCP port for clients. These clients subscribe
3203 to hear about commit notifications.
3205 The buildmaster has a CVSToys-compatible @code{PBService} client built
3206 in. There are two versions of it, one for old versions of CVSToys
3207 (1.0.9 and earlier) which used the @code{oldcred} authentication
3208 framework, and one for newer versions (1.0.10 and later) which use
3209 @code{newcred}. Both are classes in the
3210 @code{buildbot.changes.freshcvs} package.
3212 @code{FreshCVSSourceNewcred} objects are created with the following
3213 parameters:
3215 @table @samp
3217 @item @code{host} and @code{port}
3218 these specify where the CVSToys server can be reached
3220 @item @code{user} and @code{passwd}
3221 these specify the login information for the CVSToys server
3222 (@code{freshcvs}). These must match the server's values, which are
3223 defined in the @code{freshCfg} configuration file (which lives in the
3224 CVSROOT directory of the repository).
3226 @item @code{prefix}
3227 this is the prefix to be found and stripped from filenames delivered
3228 by the CVSToys server. Most projects live in sub-directories of the
3229 main repository, as siblings of the CVSROOT sub-directory, so
3230 typically this prefix is set to that top sub-directory name.
3232 @end table
3234 @heading Example
3236 To set up the freshCVS server, add a statement like the following to
3237 your @file{freshCfg} file:
3239 @example
3240 pb = ConfigurationSet([
3241     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
3242     ])
3243 @end example
3245 This will announce all changes to a client which connects to port 4519
3246 using a username of 'foo' and a password of 'bar'.
3248 Then add a clause like this to your buildmaster's @file{master.cfg}:
3250 @example
3251 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
3252                                                     "foo", "bar",
3253                                                     prefix="glib/")
3254 @end example
3256 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
3257 "glib" is the top-level directory (relative to the repository's root) where
3258 all your source code lives. Most projects keep one or more projects in the
3259 same repository (along with CVSROOT/ to hold admin files like loginfo and
3260 freshCfg); the prefix= argument tells the buildmaster to ignore everything
3261 outside that directory, and to strip that common prefix from all pathnames
3262 it handles.
3265 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
3266 @section Mail-parsing ChangeSources
3268 Many projects publish information about changes to their source tree
3269 by sending an email message out to a mailing list, frequently named
3270 PROJECT-commits or PROJECT-changes. Each message usually contains a
3271 description of the change (who made the change, which files were
3272 affected) and sometimes a copy of the diff. Humans can subscribe to
3273 this list to stay informed about what's happening to the source tree.
3275 The Buildbot can also be subscribed to a -commits mailing list, and
3276 can trigger builds in response to Changes that it hears about. The
3277 buildmaster admin needs to arrange for these email messages to arrive
3278 in a place where the buildmaster can find them, and configure the
3279 buildmaster to parse the messages correctly. Once that is in place,
3280 the email parser will create Change objects and deliver them to the
3281 Schedulers (see @pxref{Change Sources and Schedulers}) just
3282 like any other ChangeSource.
3284 There are two components to setting up an email-based ChangeSource.
3285 The first is to route the email messages to the buildmaster, which is
3286 done by dropping them into a ``maildir''. The second is to actually
3287 parse the messages, which is highly dependent upon the tool that was
3288 used to create them. Each VC system has a collection of favorite
3289 change-emailing tools, and each has a slightly different format, so
3290 each has a different parsing function. There is a separate
3291 ChangeSource variant for each parsing function.
3293 Once you've chosen a maildir location and a parsing function, create
3294 the change source and put it in @code{c['change_source']}:
3296 @example
3297 from buildbot.changes.mail import SyncmailMaildirSource
3298 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
3299                                            prefix="/trunk/")
3300 @end example
3302 @menu
3303 * Subscribing the Buildmaster::  
3304 * Using Maildirs::              
3305 * Parsing Email Change Messages::  
3306 @end menu
3308 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
3309 @subsection Subscribing the Buildmaster
3311 The recommended way to install the buildbot is to create a dedicated
3312 account for the buildmaster. If you do this, the account will probably
3313 have a distinct email address (perhaps
3314 @email{buildmaster@@example.org}). Then just arrange for this
3315 account's email to be delivered to a suitable maildir (described in
3316 the next section).
3318 If the buildbot does not have its own account, ``extension addresses''
3319 can be used to distinguish between email intended for the buildmaster
3320 and email intended for the rest of the account. In most modern MTAs,
3321 the e.g. @code{foo@@example.org} account has control over every email
3322 address at example.org which begins with "foo", such that email
3323 addressed to @email{account-foo@@example.org} can be delivered to a
3324 different destination than @email{account-bar@@example.org}. qmail
3325 does this by using separate .qmail files for the two destinations
3326 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
3327 controlling the base address and @file{.qmail-default} controlling all
3328 other extensions). Other MTAs have similar mechanisms.
3330 Thus you can assign an extension address like
3331 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
3332 @email{foo@@example.org} for your own use.
3335 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
3336 @subsection Using Maildirs
3338 A ``maildir'' is a simple directory structure originally developed for
3339 qmail that allows safe atomic update without locking. Create a base
3340 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
3341 When messages arrive, they are put into a uniquely-named file (using
3342 pids, timestamps, and random numbers) in ``tmp''. When the file is
3343 complete, it is atomically renamed into ``new''. Eventually the
3344 buildmaster notices the file in ``new'', reads and parses the
3345 contents, then moves it into ``cur''. A cronjob can be used to delete
3346 files in ``cur'' at leisure.
3348 Maildirs are frequently created with the @command{maildirmake} tool,
3349 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
3350 equivalent.
3352 Many modern MTAs can deliver directly to maildirs. The usual .forward
3353 or .procmailrc syntax is to name the base directory with a trailing
3354 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
3355 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
3356 Delivery Agent).
3358 For MTAs which cannot put files into maildirs directly, the
3359 ``safecat'' tool can be executed from a .forward file to accomplish
3360 the same thing.
3362 The Buildmaster uses the linux DNotify facility to receive immediate
3363 notification when the maildir's ``new'' directory has changed. When
3364 this facility is not available, it polls the directory for new
3365 messages, every 10 seconds by default.
3367 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
3368 @subsection Parsing Email Change Messages
3370 The second component to setting up an email-based ChangeSource is to
3371 parse the actual notices. This is highly dependent upon the VC system
3372 and commit script in use.
3374 A couple of common tools used to create these change emails are:
3376 @table @samp
3378 @item CVS
3379 @table @samp
3380 @item CVSToys MailNotifier
3381 @ref{FCMaildirSource}
3382 @item Bonsai notification
3383 @ref{BonsaiMaildirSource}
3384 @item syncmail
3385 @ref{SyncmailMaildirSource}
3386 @end table
3388 @item SVN
3389 @table @samp
3390 @item svnmailer
3391 http://opensource.perlig.de/en/svnmailer/
3392 @item commit-email.pl
3393 @ref{SVNCommitEmailMaildirSource}
3394 @end table
3396 @item Mercurial
3397 @table @samp
3398 @item NotifyExtension
3399 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
3400 @end table
3402 @item Git
3403 @table @samp
3404 @item post-receive-email
3405 http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email;hb=HEAD
3406 @end table
3408 @end table
3411 The following sections describe the parsers available for each of
3412 these tools.
3414 Most of these parsers accept a @code{prefix=} argument, which is used
3415 to limit the set of files that the buildmaster pays attention to. This
3416 is most useful for systems like CVS and SVN which put multiple
3417 projects in a single repository (or use repository names to indicate
3418 branches). Each filename that appears in the email is tested against
3419 the prefix: if the filename does not start with the prefix, the file
3420 is ignored. If the filename @emph{does} start with the prefix, that
3421 prefix is stripped from the filename before any further processing is
3422 done. Thus the prefix usually ends with a slash.
3424 @menu
3425 * FCMaildirSource::             
3426 * SyncmailMaildirSource::       
3427 * BonsaiMaildirSource::         
3428 * SVNCommitEmailMaildirSource::  
3429 @end menu
3431 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
3432 @subsubsection FCMaildirSource
3435 @csindex buildbot.changes.mail.FCMaildirSource
3437 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
3439 This parser works with the CVSToys @code{MailNotification} action,
3440 which will send email to a list of recipients for each commit. This
3441 tends to work better than using @code{/bin/mail} from within the
3442 CVSROOT/loginfo file directly, as CVSToys will batch together all
3443 files changed during the same CVS invocation, and can provide more
3444 information (like creating a ViewCVS URL for each file changed).
3446 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3447 messages and turn them into Change objects. It can be given two
3448 parameters: the directory name of the maildir root, and the prefix to
3449 strip.
3451 @example
3452 from buildbot.changes.mail import FCMaildirSource
3453 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3454 @end example
3456 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3457 @subsubsection SyncmailMaildirSource
3459 @csindex buildbot.changes.mail.SyncmailMaildirSource
3461 http://sourceforge.net/projects/cvs-syncmail
3463 @code{SyncmailMaildirSource} knows how to parse the message format used by
3464 the CVS ``syncmail'' script.
3466 @example
3467 from buildbot.changes.mail import SyncmailMaildirSource
3468 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3469 @end example
3471 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3472 @subsubsection BonsaiMaildirSource
3474 @csindex buildbot.changes.mail.BonsaiMaildirSource
3476 http://www.mozilla.org/bonsai.html
3478 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3479 tree-management system built by Mozilla.
3481 @example
3482 from buildbot.changes.mail import BonsaiMaildirSource
3483 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3484 @end example
3486 @node SVNCommitEmailMaildirSource,  , BonsaiMaildirSource, Parsing Email Change Messages
3487 @subsubsection SVNCommitEmailMaildirSource
3489 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3491 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3492 @code{commit-email.pl} script, which is included in the Subversion
3493 distribution.
3495 It does not currently handle branches: all of the Change objects that
3496 it creates will be associated with the default (i.e. trunk) branch.
3498 @example
3499 from buildbot.changes.mail import SVNCommitEmailMaildirSource
3500 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
3501 @end example
3504 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
3505 @section PBChangeSource
3507 @csindex buildbot.changes.pb.PBChangeSource
3509 The last kind of ChangeSource actually listens on a TCP port for
3510 clients to connect and push change notices @emph{into} the
3511 Buildmaster. This is used by the built-in @code{buildbot sendchange}
3512 notification tool, as well as the VC-specific
3513 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
3514 @file{contrib/hg_buildbot.py} tools, and the
3515 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
3516 repository (in a commit hook script), and connect to the buildmaster
3517 directly each time a file is comitted. This is also useful for
3518 creating new kinds of change sources that work on a @code{push} model
3519 instead of some kind of subscription scheme, for example a script
3520 which is run out of an email .forward file.
3522 This ChangeSource can be configured to listen on its own TCP port, or
3523 it can share the port that the buildmaster is already using for the
3524 buildslaves to connect. (This is possible because the
3525 @code{PBChangeSource} uses the same protocol as the buildslaves, and
3526 they can be distinguished by the @code{username} attribute used when
3527 the initial connection is established). It might be useful to have it
3528 listen on a different port if, for example, you wanted to establish
3529 different firewall rules for that port. You could allow only the SVN
3530 repository machine access to the @code{PBChangeSource} port, while
3531 allowing only the buildslave machines access to the slave port. Or you
3532 could just expose one port and run everything over it. @emph{Note:
3533 this feature is not yet implemented, the PBChangeSource will always
3534 share the slave port and will always have a @code{user} name of
3535 @code{change}, and a passwd of @code{changepw}. These limitations will
3536 be removed in the future.}.
3539 The @code{PBChangeSource} is created with the following arguments. All
3540 are optional.
3542 @table @samp
3543 @item @code{port}
3544 which port to listen on. If @code{None} (which is the default), it
3545 shares the port used for buildslave connections. @emph{Not
3546 Implemented, always set to @code{None}}.
3548 @item @code{user} and @code{passwd}
3549 The user/passwd account information that the client program must use
3550 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
3551 Implemented, @code{user} is currently always set to @code{change},
3552 @code{passwd} is always set to @code{changepw}}.
3554 @item @code{prefix}
3555 The prefix to be found and stripped from filenames delivered over the
3556 connection. Any filenames which do not start with this prefix will be
3557 removed. If all the filenames in a given Change are removed, the that
3558 whole Change will be dropped. This string should probably end with a
3559 directory separator.
3561 This is useful for changes coming from version control systems that
3562 represent branches as parent directories within the repository (like
3563 SVN and Perforce). Use a prefix of 'trunk/' or
3564 'project/branches/foobranch/' to only follow one branch and to get
3565 correct tree-relative filenames. Without a prefix, the PBChangeSource
3566 will probably deliver Changes with filenames like @file{trunk/foo.c}
3567 instead of just @file{foo.c}. Of course this also depends upon the
3568 tool sending the Changes in (like @command{buildbot sendchange}) and
3569 what filenames it is delivering: that tool may be filtering and
3570 stripping prefixes at the sending end.
3572 @end table
3574 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
3575 @section P4Source
3577 @csindex buildbot.changes.p4poller.P4Source
3579 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
3580 Perforce} depot for changes. It accepts the following arguments:
3582 @table @samp
3583 @item @code{p4base}
3584 The base depot path to watch, without the trailing '/...'.
3586 @item @code{p4port}
3587 The Perforce server to connect to (as host:port).
3589 @item @code{p4user}
3590 The Perforce user.
3592 @item @code{p4passwd}
3593 The Perforce password.
3595 @item @code{split_file}
3596 A function that maps a pathname, without the leading @code{p4base}, to a
3597 (branch, filename) tuple. The default just returns (None, branchfile),
3598 which effectively disables branch support. You should supply a function
3599 which understands your repository structure.
3601 @item @code{pollinterval}
3602 How often to poll, in seconds. Defaults to 600 (10 minutes).
3604 @item @code{histmax}
3605 The maximum number of changes to inspect at a time. If more than this
3606 number occur since the last poll, older changes will be silently
3607 ignored.
3608 @end table
3610 @heading Example
3612 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
3613 specified in the buildmaster's environment. It watches a project in which the
3614 branch name is simply the next path component, and the file is all path
3615 components after.
3617 @example
3618 import buildbot.changes.p4poller
3619 s = p4poller.P4Source(p4base='//depot/project/',
3620                       split_file=lambda branchfile: branchfile.split('/',1),
3621                      )
3622 c['change_source'] = s
3623 @end example
3625 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
3626 @section BonsaiPoller
3628 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
3630 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
3631 CGI script accessed through a web server that provides information
3632 about a CVS tree, for example the Mozilla bonsai server at
3633 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
3634 humans and machines. In this case, the buildbot's change source forms
3635 a query which asks about any files in the specified branch which have
3636 changed since the last query.
3638 Please take a look at the BonsaiPoller docstring for details about the
3639 arguments it accepts.
3642 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
3643 @section SVNPoller
3645 @csindex buildbot.changes.svnpoller.SVNPoller
3647 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
3648 which periodically polls a @uref{http://subversion.tigris.org/,
3649 Subversion} repository for new revisions, by running the @code{svn
3650 log} command in a subshell. It can watch a single branch or multiple
3651 branches.
3653 @code{SVNPoller} accepts the following arguments:
3655 @table @code
3656 @item svnurl
3657 The base URL path to watch, like
3658 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
3659 @code{http://divmod.org/svn/Divmod/}, or even
3660 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
3661 include the access scheme, the location of the repository (both the
3662 hostname for remote ones, and any additional directory names necessary
3663 to get to the repository), and the sub-path within the repository's
3664 virtual filesystem for the project and branch of interest.
3666 The @code{SVNPoller} will only pay attention to files inside the
3667 subdirectory specified by the complete svnurl.
3669 @item split_file
3670 A function to convert pathnames into (branch, relative_pathname)
3671 tuples. Use this to explain your repository's branch-naming policy to
3672 @code{SVNPoller}. This function must accept a single string and return
3673 a two-entry tuple. There are a few utility functions in
3674 @code{buildbot.changes.svnpoller} that can be used as a
3675 @code{split_file} function, see below for details.
3677 The default value always returns (None, path), which indicates that
3678 all files are on the trunk.
3680 Subclasses of @code{SVNPoller} can override the @code{split_file}
3681 method instead of using the @code{split_file=} argument.
3683 @item svnuser
3684 An optional string parameter. If set, the @code{--user} argument will
3685 be added to all @code{svn} commands. Use this if you have to
3686 authenticate to the svn server before you can do @code{svn info} or
3687 @code{svn log} commands.
3689 @item svnpasswd
3690 Like @code{svnuser}, this will cause a @code{--password} argument to
3691 be passed to all svn commands.
3693 @item pollinterval
3694 How often to poll, in seconds. Defaults to 600 (checking once every 10
3695 minutes). Lower this if you want the buildbot to notice changes
3696 faster, raise it if you want to reduce the network and CPU load on
3697 your svn server. Please be considerate of public SVN repositories by
3698 using a large interval when polling them.
3700 @item histmax
3701 The maximum number of changes to inspect at a time. Every POLLINTERVAL
3702 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
3703 looks through them for any ones it does not already know about. If
3704 more than HISTMAX revisions have been committed since the last poll,
3705 older changes will be silently ignored. Larger values of histmax will
3706 cause more time and memory to be consumed on each poll attempt.
3707 @code{histmax} defaults to 100.
3709 @item svnbin
3710 This controls the @code{svn} executable to use. If subversion is
3711 installed in a weird place on your system (outside of the
3712 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
3713 to find it. The default value of ``svn'' will almost always be
3714 sufficient.
3716 @end table
3718 @heading Branches
3720 Each source file that is tracked by a Subversion repository has a
3721 fully-qualified SVN URL in the following form:
3722 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
3723 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
3724 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
3725 string. The @code{SVNPoller} is responsible for producing Changes that
3726 contain a branch name and a FILEPATH (which is relative to the top of
3727 a checked-out tree). The details of how these strings are split up
3728 depend upon how your repository names its branches.
3730 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
3732 One common layout is to have all the various projects that share a
3733 repository get a single top-level directory each. Then under a given
3734 project's directory, you get two subdirectories, one named ``trunk''
3735 and another named ``branches''. Under ``branches'' you have a bunch of
3736 other directories, one per branch, with names like ``1.5.x'' and
3737 ``testing''. It is also common to see directories like ``tags'' and
3738 ``releases'' next to ``branches'' and ``trunk''.
3740 For example, the Twisted project has a subversion server on
3741 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
3742 repository is available through a SCHEME of ``svn:''. The primary
3743 sub-project is Twisted, of course, with a repository root of
3744 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
3745 Informant, with a root of
3746 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
3747 checked-out Twisted tree, there is a file named bin/trial (which is
3748 used to run unit test suites).
3750 The trunk for Twisted is in
3751 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
3752 fully-qualified SVN URL for the trunk version of @code{trial} would be
3753 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
3754 SVNURL for that file on a branch named ``1.5.x'' would be
3755 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
3757 To set up a @code{SVNPoller} that watches the Twisted trunk (and
3758 nothing else), we would use the following:
3760 @example
3761 from buildbot.changes.svnpoller import SVNPoller
3762 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
3763 @end example
3765 In this case, every Change that our @code{SVNPoller} produces will
3766 have @code{.branch=None}, to indicate that the Change is on the trunk.
3767 No other sub-projects or branches will be tracked.
3769 If we want our ChangeSource to follow multiple branches, we have to do
3770 two things. First we have to change our @code{svnurl=} argument to
3771 watch more than just ``.../Twisted/trunk''. We will set it to
3772 ``.../Twisted'' so that we'll see both the trunk and all the branches.
3773 Second, we have to tell @code{SVNPoller} how to split the
3774 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
3775 out into (BRANCH) and (FILEPATH) pairs.
3777 We do the latter by providing a ``split_file'' function. This function
3778 is responsible for splitting something like
3779 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
3780 @code{filepath}=''bin/trial''. This function is always given a string
3781 that names a file relative to the subdirectory pointed to by the
3782 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
3783 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
3784 branch indicated), or None to indicate that the file is outside any
3785 project of interest.
3787 (note that we want to see ``branches/1.5.x'' rather than just
3788 ``1.5.x'' because when we perform the SVN checkout, we will probably
3789 append the branch name to the baseURL, which requires that we keep the
3790 ``branches'' component in there. Other VC schemes use a different
3791 approach towards branches and may not require this artifact.)
3793 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
3794 scheme, the following function will work:
3796 @example
3797 def split_file_branches(path):
3798     pieces = path.split('/')
3799     if pieces[0] == 'trunk':
3800         return (None, '/'.join(pieces[1:]))
3801     elif pieces[0] == 'branches':
3802         return ('/'.join(pieces[0:2]),
3803                 '/'.join(pieces[2:]))
3804     else:
3805         return None
3806 @end example
3808 This function is provided as
3809 @code{buildbot.changes.svnpoller.split_file_branches} for your
3810 convenience. So to have our Twisted-watching @code{SVNPoller} follow
3811 multiple branches, we would use this:
3813 @example
3814 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
3815 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
3816                                split_file=split_file_branches)
3817 @end example
3819 Changes for all sorts of branches (with names like ``branches/1.5.x'',
3820 and None to indicate the trunk) will be delivered to the Schedulers.
3821 Each Scheduler is then free to use or ignore each branch as it sees
3822 fit.
3824 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
3826 Another common way to organize a Subversion repository is to put the
3827 branch name at the top, and the projects underneath. This is
3828 especially frequent when there are a number of related sub-projects
3829 that all get released in a group.
3831 For example, Divmod.org hosts a project named ``Nevow'' as well as one
3832 named ``Quotient''. In a checked-out Nevow tree there is a directory
3833 named ``formless'' that contains a python source file named
3834 ``webform.py''. This repository is accessible via webdav (and thus
3835 uses an ``http:'' scheme) through the divmod.org hostname. There are
3836 many branches in this repository, and they use a
3837 (BRANCHNAME)/(PROJECT) naming policy.
3839 The fully-qualified SVN URL for the trunk version of webform.py is
3840 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
3841 You can do an @code{svn co} with that URL and get a copy of the latest
3842 version. The 1.5.x branch version of this file would have a URL of
3843 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
3844 The whole Nevow trunk would be checked out with
3845 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
3846 trunk would be checked out using
3847 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
3849 Now suppose we want to have an @code{SVNPoller} that only cares about
3850 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
3851 described earlier:
3853 @example
3854 from buildbot.changes.svnpoller import SVNPoller
3855 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
3856 @end example
3858 But what happens when we want to track multiple Nevow branches? We
3859 have to point our @code{svnurl=} high enough to see all those
3860 branches, but we also don't want to include Quotient changes (since
3861 we're only building Nevow). To accomplish this, we must rely upon the
3862 @code{split_file} function to help us tell the difference between
3863 files that belong to Nevow and those that belong to Quotient, as well
3864 as figuring out which branch each one is on.
3866 @example
3867 from buildbot.changes.svnpoller import SVNPoller
3868 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
3869                                split_file=my_file_splitter)
3870 @end example
3872 The @code{my_file_splitter} function will be called with
3873 repository-relative pathnames like:
3875 @table @code
3876 @item trunk/Nevow/formless/webform.py
3877 This is a Nevow file, on the trunk. We want the Change that includes this
3878 to see a filename of @code{formless/webform.py"}, and a branch of None
3880 @item branches/1.5.x/Nevow/formless/webform.py
3881 This is a Nevow file, on a branch. We want to get
3882 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
3884 @item trunk/Quotient/setup.py
3885 This is a Quotient file, so we want to ignore it by having
3886 @code{my_file_splitter} return None.
3888 @item branches/1.5.x/Quotient/setup.py
3889 This is also a Quotient file, which should be ignored.
3890 @end table
3892 The following definition for @code{my_file_splitter} will do the job:
3894 @example
3895 def my_file_splitter(path):
3896     pieces = path.split('/')
3897     if pieces[0] == 'trunk':
3898         branch = None
3899         pieces.pop(0) # remove 'trunk'
3900     elif pieces[0] == 'branches':
3901         pieces.pop(0) # remove 'branches'
3902         # grab branch name
3903         branch = 'branches/' + pieces.pop(0)
3904     else:
3905         return None # something weird
3906     projectname = pieces.pop(0)
3907     if projectname != 'Nevow':
3908         return None # wrong project
3909     return (branch, '/'.join(pieces))
3910 @end example
3912 @node MercurialHook,  , SVNPoller, Getting Source Code Changes
3913 @section MercurialHook
3915 Since Mercurial is written in python, the hook script can invoke
3916 Buildbot's @code{sendchange} function directly, rather than having to
3917 spawn an external process. This function delivers the same sort of
3918 changes as @code{buildbot sendchange} and the various hook scripts in
3919 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
3920 buildmaster to receive these changes.
3922 To set this up, first choose a Mercurial repository that represents
3923 your central ``official'' source tree. This will be the same
3924 repository that your buildslaves will eventually pull from. Install
3925 Buildbot on the machine that hosts this repository, using the same
3926 version of python as Mercurial is using (so that the Mercurial hook
3927 can import code from buildbot). Then add the following to the
3928 @code{.hg/hgrc} file in that repository, replacing the buildmaster
3929 hostname/portnumber as appropriate for your buildbot:
3931 @example
3932 [hooks]
3933 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
3935 [hgbuildbot]
3936 master = buildmaster.example.org:9987
3937 @end example
3939 (Note that Mercurial lets you define multiple @code{changegroup} hooks
3940 by giving them distinct names, like @code{changegroup.foo} and
3941 @code{changegroup.bar}, which is why we use
3942 @code{changegroup.buildbot} in this example. There is nothing magical
3943 about the ``buildbot'' suffix in the hook name. The
3944 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
3945 only section that the buildbot hook pays attention to.)
3947 Also note that this runs as a @code{changegroup} hook, rather than as
3948 an @code{incoming} hook. The @code{changegroup} hook is run with
3949 multiple revisions at a time (say, if multiple revisions are being
3950 pushed to this repository in a single @command{hg push} command),
3951 whereas the @code{incoming} hook is run with just one revision at a
3952 time. The @code{hgbuildbot.hook} function will only work with the
3953 @code{changegroup} hook.
3955 The @code{[hgbuildbot]} section has two other parameters that you
3956 might specify, both of which control the name of the branch that is
3957 attached to the changes coming from this hook.
3959 One common branch naming policy for Mercurial repositories is to use
3960 it just like Darcs: each branch goes into a separate repository, and
3961 all the branches for a single project share a common parent directory.
3962 For example, you might have @file{/var/repos/PROJECT/trunk/} and
3963 @file{/var/repos/PROJECT/release}. To use this style, use the
3964 @code{branchtype = dirname} setting, which simply uses the last
3965 component of the repository's enclosing directory as the branch name:
3967 @example
3968 [hgbuildbot]
3969 master = buildmaster.example.org:9987
3970 branchtype = dirname
3971 @end example
3973 Another approach is to use Mercurial's built-in branches (the kind
3974 created with @command{hg branch} and listed with @command{hg
3975 branches}). This feature associates persistent names with particular
3976 lines of descent within a single repository. (note that the buildbot
3977 @code{source.Mercurial} checkout step does not yet support this kind
3978 of branch). To have the commit hook deliver this sort of branch name
3979 with the Change object, use @code{branchtype = inrepo}:
3981 @example
3982 [hgbuildbot]
3983 master = buildmaster.example.org:9987
3984 branchtype = inrepo
3985 @end example
3987 Finally, if you want to simply specify the branchname directly, for
3988 all changes, use @code{branch = BRANCHNAME}. This overrides
3989 @code{branchtype}:
3991 @example
3992 [hgbuildbot]
3993 master = buildmaster.example.org:9987
3994 branch = trunk
3995 @end example
3997 If you use @code{branch=} like this, you'll need to put a separate
3998 .hgrc in each repository. If you use @code{branchtype=}, you may be
3999 able to use the same .hgrc for all your repositories, stored in
4000 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
4003 @node Build Process, Status Delivery, Getting Source Code Changes, Top
4004 @chapter Build Process
4006 A @code{Build} object is responsible for actually performing a build.
4007 It gets access to a remote @code{SlaveBuilder} where it may run
4008 commands, and a @code{BuildStatus} object where it must emit status
4009 events. The @code{Build} is created by the Builder's
4010 @code{BuildFactory}.
4012 The default @code{Build} class is made up of a fixed sequence of
4013 @code{BuildSteps}, executed one after another until all are complete
4014 (or one of them indicates that the build should be halted early). The
4015 default @code{BuildFactory} creates instances of this @code{Build}
4016 class with a list of @code{BuildSteps}, so the basic way to configure
4017 the build is to provide a list of @code{BuildSteps} to your
4018 @code{BuildFactory}.
4020 More complicated @code{Build} subclasses can make other decisions:
4021 execute some steps only if certain files were changed, or if certain
4022 previous steps passed or failed. The base class has been written to
4023 allow users to express basic control flow without writing code, but
4024 you can always subclass and customize to achieve more specialized
4025 behavior.
4027 @menu
4028 * Build Steps::                 
4029 * Interlocks::                  
4030 * Build Factories::             
4031 @end menu
4033 @node Build Steps, Interlocks, Build Process, Build Process
4034 @section Build Steps
4036 @code{BuildStep}s are usually specified in the buildmaster's
4037 configuration file, in a list that goes into the @code{BuildFactory}.
4038 The @code{BuildStep} instances in this list are used as templates to
4039 construct new independent copies for each build (so that state can be
4040 kept on the @code{BuildStep} in one build without affecting a later
4041 build). Each @code{BuildFactory} can be created with a list of steps,
4042 or the factory can be created empty and then steps added to it using
4043 the @code{addStep} method:
4045 @example
4046 from buildbot.steps import source, shell
4047 from buildbot.process import factory
4049 f = factory.BuildFactory()
4050 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
4051 f.addStep(shell.ShellCommand(command=["make", "all"]))
4052 f.addStep(shell.ShellCommand(command=["make", "test"]))
4053 @end example
4055 In earlier versions (0.7.5 and older), these steps were specified with
4056 a tuple of (step_class, keyword_arguments). Steps can still be
4057 specified this way, but the preferred form is to pass actual
4058 @code{BuildStep} instances to @code{addStep}, because that gives the
4059 @code{BuildStep} class a chance to do some validation on the
4060 arguments.
4062 The rest of this section lists all the standard BuildStep objects
4063 available for use in a Build, and the parameters which can be used to
4064 control each.
4066 @menu
4067 * Common Parameters::           
4068 * Using Build Properties::      
4069 * Source Checkout::             
4070 * ShellCommand::                
4071 * Simple ShellCommand Subclasses::  
4072 * Python BuildSteps::           
4073 * Transferring Files::          
4074 * Triggering Schedulers::       
4075 * Writing New BuildSteps::      
4076 @end menu
4078 @node Common Parameters, Using Build Properties, Build Steps, Build Steps
4079 @subsection Common Parameters
4081 The standard @code{Build} runs a series of @code{BuildStep}s in order,
4082 only stopping when it runs out of steps or if one of them requests
4083 that the build be halted. It collects status information from each one
4084 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
4086 All BuildSteps accept some common parameters. Some of these control
4087 how their individual status affects the overall build. Others are used
4088 to specify which @code{Locks} (see @pxref{Interlocks}) should be
4089 acquired before allowing the step to run.
4091 Arguments common to all @code{BuildStep} subclasses:
4094 @table @code
4095 @item name
4096 the name used to describe the step on the status display. It is also
4097 used to give a name to any LogFiles created by this step.
4099 @item haltOnFailure
4100 if True, a FAILURE of this build step will cause the build to halt
4101 immediately with an overall result of FAILURE.
4103 @item flunkOnWarnings
4104 when True, a WARNINGS or FAILURE of this build step will mark the
4105 overall build as FAILURE. The remaining steps will still be executed.
4107 @item flunkOnFailure
4108 when True, a FAILURE of this build step will mark the overall build as
4109 a FAILURE. The remaining steps will still be executed.
4111 @item warnOnWarnings
4112 when True, a WARNINGS or FAILURE of this build step will mark the
4113 overall build as having WARNINGS. The remaining steps will still be
4114 executed.
4116 @item warnOnFailure
4117 when True, a FAILURE of this build step will mark the overall build as
4118 having WARNINGS. The remaining steps will still be executed.
4120 @item locks
4121 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
4122 @code{buildbot.locks.MasterLock}) that should be acquired before
4123 starting this Step. The Locks will be released when the step is
4124 complete. Note that this is a list of actual Lock instances, not
4125 names. Also note that all Locks must have unique names.
4127 @end table
4129 @node Using Build Properties, Source Checkout, Common Parameters, Build Steps
4130 @subsection Using Build Properties
4131 @cindex Properties
4133 Build properties are a generalized way to provide configuration
4134 information to build steps; see @ref{Build Properties}.
4136 Some build properties are inherited from external sources -- global
4137 properties, schedulers, or buildslaves.  Some build properties are
4138 set when the build starts, such as the SourceStamp information. Other
4139 properties can be set by BuildSteps as they run, for example the
4140 various Source steps will set the @code{got_revision} property to the
4141 source revision that was actually checked out (which can be useful
4142 when the SourceStamp in use merely requested the ``latest revision'':
4143 @code{got_revision} will tell you what was actually built).
4145 In custom BuildSteps, you can get and set the build properties with
4146 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4147 for the name of the property, and returns or accepts an
4148 arbitrary@footnote{Build properties are serialized along with the
4149 build results, so they must be serializable. For this reason, the
4150 value of any build property should be simple inert data: strings,
4151 numbers, lists, tuples, and dictionaries. They should not contain
4152 class instances.} object. For example:
4154 @example
4155 class MakeTarball(ShellCommand):
4156     def start(self):
4157         if self.getProperty("os") == "win":
4158             self.setCommand([ ... ]) # windows-only command
4159         else:
4160             self.setCommand([ ... ]) # equivalent for other systems
4161         ShellCommand.start(self)
4162 @end example
4164 @heading WithProperties
4165 @cindex WithProperties
4167 You can use build properties in ShellCommands by using the
4168 @code{WithProperties} wrapper when setting the arguments of
4169 the ShellCommand. This interpolates the named build properties
4170 into the generated shell command.  Most step parameters accept
4171 @code{WithProperties}.  Please file bugs for any parameters which
4172 do not.
4174 @example
4175 from buildbot.steps.shell import ShellCommand
4176 from buildbot.process.properties import WithProperties
4178 f.addStep(ShellCommand(
4179           command=["tar", "czf",
4180                    WithProperties("build-%s.tar.gz", "revision"),
4181                    "source"]))
4182 @end example
4184 If this BuildStep were used in a tree obtained from Subversion, it
4185 would create a tarball with a name like @file{build-1234.tar.gz}.
4187 The @code{WithProperties} function does @code{printf}-style string
4188 interpolation, using strings obtained by calling
4189 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4190 @code{%d}, etc), you must have exactly one additional argument to
4191 indicate which build property you want to insert.
4193 You can also use python dictionary-style string interpolation by using
4194 the @code{%(propname)s} syntax. In this form, the property name goes
4195 in the parentheses, and WithProperties takes @emph{no} additional
4196 arguments:
4198 @example
4199 f.addStep(ShellCommand(
4200           command=["tar", "czf",
4201                    WithProperties("build-%(revision)s.tar.gz"),
4202                    "source"]))
4203 @end example
4205 Don't forget the extra ``s'' after the closing parenthesis! This is
4206 the cause of many confusing errors. 
4208 The dictionary-style interpolation supports a number of more advanced
4209 syntaxes, too.
4211 @table @code
4213 @item propname:-replacement
4214 If @code{propname} exists, substitute its value; otherwise,
4215 substitute @code{replacement}.  @code{replacement} may be empty
4216 (@code{%(propname:-)s})
4218 @item propname:+replacement
4219 If @code{propname} exists, substitute @code{replacement}; otherwise,
4220 substitute an empty string.
4222 @end table
4224 Although these are similar to shell substitutions, no other
4225 substitutions are currently supported, and @code{replacement} in the
4226 above cannot contain more substitutions.
4228 Note: like python, you can either do positional-argument interpolation
4229 @emph{or} keyword-argument interpolation, not both. Thus you cannot use
4230 a string like @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4232 @heading Common Build Properties
4234 The following build properties are set when the build is started, and
4235 are available to all steps.
4237 @table @code
4238 @item branch
4240 This comes from the build's SourceStamp, and describes which branch is
4241 being checked out. This will be @code{None} (which interpolates into
4242 @code{WithProperties} as an empty string) if the build is on the
4243 default branch, which is generally the trunk. Otherwise it will be a
4244 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4245 system being used.
4247 @item revision
4249 This also comes from the SourceStamp, and is the revision of the
4250 source code tree that was requested from the VC system. When a build
4251 is requested of a specific revision (as is generally the case when
4252 the build is triggered by Changes), this will contain the revision
4253 specification. The syntax depends upon the VC system in use: for SVN
4254 it is an integer, for Mercurial it is a short string, for Darcs it
4255 is a rather large string, etc.
4257 If the ``force build'' button was pressed, the revision will be
4258 @code{None}, which means to use the most recent revision available.
4259 This is a ``trunk build''. This will be interpolated as an empty
4260 string.
4262 @item got_revision
4264 This is set when a Source step checks out the source tree, and
4265 provides the revision that was actually obtained from the VC system.
4266 In general this should be the same as @code{revision}, except for
4267 trunk builds, where @code{got_revision} indicates what revision was
4268 current when the checkout was performed. This can be used to rebuild
4269 the same source code later.
4271 Note that for some VC systems (Darcs in particular), the revision is a
4272 large string containing newlines, and is not suitable for interpolation
4273 into a filename.
4275 @item buildername
4277 This is a string that indicates which Builder the build was a part of.
4278 The combination of buildername and buildnumber uniquely identify a
4279 build.
4281 @item buildnumber
4283 Each build gets a number, scoped to the Builder (so the first build
4284 performed on any given Builder will have a build number of 0). This
4285 integer property contains the build's number.
4287 @item slavename
4289 This is a string which identifies which buildslave the build is
4290 running on.
4292 @item scheduler
4294 If the build was started from a scheduler, then this property will
4295 contain the name of that scheduler.
4297 @end table
4300 @node Source Checkout, ShellCommand, Using Build Properties, Build Steps
4301 @subsection Source Checkout
4303 The first step of any build is typically to acquire the source code
4304 from which the build will be performed. There are several classes to
4305 handle this, one for each of the different source control system that
4306 Buildbot knows about. For a description of how Buildbot treats source
4307 control in general, see @ref{Version Control Systems}.
4309 All source checkout steps accept some common parameters to control how
4310 they get the sources and where they should be placed. The remaining
4311 per-VC-system parameters are mostly to specify where exactly the
4312 sources are coming from.
4314 @table @code
4315 @item mode
4317 a string describing the kind of VC operation that is desired. Defaults
4318 to @code{update}.
4320 @table @code
4321 @item update
4322 specifies that the CVS checkout/update should be performed directly
4323 into the workdir. Each build is performed in the same directory,
4324 allowing for incremental builds. This minimizes disk space, bandwidth,
4325 and CPU time. However, it may encounter problems if the build process
4326 does not handle dependencies properly (sometimes you must do a ``clean
4327 build'' to make sure everything gets compiled), or if source files are
4328 deleted but generated files can influence test behavior (e.g. python's
4329 .pyc files), or when source directories are deleted but generated
4330 files prevent CVS from removing them. Builds ought to be correct
4331 regardless of whether they are done ``from scratch'' or incrementally,
4332 but it is useful to test both kinds: this mode exercises the
4333 incremental-build style.
4335 @item copy
4336 specifies that the CVS workspace should be maintained in a separate
4337 directory (called the 'copydir'), using checkout or update as
4338 necessary. For each build, a new workdir is created with a copy of the
4339 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
4340 disk space required, but keeps the bandwidth low (update instead of a
4341 full checkout). A full 'clean' build is performed each time. This
4342 avoids any generated-file build problems, but is still occasionally
4343 vulnerable to CVS problems such as a repository being manually
4344 rearranged, causing CVS errors on update which are not an issue with a
4345 full checkout.
4347 @c TODO: something is screwy about this, revisit. Is it the source
4348 @c directory or the working directory that is deleted each time?
4350 @item clobber
4351 specifes that the working directory should be deleted each time,
4352 necessitating a full checkout for each build. This insures a clean
4353 build off a complete checkout, avoiding any of the problems described
4354 above. This mode exercises the ``from-scratch'' build style.
4356 @item export
4357 this is like @code{clobber}, except that the 'cvs export' command is
4358 used to create the working directory. This command removes all CVS
4359 metadata files (the CVS/ directories) from the tree, which is
4360 sometimes useful for creating source tarballs (to avoid including the
4361 metadata in the tar file).
4362 @end table
4364 @item workdir
4365 like all Steps, this indicates the directory where the build will take
4366 place. Source Steps are special in that they perform some operations
4367 outside of the workdir (like creating the workdir itself).
4369 @item alwaysUseLatest
4370 if True, bypass the usual ``update to the last Change'' behavior, and
4371 always update to the latest changes instead.
4373 @item retry
4374 If set, this specifies a tuple of @code{(delay, repeats)} which means
4375 that when a full VC checkout fails, it should be retried up to
4376 @var{repeats} times, waiting @var{delay} seconds between attempts. If
4377 you don't provide this, it defaults to @code{None}, which means VC
4378 operations should not be retried. This is provided to make life easier
4379 for buildslaves which are stuck behind poor network connections.
4381 @end table
4384 My habit as a developer is to do a @code{cvs update} and @code{make} each
4385 morning. Problems can occur, either because of bad code being checked in, or
4386 by incomplete dependencies causing a partial rebuild to fail where a
4387 complete from-scratch build might succeed. A quick Builder which emulates
4388 this incremental-build behavior would use the @code{mode='update'}
4389 setting.
4391 On the other hand, other kinds of dependency problems can cause a clean
4392 build to fail where a partial build might succeed. This frequently results
4393 from a link step that depends upon an object file that was removed from a
4394 later version of the tree: in the partial tree, the object file is still
4395 around (even though the Makefiles no longer know how to create it).
4397 ``official'' builds (traceable builds performed from a known set of
4398 source revisions) are always done as clean builds, to make sure it is
4399 not influenced by any uncontrolled factors (like leftover files from a
4400 previous build). A ``full'' Builder which behaves this way would want
4401 to use the @code{mode='clobber'} setting.
4403 Each VC system has a corresponding source checkout class: their
4404 arguments are described on the following pages.
4407 @menu
4408 * CVS::                         
4409 * SVN::                         
4410 * Darcs::                       
4411 * Mercurial::                   
4412 * Arch::                        
4413 * Bazaar::                      
4414 * Bzr::                         
4415 * P4::                          
4416 * Git::                         
4417 @end menu
4419 @node CVS, SVN, Source Checkout, Source Checkout
4420 @subsubsection CVS
4421 @cindex CVS Checkout
4422 @bsindex buildbot.steps.source.CVS
4425 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
4426 CVS} checkout or update. It takes the following arguments:
4428 @table @code
4429 @item cvsroot
4430 (required): specify the CVSROOT value, which points to a CVS
4431 repository, probably on a remote machine. For example, the cvsroot
4432 value you would use to get a copy of the Buildbot source code is
4433 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
4435 @item cvsmodule
4436 (required): specify the cvs @code{module}, which is generally a
4437 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
4438 code is @code{buildbot}.
4440 @item branch
4441 a string which will be used in a @code{-r} argument. This is most
4442 useful for specifying a branch to work on. Defaults to @code{HEAD}.
4444 @item global_options
4445 a list of flags to be put before the verb in the CVS command.
4447 @item checkoutDelay
4448 if set, the number of seconds to put between the timestamp of the last
4449 known Change and the value used for the @code{-D} option. Defaults to
4450 half of the parent Build's treeStableTimer.
4452 @end table
4455 @node SVN, Darcs, CVS, Source Checkout
4456 @subsubsection SVN
4458 @cindex SVN Checkout
4459 @bsindex buildbot.steps.source.SVN
4462 The @code{SVN} build step performs a
4463 @uref{http://subversion.tigris.org, Subversion} checkout or update.
4464 There are two basic ways of setting up the checkout step, depending
4465 upon whether you are using multiple branches or not.
4467 If all of your builds use the same branch, then you should create the
4468 @code{SVN} step with the @code{svnurl} argument:
4470 @table @code
4471 @item svnurl
4472 (required): this specifies the @code{URL} argument that will be given
4473 to the @code{svn checkout} command. It dictates both where the
4474 repository is located and which sub-tree should be extracted. In this
4475 respect, it is like a combination of the CVS @code{cvsroot} and
4476 @code{cvsmodule} arguments. For example, if you are using a remote
4477 Subversion repository which is accessible through HTTP at a URL of
4478 @code{http://svn.example.com/repos}, and you wanted to check out the
4479 @code{trunk/calc} sub-tree, you would use
4480 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
4481 to your @code{SVN} step.
4482 @end table
4484 If, on the other hand, you are building from multiple branches, then
4485 you should create the @code{SVN} step with the @code{baseURL} and
4486 @code{defaultBranch} arguments instead:
4488 @table @code
4489 @item baseURL
4490 (required): this specifies the base repository URL, to which a branch
4491 name will be appended. It should probably end in a slash.
4493 @item defaultBranch
4494 this specifies the name of the branch to use when a Build does not
4495 provide one of its own. This will be appended to @code{baseURL} to
4496 create the string that will be passed to the @code{svn checkout}
4497 command.
4498 @end table
4500 If you are using branches, you must also make sure your
4501 @code{ChangeSource} will report the correct branch names.
4503 @heading branch example
4505 Let's suppose that the ``MyProject'' repository uses branches for the
4506 trunk, for various users' individual development efforts, and for
4507 several new features that will require some amount of work (involving
4508 multiple developers) before they are ready to merge onto the trunk.
4509 Such a repository might be organized as follows:
4511 @example
4512 svn://svn.example.org/MyProject/trunk
4513 svn://svn.example.org/MyProject/branches/User1/foo
4514 svn://svn.example.org/MyProject/branches/User1/bar
4515 svn://svn.example.org/MyProject/branches/User2/baz
4516 svn://svn.example.org/MyProject/features/newthing
4517 svn://svn.example.org/MyProject/features/otherthing
4518 @end example
4520 Further assume that we want the Buildbot to run tests against the
4521 trunk and against all the feature branches (i.e., do a
4522 checkout/compile/build of branch X when a file has been changed on
4523 branch X, when X is in the set [trunk, features/newthing,
4524 features/otherthing]). We do not want the Buildbot to automatically
4525 build any of the user branches, but it should be willing to build a
4526 user branch when explicitly requested (most likely by the user who
4527 owns that branch).
4529 There are three things that need to be set up to accomodate this
4530 system. The first is a ChangeSource that is capable of identifying the
4531 branch which owns any given file. This depends upon a user-supplied
4532 function, in an external program that runs in the SVN commit hook and
4533 connects to the buildmaster's @code{PBChangeSource} over a TCP
4534 connection. (you can use the ``@code{buildbot sendchange}'' utility
4535 for this purpose, but you will still need an external program to
4536 decide what value should be passed to the @code{--branch=} argument).
4537 For example, a change to a file with the SVN url of
4538 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
4539 be broken down into a Change instance with
4540 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
4542 The second piece is an @code{AnyBranchScheduler} which will pay
4543 attention to the desired branches. It will not pay attention to the
4544 user branches, so it will not automatically start builds in response
4545 to changes there. The AnyBranchScheduler class requires you to
4546 explicitly list all the branches you want it to use, but it would not
4547 be difficult to write a subclass which used
4548 @code{branch.startswith('features/'} to remove the need for this
4549 explicit list. Or, if you want to build user branches too, you can use
4550 AnyBranchScheduler with @code{branches=None} to indicate that you want
4551 it to pay attention to all branches.
4553 The third piece is an @code{SVN} checkout step that is configured to
4554 handle the branches correctly, with a @code{baseURL} value that
4555 matches the way the ChangeSource splits each file's URL into base,
4556 branch, and file.
4558 @example
4559 from buildbot.changes.pb import PBChangeSource
4560 from buildbot.scheduler import AnyBranchScheduler
4561 from buildbot.process import source, factory
4562 from buildbot.steps import source, shell
4564 c['change_source'] = PBChangeSource()
4565 s1 = AnyBranchScheduler('main',
4566                         ['trunk', 'features/newthing', 'features/otherthing'],
4567                         10*60, ['test-i386', 'test-ppc'])
4568 c['schedulers'] = [s1]
4570 f = factory.BuildFactory()
4571 f.addStep(source.SVN(mode='update',
4572                      baseURL='svn://svn.example.org/MyProject/',
4573                      defaultBranch='trunk'))
4574 f.addStep(shell.Compile(command="make all"))
4575 f.addStep(shell.Test(command="make test"))
4577 c['builders'] = [
4578   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
4579                        'factory':f @},
4580   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
4581                       'factory':f @},
4583 @end example
4585 In this example, when a change arrives with a @code{branch} attribute
4586 of ``trunk'', the resulting build will have an SVN step that
4587 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
4588 ``trunk'' (the branch name) to get the correct svn command. If the
4589 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
4590 will concatenate ``svn://svn.example.org/MyProject/'' with
4591 ``features/newthing'' to get the svnurl for checkout.
4593 @node Darcs, Mercurial, SVN, Source Checkout
4594 @subsubsection Darcs
4596 @cindex Darcs Checkout
4597 @bsindex buildbot.steps.source.Darcs
4600 The @code{Darcs} build step performs a
4601 @uref{http://darcs.net/, Darcs} checkout or update.
4603 Like @xref{SVN}, this step can either be configured to always check
4604 out a specific tree, or set up to pull from a particular branch that
4605 gets specified separately for each build. Also like SVN, the
4606 repository URL given to Darcs is created by concatenating a
4607 @code{baseURL} with the branch name, and if no particular branch is
4608 requested, it uses a @code{defaultBranch}. The only difference in
4609 usage is that each potential Darcs repository URL must point to a
4610 fully-fledged repository, whereas SVN URLs usually point to sub-trees
4611 of the main Subversion repository. In other words, doing an SVN
4612 checkout of @code{baseURL} is legal, but silly, since you'd probably
4613 wind up with a copy of every single branch in the whole repository.
4614 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
4615 the parent directory of a collection of Darcs repositories is not
4616 itself a valid repository.
4618 The Darcs step takes the following arguments:
4620 @table @code
4621 @item repourl
4622 (required unless @code{baseURL} is provided): the URL at which the
4623 Darcs source repository is available.
4625 @item baseURL
4626 (required unless @code{repourl} is provided): the base repository URL,
4627 to which a branch name will be appended. It should probably end in a
4628 slash.
4630 @item defaultBranch
4631 (allowed if and only if @code{baseURL} is provided): this specifies
4632 the name of the branch to use when a Build does not provide one of its
4633 own. This will be appended to @code{baseURL} to create the string that
4634 will be passed to the @code{darcs get} command.
4635 @end table
4637 @node Mercurial, Arch, Darcs, Source Checkout
4638 @subsubsection Mercurial
4640 @cindex Mercurial Checkout
4641 @bsindex buildbot.steps.source.Mercurial
4644 The @code{Mercurial} build step performs a
4645 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
4646 or update.
4648 Branches are handled just like @xref{Darcs}.
4650 The Mercurial step takes the following arguments:
4652 @table @code
4653 @item repourl
4654 (required unless @code{baseURL} is provided): the URL at which the
4655 Mercurial source repository is available.
4657 @item baseURL
4658 (required unless @code{repourl} is provided): the base repository URL,
4659 to which a branch name will be appended. It should probably end in a
4660 slash.
4662 @item defaultBranch
4663 (allowed if and only if @code{baseURL} is provided): this specifies
4664 the name of the branch to use when a Build does not provide one of its
4665 own. This will be appended to @code{baseURL} to create the string that
4666 will be passed to the @code{hg clone} command.
4667 @end table
4670 @node Arch, Bazaar, Mercurial, Source Checkout
4671 @subsubsection Arch
4673 @cindex Arch Checkout
4674 @bsindex buildbot.steps.source.Arch
4677 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
4678 Arch} checkout or update using the @code{tla} client. It takes the
4679 following arguments:
4681 @table @code
4682 @item url
4683 (required): this specifies the URL at which the Arch source archive is
4684 available.
4686 @item version
4687 (required): this specifies which ``development line'' (like a branch)
4688 should be used. This provides the default branch name, but individual
4689 builds may specify a different one.
4691 @item archive
4692 (optional): Each repository knows its own archive name. If this
4693 parameter is provided, it must match the repository's archive name.
4694 The parameter is accepted for compatibility with the @code{Bazaar}
4695 step, below.
4697 @end table
4699 @node Bazaar, Bzr, Arch, Source Checkout
4700 @subsubsection Bazaar
4702 @cindex Bazaar Checkout
4703 @bsindex buildbot.steps.source.Bazaar
4706 @code{Bazaar} is an alternate implementation of the Arch VC system,
4707 which uses a client named @code{baz}. The checkout semantics are just
4708 different enough from @code{tla} that there is a separate BuildStep for
4711 It takes exactly the same arguments as @code{Arch}, except that the
4712 @code{archive=} parameter is required. (baz does not emit the archive
4713 name when you do @code{baz register-archive}, so we must provide it
4714 ourselves).
4717 @node Bzr, P4, Bazaar, Source Checkout
4718 @subsubsection Bzr
4720 @cindex Bzr Checkout
4721 @bsindex buildbot.steps.source.Bzr
4723 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
4724 as simply ``Bazaar''. The repository-vs-workspace model is similar to
4725 Darcs, but it uses a strictly linear sequence of revisions (one
4726 history per branch) like Arch. Branches are put in subdirectories.
4727 This makes it look very much like Mercurial, so it takes the same
4728 arguments:
4730 @table @code
4732 @item repourl
4733 (required unless @code{baseURL} is provided): the URL at which the
4734 Bzr source repository is available.
4736 @item baseURL
4737 (required unless @code{repourl} is provided): the base repository URL,
4738 to which a branch name will be appended. It should probably end in a
4739 slash.
4741 @item defaultBranch
4742 (allowed if and only if @code{baseURL} is provided): this specifies
4743 the name of the branch to use when a Build does not provide one of its
4744 own. This will be appended to @code{baseURL} to create the string that
4745 will be passed to the @code{bzr checkout} command.
4746 @end table
4750 @node P4, Git, Bzr, Source Checkout
4751 @subsubsection P4
4753 @cindex Perforce Update
4754 @bsindex buildbot.steps.source.P4
4755 @c TODO @bsindex buildbot.steps.source.P4Sync
4758 The @code{P4} build step creates a @uref{http://www.perforce.com/,
4759 Perforce} client specification and performs an update.
4761 @table @code
4762 @item p4base
4763 A view into the Perforce depot without branch name or trailing "...".
4764 Typically "//depot/proj/".
4765 @item defaultBranch
4766 A branch name to append on build requests if none is specified.
4767 Typically "trunk".
4768 @item p4port
4769 (optional): the host:port string describing how to get to the P4 Depot
4770 (repository), used as the -p argument for all p4 commands.
4771 @item p4user
4772 (optional): the Perforce user, used as the -u argument to all p4
4773 commands.
4774 @item p4passwd
4775 (optional): the Perforce password, used as the -p argument to all p4
4776 commands.
4777 @item p4extra_views
4778 (optional): a list of (depotpath, clientpath) tuples containing extra
4779 views to be mapped into the client specification. Both will have
4780 "/..." appended automatically. The client name and source directory
4781 will be prepended to the client path.
4782 @item p4client
4783 (optional): The name of the client to use. In mode='copy' and
4784 mode='update', it's particularly important that a unique name is used
4785 for each checkout directory to avoid incorrect synchronization. For
4786 this reason, Python percent substitution will be performed on this value
4787 to replace %(slave)s with the slave name and %(builder)s with the
4788 builder name. The default is "buildbot_%(slave)s_%(build)s".
4789 @end table
4792 @node Git,  , P4, Source Checkout
4793 @subsubsection Git
4795 @cindex Git Checkout
4796 @bsindex buildbot.steps.source.Git
4798 The @code{Git} build step clones or updates a @uref{http://git.or.cz/,
4799 Git} repository and checks out the specified branch or revision. Note
4800 that the buildbot supports Git version 1.2.0 and later: earlier
4801 versions (such as the one shipped in Ubuntu 'Dapper') do not support
4802 the @command{git init} command that the buildbot uses.
4804 The Git step takes the following arguments:
4806 @table @code
4807 @item repourl
4808 (required): the URL of the upstream Git repository.
4810 @item branch
4811 (optional): this specifies the name of the branch to use when a Build
4812 does not provide one of its own. If this this parameter is not
4813 specified, and the Build does not provide a branch, the ``master''
4814 branch will be used.
4815 @end table
4818 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
4819 @subsection ShellCommand
4821 @bsindex buildbot.steps.shell.ShellCommand
4822 @c TODO @bsindex buildbot.steps.shell.TreeSize
4824 This is a useful base class for just about everything you might want
4825 to do during a build (except for the initial source checkout). It runs
4826 a single command in a child shell on the buildslave. All stdout/stderr
4827 is recorded into a LogFile. The step finishes with a status of FAILURE
4828 if the command's exit code is non-zero, otherwise it has a status of
4829 SUCCESS.
4831 The preferred way to specify the command is with a list of argv strings,
4832 since this allows for spaces in filenames and avoids doing any fragile
4833 shell-escaping. You can also specify the command with a single string, in
4834 which case the string is given to '/bin/sh -c COMMAND' for parsing.
4836 All ShellCommands are run by default in the ``workdir'', which
4837 defaults to the ``@file{build}'' subdirectory of the slave builder's
4838 base directory. The absolute path of the workdir will thus be the
4839 slave's basedir (set as an option to @code{buildbot create-slave},
4840 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
4841 builder's @code{c['builddir']} key in master.cfg) plus the workdir
4842 itself (a class-level attribute of the BuildFactory, defaults to
4843 ``@file{build}'').
4845 @code{ShellCommand} arguments:
4847 @table @code
4848 @item command
4849 a list of strings (preferred) or single string (discouraged) which
4850 specifies the command to be run. A list of strings is preferred
4851 because it can be used directly as an argv array. Using a single
4852 string (with embedded spaces) requires the buildslave to pass the
4853 string to /bin/sh for interpretation, which raises all sorts of
4854 difficult questions about how to escape or interpret shell
4855 metacharacters.
4857 @item env
4858 a dictionary of environment strings which will be added to the child
4859 command's environment. For example, to run tests with a different i18n
4860 language setting, you might use
4862 @example
4863 f.addStep(ShellCommand(command=["make", "test"],
4864                        env=@{'LANG': 'fr_FR'@}))
4865 @end example
4867 These variable settings will override any existing ones in the
4868 buildslave's environment or the environment specified in the
4869 Builder. The exception is PYTHONPATH, which is merged
4870 with (actually prepended to) any existing $PYTHONPATH setting. The
4871 value is treated as a list of directories to prepend, and a single
4872 string is treated like a one-item list. For example, to prepend both
4873 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
4874 to any existing $PYTHONPATH setting, you would do something like the
4875 following:
4877 @example
4878 f.addStep(ShellCommand(
4879               command=["make", "test"],
4880               env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
4881                                    "/home/buildbot/lib/python"] @}))
4882 @end example
4884 @item want_stdout
4885 if False, stdout from the child process is discarded rather than being
4886 sent to the buildmaster for inclusion in the step's LogFile.
4888 @item want_stderr
4889 like @code{want_stdout} but for stderr. Note that commands run through
4890 a PTY do not have separate stdout/stderr streams: both are merged into
4891 stdout.
4893 @item logfiles
4894 Sometimes commands will log interesting data to a local file, rather
4895 than emitting everything to stdout or stderr. For example, Twisted's
4896 ``trial'' command (which runs unit tests) only presents summary
4897 information to stdout, and puts the rest into a file named
4898 @file{_trial_temp/test.log}. It is often useful to watch these files
4899 as the command runs, rather than using @command{/bin/cat} to dump
4900 their contents afterwards.
4902 The @code{logfiles=} argument allows you to collect data from these
4903 secondary logfiles in near-real-time, as the step is running. It
4904 accepts a dictionary which maps from a local Log name (which is how
4905 the log data is presented in the build results) to a remote filename
4906 (interpreted relative to the build's working directory). Each named
4907 file will be polled on a regular basis (every couple of seconds) as
4908 the build runs, and any new text will be sent over to the buildmaster.
4910 @example
4911 f.addStep(ShellCommand(
4912               command=["make", "test"],
4913               logfiles=@{"triallog": "_trial_temp/test.log"@}))
4914 @end example
4917 @item timeout
4918 if the command fails to produce any output for this many seconds, it
4919 is assumed to be locked up and will be killed.
4921 @item description
4922 This will be used to describe the command (on the Waterfall display)
4923 while the command is still running. It should be a single
4924 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
4925 form is a list of short strings, which allows the HTML Waterfall
4926 display to create narrower columns by emitting a <br> tag between each
4927 word. You may also provide a single string.
4929 @item descriptionDone
4930 This will be used to describe the command once it has finished. A
4931 simple noun like ``compile'' or ``tests'' should be used. Like
4932 @code{description}, this may either be a list of short strings or a
4933 single string.
4935 If neither @code{description} nor @code{descriptionDone} are set, the
4936 actual command arguments will be used to construct the description.
4937 This may be a bit too wide to fit comfortably on the Waterfall
4938 display.
4940 @example
4941 f.addStep(ShellCommand(command=["make", "test"],
4942                        description=["testing"],
4943                        descriptionDone=["tests"]))
4944 @end example
4946 @end table
4948 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
4949 @subsection Simple ShellCommand Subclasses
4951 Several subclasses of ShellCommand are provided as starting points for
4952 common build steps. These are all very simple: they just override a few
4953 parameters so you don't have to specify them yourself, making the master.cfg
4954 file less verbose.
4956 @menu
4957 * Configure::                   
4958 * Compile::                     
4959 * Test::                        
4960 * TreeSize::                    
4961 * PerlModuleTest::              
4962 * SetProperty::                 
4963 @end menu
4965 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
4966 @subsubsection Configure
4968 @bsindex buildbot.steps.shell.Configure
4970 This is intended to handle the @code{./configure} step from
4971 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
4972 MakeMaker.pm-style modules. The default command is @code{./configure}
4973 but you can change this by providing a @code{command=} parameter.
4975 @node Compile, Test, Configure, Simple ShellCommand Subclasses
4976 @subsubsection Compile
4978 @bsindex buildbot.steps.shell.Compile
4980 This is meant to handle compiling or building a project written in C.
4981 The default command is @code{make all}. When the compile is finished,
4982 the log file is scanned for GCC warning messages, a summary log is
4983 created with any problems that were seen, and the step is marked as
4984 WARNINGS if any were discovered. The number of warnings is stored in a
4985 Build Property named ``warnings-count'', which is accumulated over all
4986 Compile steps (so if two warnings are found in one step, and three are
4987 found in another step, the overall build will have a
4988 ``warnings-count'' property of 5.
4990 The default regular expression used to detect a warning is
4991 @code{'.*warning[: ].*'} , which is fairly liberal and may cause
4992 false-positives. To use a different regexp, provide a
4993 @code{warningPattern=} argument, or use a subclass which sets the
4994 @code{warningPattern} attribute:
4996 @example
4997 f.addStep(Compile(command=["make", "test"],
4998                   warningPattern="^Warning: "))
4999 @end example
5001 The @code{warningPattern=} can also be a pre-compiled python regexp
5002 object: this makes it possible to add flags like @code{re.I} (to use
5003 case-insensitive matching).
5005 (TODO: this step needs to be extended to look for GCC error messages
5006 as well, and collect them into a separate logfile, along with the
5007 source code filenames involved).
5010 @node Test, TreeSize, Compile, Simple ShellCommand Subclasses
5011 @subsubsection Test
5013 @bsindex buildbot.steps.shell.Test
5015 This is meant to handle unit tests. The default command is @code{make
5016 test}, and the @code{warnOnFailure} flag is set.
5018 @node TreeSize, PerlModuleTest, Test, Simple ShellCommand Subclasses
5019 @subsubsection TreeSize
5021 @bsindex buildbot.steps.shell.TreeSize
5023 This is a simple command that uses the 'du' tool to measure the size
5024 of the code tree. It puts the size (as a count of 1024-byte blocks,
5025 aka 'KiB' or 'kibibytes') on the step's status text, and sets a build
5026 property named 'tree-size-KiB' with the same value.
5028 @node PerlModuleTest, SetProperty, TreeSize, Simple ShellCommand Subclasses
5029 @subsubsection PerlModuleTest
5031 @bsindex buildbot.steps.shell.PerlModuleTest
5033 This is a simple command that knows how to run tests of perl modules.
5034 It parses the output to determine the number of tests passed and
5035 failed and total number executed, saving the results for later query.
5037 @node SetProperty,  , PerlModuleTest, Simple ShellCommand Subclasses
5038 @subsubsection SetProperty
5040 @bsindex buildbot.steps.shell.SetProperty
5042 This buildstep is similar to ShellCommand, except that it captures the
5043 output of the command into a property.  It is usually used like this:
5045 @example
5046 f.addStep(SetProperty(command="uname -a", property="uname"))
5047 @end example
5049 This runs @code{uname -a} and captures its stdout, stripped of leading
5050 and trailing whitespace, in the property "uname".  To avoid stripping,
5051 add @code{strip=False}.  The @code{property} argument can be specified
5052 as a @code{WithProperties} object.
5054 The more advanced usage allows you to specify a function to extract
5055 properties from the command output.  Here you can use regular
5056 expressions, string interpolation, or whatever you would like.
5057 The function is called with three arguments: the exit status of the
5058 command, its standard output as a string, and its standard error as
5059 a string.  It should return a dictionary containing all new properties.
5061 @example
5062 def glob2list(rc, stdout, stderr):
5063     jpgs = [ l.strip() for l in stdout.split('\n') ]
5064     return @{ 'jpgs' : jpgs @}
5065 f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
5066 @end example
5068 Note that any ordering relationship of the contents of stdout and
5069 stderr is lost.  For example, given
5071 @example
5072 f.addStep(SetProperty(
5073     command="echo output1; echo error >&2; echo output2", 
5074     extract_fn=my_extract))
5075 @end example
5077 Then @code{my_extract} will see @code{stdout="output1\noutput2\n"}
5078 and @code{stderr="error\n"}.
5080 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
5081 @subsection Python BuildSteps
5083 Here are some BuildSteps that are specifcally useful for projects
5084 implemented in Python.
5086 @menu
5087 * BuildEPYDoc::                 
5088 * PyFlakes::                    
5089 @end menu
5091 @node BuildEPYDoc, PyFlakes, Python BuildSteps, Python BuildSteps
5092 @subsubsection BuildEPYDoc
5094 @bsindex buildbot.steps.python.BuildEPYDoc
5096 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
5097 API documentation for Python modules from their docstrings. It reads
5098 all the .py files from your source tree, processes the docstrings
5099 therein, and creates a large tree of .html files (or a single .pdf
5100 file).
5102 The @code{buildbot.steps.python.BuildEPYDoc} step will run
5103 @command{epydoc} to produce this API documentation, and will count the
5104 errors and warnings from its output.
5106 You must supply the command line to be used. The default is
5107 @command{make epydocs}, which assumes that your project has a Makefile
5108 with an ``epydocs'' target. You might wish to use something like
5109 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
5110 to add @command{--pdf} to generate a PDF file instead of a large tree
5111 of HTML files.
5113 The API docs are generated in-place in the build tree (under the
5114 workdir, in the subdirectory controlled by the ``-o'' argument). To
5115 make them useful, you will probably have to copy them to somewhere
5116 they can be read. A command like @command{rsync -ad apiref/
5117 dev.example.com:~public_html/current-apiref/} might be useful. You
5118 might instead want to bundle them into a tarball and publish it in the
5119 same place where the generated install tarball is placed.
5121 @example
5122 from buildbot.steps.python import BuildEPYDoc
5125 f.addStep(BuildEPYDoc(command=["epydoc", "-o", "apiref", "source/mypkg"]))
5126 @end example
5129 @node PyFlakes,  , BuildEPYDoc, Python BuildSteps
5130 @subsubsection PyFlakes
5132 @bsindex buildbot.steps.python.PyFlakes
5134 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
5135 to perform basic static analysis of Python code to look for simple
5136 errors, like missing imports and references of undefined names. It is
5137 like a fast and simple form of the C ``lint'' program. Other tools
5138 (like pychecker) provide more detailed results but take longer to run.
5140 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
5141 count the various kinds of errors and warnings it detects.
5143 You must supply the command line to be used. The default is
5144 @command{make pyflakes}, which assumes you have a top-level Makefile
5145 with a ``pyflakes'' target. You might want to use something like
5146 @command{pyflakes .} or @command{pyflakes src}.
5148 @example
5149 from buildbot.steps.python import PyFlakes
5152 f.addStep(PyFlakes(command=["pyflakes", "src"]))
5153 @end example
5156 @node Transferring Files, Triggering Schedulers, Python BuildSteps, Build Steps
5157 @subsection Transferring Files
5159 @cindex File Transfer
5160 @bsindex buildbot.steps.transfer.FileUpload
5161 @bsindex buildbot.steps.transfer.FileDownload
5163 Most of the work involved in a build will take place on the
5164 buildslave. But occasionally it is useful to do some work on the
5165 buildmaster side. The most basic way to involve the buildmaster is
5166 simply to move a file from the slave to the master, or vice versa.
5167 There are a pair of BuildSteps named @code{FileUpload} and
5168 @code{FileDownload} to provide this functionality. @code{FileUpload}
5169 moves a file @emph{up to} the master, while @code{FileDownload} moves
5170 a file @emph{down from} the master.
5172 As an example, let's assume that there is a step which produces an
5173 HTML file within the source tree that contains some sort of generated
5174 project documentation. We want to move this file to the buildmaster,
5175 into a @file{~/public_html} directory, so it can be visible to
5176 developers. This file will wind up in the slave-side working directory
5177 under the name @file{docs/reference.html}. We want to put it into the
5178 master-side @file{~/public_html/ref.html}.
5180 @example
5181 from buildbot.steps.shell import ShellCommand
5182 from buildbot.steps.transfer import FileUpload
5184 f.addStep(ShellCommand(command=["make", "docs"]))
5185 f.addStep(FileUpload(slavesrc="docs/reference.html",
5186                      masterdest="~/public_html/ref.html"))
5187 @end example
5189 The @code{masterdest=} argument will be passed to os.path.expanduser,
5190 so things like ``~'' will be expanded properly. Non-absolute paths
5191 will be interpreted relative to the buildmaster's base directory.
5192 Likewise, the @code{slavesrc=} argument will be expanded and
5193 interpreted relative to the builder's working directory.
5196 To move a file from the master to the slave, use the
5197 @code{FileDownload} command. For example, let's assume that some step
5198 requires a configuration file that, for whatever reason, could not be
5199 recorded in the source code repository or generated on the buildslave
5200 side:
5202 @example
5203 from buildbot.steps.shell import ShellCommand
5204 from buildbot.steps.transfer import FileUpload
5206 f.addStep(FileDownload(mastersrc="~/todays_build_config.txt",
5207                        slavedest="build_config.txt"))
5208 f.addStep(ShellCommand(command=["make", "config"]))
5209 @end example
5211 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
5212 relative to the buildmaster's base directory, and the
5213 @code{slavedest=} argument is relative to the builder's working
5214 directory. If the buildslave is running in @file{~buildslave}, and the
5215 builder's ``builddir'' is something like @file{tests-i386}, then the
5216 workdir is going to be @file{~buildslave/tests-i386/build}, and a
5217 @code{slavedest=} of @file{foo/bar.html} will get put in
5218 @file{~buildslave/tests-i386/build/foo/bar.html}. Both of these commands
5219 will create any missing intervening directories.
5221 @subheading Other Parameters
5223 The @code{maxsize=} argument lets you set a maximum size for the file
5224 to be transferred. This may help to avoid surprises: transferring a
5225 100MB coredump when you were expecting to move a 10kB status file
5226 might take an awfully long time. The @code{blocksize=} argument
5227 controls how the file is sent over the network: larger blocksizes are
5228 slightly more efficient but also consume more memory on each end, and
5229 there is a hard-coded limit of about 640kB.
5231 The @code{mode=} argument allows you to control the access permissions
5232 of the target file, traditionally expressed as an octal integer. The
5233 most common value is probably 0755, which sets the ``x'' executable
5234 bit on the file (useful for shell scripts and the like). The default
5235 value for @code{mode=} is None, which means the permission bits will
5236 default to whatever the umask of the writing process is. The default
5237 umask tends to be fairly restrictive, but at least on the buildslave
5238 you can make it less restrictive with a --umask command-line option at
5239 creation time (@pxref{Buildslave Options}).
5242 @node Triggering Schedulers, Writing New BuildSteps, Transferring Files, Build Steps
5243 @subsection Triggering Schedulers
5245 The counterpart to the Triggerable described in section
5246 @pxref{Triggerable Scheduler} is the Trigger BuildStep.
5248 @example
5249 from buildbot.steps.trigger import Trigger
5250 f.addStep(Trigger(schedulerNames=['build-prep'],
5251                   waitForFinish=True,
5252                   updateSourceStamp=True))
5253 @end example
5255 The @code{schedulerNames=} argument lists the Triggerables
5256 that should be triggered when this step is executed.  Note that
5257 it is possible, but not advisable, to create a cycle where a build
5258 continually triggers itself, because the schedulers are specified
5259 by name.
5261 If @code{waitForFinish} is True, then the step will not finish until
5262 all of the builds from the triggered schedulers have finished. If this
5263 argument is False (the default) or not given, then the buildstep
5264 succeeds immediately after triggering the schedulers.
5266 If @code{updateSourceStamp} is True (the default), then step updates
5267 the SourceStamp given to the Triggerables to include
5268 @code{got_revision} (the revision actually used in this build) as
5269 @code{revision} (the revision to use in the triggered builds). This is
5270 useful to ensure that all of the builds use exactly the same
5271 SourceStamp, even if other Changes have occurred while the build was
5272 running.
5274 @node Writing New BuildSteps,  , Triggering Schedulers, Build Steps
5275 @subsection Writing New BuildSteps
5277 While it is a good idea to keep your build process self-contained in
5278 the source code tree, sometimes it is convenient to put more
5279 intelligence into your Buildbot configuration. One was to do this is
5280 to write a custom BuildStep. Once written, this Step can be used in
5281 the @file{master.cfg} file.
5283 The best reason for writing a custom BuildStep is to better parse the
5284 results of the command being run. For example, a BuildStep that knows
5285 about JUnit could look at the logfiles to determine which tests had
5286 been run, how many passed and how many failed, and then report more
5287 detailed information than a simple @code{rc==0} -based ``good/bad''
5288 decision.
5290 TODO: add more description of BuildSteps.
5292 @menu
5293 * BuildStep LogFiles::          
5294 * Reading Logfiles::            
5295 * Adding LogObservers::         
5296 * BuildStep URLs::              
5297 @end menu
5299 @node BuildStep LogFiles, Reading Logfiles, Writing New BuildSteps, Writing New BuildSteps
5300 @subsubsection BuildStep LogFiles
5302 Each BuildStep has a collection of ``logfiles''. Each one has a short
5303 name, like ``stdio'' or ``warnings''. Each LogFile contains an
5304 arbitrary amount of text, usually the contents of some output file
5305 generated during a build or test step, or a record of everything that
5306 was printed to stdout/stderr during the execution of some command.
5308 These LogFiles are stored to disk, so they can be retrieved later.
5310 Each can contain multiple ``channels'', generally limited to three
5311 basic ones: stdout, stderr, and ``headers''. For example, when a
5312 ShellCommand runs, it writes a few lines to the ``headers'' channel to
5313 indicate the exact argv strings being run, which directory the command
5314 is being executed in, and the contents of the current environment
5315 variables. Then, as the command runs, it adds a lot of ``stdout'' and
5316 ``stderr'' messages. When the command finishes, a final ``header''
5317 line is added with the exit code of the process.
5319 Status display plugins can format these different channels in
5320 different ways. For example, the web page shows LogFiles as text/html,
5321 with header lines in blue text, stdout in black, and stderr in red. A
5322 different URL is available which provides a text/plain format, in
5323 which stdout and stderr are collapsed together, and header lines are
5324 stripped completely. This latter option makes it easy to save the
5325 results to a file and run @command{grep} or whatever against the
5326 output.
5328 Each BuildStep contains a mapping (implemented in a python dictionary)
5329 from LogFile name to the actual LogFile objects. Status plugins can
5330 get a list of LogFiles to display, for example, a list of HREF links
5331 that, when clicked, provide the full contents of the LogFile.
5333 @heading Using LogFiles in custom BuildSteps
5335 The most common way for a custom BuildStep to use a LogFile is to
5336 summarize the results of a ShellCommand (after the command has
5337 finished running). For example, a compile step with thousands of lines
5338 of output might want to create a summary of just the warning messages.
5339 If you were doing this from a shell, you would use something like:
5341 @example
5342 grep "warning:" output.log >warnings.log
5343 @end example
5345 In a custom BuildStep, you could instead create a ``warnings'' LogFile
5346 that contained the same text. To do this, you would add code to your
5347 @code{createSummary} method that pulls lines from the main output log
5348 and creates a new LogFile with the results:
5350 @example
5351     def createSummary(self, log):
5352         warnings = []
5353         for line in log.readlines():
5354             if "warning:" in line:
5355                 warnings.append()
5356         self.addCompleteLog('warnings', "".join(warnings))
5357 @end example
5359 This example uses the @code{addCompleteLog} method, which creates a
5360 new LogFile, puts some text in it, and then ``closes'' it, meaning
5361 that no further contents will be added. This LogFile will appear in
5362 the HTML display under an HREF with the name ``warnings'', since that
5363 is the name of the LogFile.
5365 You can also use @code{addHTMLLog} to create a complete (closed)
5366 LogFile that contains HTML instead of plain text. The normal LogFile
5367 will be HTML-escaped if presented through a web page, but the HTML
5368 LogFile will not. At the moment this is only used to present a pretty
5369 HTML representation of an otherwise ugly exception traceback when
5370 something goes badly wrong during the BuildStep.
5372 In contrast, you might want to create a new LogFile at the beginning
5373 of the step, and add text to it as the command runs. You can create
5374 the LogFile and attach it to the build by calling @code{addLog}, which
5375 returns the LogFile object. You then add text to this LogFile by
5376 calling methods like @code{addStdout} and @code{addHeader}. When you
5377 are done, you must call the @code{finish} method so the LogFile can be
5378 closed. It may be useful to create and populate a LogFile like this
5379 from a LogObserver method @xref{Adding LogObservers}.
5381 The @code{logfiles=} argument to @code{ShellCommand} (see
5382 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
5383 by asking the buildslave to watch a actual file on disk. The
5384 buildslave will look for additions in the target file and report them
5385 back to the BuildStep. These additions will be added to the LogFile by
5386 calling @code{addStdout}. These secondary LogFiles can be used as the
5387 source of a LogObserver just like the normal ``stdio'' LogFile.
5389 @node Reading Logfiles, Adding LogObservers, BuildStep LogFiles, Writing New BuildSteps
5390 @subsubsection Reading Logfiles
5392 Once a LogFile has been added to a BuildStep with @code{addLog()},
5393 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
5394 your BuildStep can retrieve it by using @code{getLog()}:
5396 @example
5397 class MyBuildStep(ShellCommand):
5398     logfiles = @{ "nodelog": "_test/node.log" @}
5400     def evaluateCommand(self, cmd):
5401         nodelog = self.getLog("nodelog")
5402         if "STARTED" in nodelog.getText():
5403             return SUCCESS
5404         else:
5405             return FAILURE
5406 @end example
5408 For a complete list of the methods you can call on a LogFile, please
5409 see the docstrings on the @code{IStatusLog} class in
5410 @file{buildbot/interfaces.py}.
5413 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
5414 @subsubsection Adding LogObservers
5416 @cindex LogObserver
5417 @cindex LogLineObserver
5419 Most shell commands emit messages to stdout or stderr as they operate,
5420 especially if you ask them nicely with a @code{--verbose} flag of some
5421 sort. They may also write text to a log file while they run. Your
5422 BuildStep can watch this output as it arrives, to keep track of how
5423 much progress the command has made. You can get a better measure of
5424 progress by counting the number of source files compiled or test cases
5425 run than by merely tracking the number of bytes that have been written
5426 to stdout. This improves the accuracy and the smoothness of the ETA
5427 display.
5429 To accomplish this, you will need to attach a @code{LogObserver} to
5430 one of the log channels, most commonly to the ``stdio'' channel but
5431 perhaps to another one which tracks a log file. This observer is given
5432 all text as it is emitted from the command, and has the opportunity to
5433 parse that output incrementally. Once the observer has decided that
5434 some event has occurred (like a source file being compiled), it can
5435 use the @code{setProgress} method to tell the BuildStep about the
5436 progress that this event represents.
5438 There are a number of pre-built @code{LogObserver} classes that you
5439 can choose from (defined in @code{buildbot.process.buildstep}, and of
5440 course you can subclass them to add further customization. The
5441 @code{LogLineObserver} class handles the grunt work of buffering and
5442 scanning for end-of-line delimiters, allowing your parser to operate
5443 on complete stdout/stderr lines. (Lines longer than a set maximum
5444 length are dropped; the maximum defaults to 16384 bytes, but you can
5445 change it by calling @code{setMaxLineLength()} on your
5446 @code{LogLineObserver} instance.  Use @code{sys.maxint} for effective
5447 infinity.)
5449 For example, let's take a look at the @code{TrialTestCaseCounter},
5450 which is used by the Trial step to count test cases as they are run.
5451 As Trial executes, it emits lines like the following:
5453 @example
5454 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
5455 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
5456 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
5457 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
5458 @end example
5460 When the tests are finished, trial emits a long line of ``======'' and
5461 then some lines which summarize the tests that failed. We want to
5462 avoid parsing these trailing lines, because their format is less
5463 well-defined than the ``[OK]'' lines.
5465 The parser class looks like this:
5467 @example
5468 from buildbot.process.buildstep import LogLineObserver
5470 class TrialTestCaseCounter(LogLineObserver):
5471     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
5472     numTests = 0
5473     finished = False
5475     def outLineReceived(self, line):
5476         if self.finished:
5477             return
5478         if line.startswith("=" * 40):
5479             self.finished = True
5480             return
5482         m = self._line_re.search(line.strip())
5483         if m:
5484             testname, result = m.groups()
5485             self.numTests += 1
5486             self.step.setProgress('tests', self.numTests)
5487 @end example
5489 This parser only pays attention to stdout, since that's where trial
5490 writes the progress lines. It has a mode flag named @code{finished} to
5491 ignore everything after the ``===='' marker, and a scary-looking
5492 regular expression to match each line while hopefully ignoring other
5493 messages that might get displayed as the test runs.
5495 Each time it identifies a test has been completed, it increments its
5496 counter and delivers the new progress value to the step with
5497 @code{self.step.setProgress}. This class is specifically measuring
5498 progress along the ``tests'' metric, in units of test cases (as
5499 opposed to other kinds of progress like the ``output'' metric, which
5500 measures in units of bytes). The Progress-tracking code uses each
5501 progress metric separately to come up with an overall completion
5502 percentage and an ETA value.
5504 To connect this parser into the @code{Trial} BuildStep,
5505 @code{Trial.__init__} ends with the following clause:
5507 @example
5508         # this counter will feed Progress along the 'test cases' metric
5509         counter = TrialTestCaseCounter()
5510         self.addLogObserver('stdio', counter)
5511 @end example
5513 This creates a TrialTestCaseCounter and tells the step that the
5514 counter wants to watch the ``stdio'' log. The observer is
5515 automatically given a reference to the step in its @code{.step}
5516 attribute.
5518 @subheading A Somewhat Whimsical Example
5520 Let's say that we've got some snazzy new unit-test framework called
5521 Framboozle. It's the hottest thing since sliced bread. It slices, it
5522 dices, it runs unit tests like there's no tomorrow. Plus if your unit
5523 tests fail, you can use its name for a Web 2.1 startup company, make
5524 millions of dollars, and hire engineers to fix the bugs for you, while
5525 you spend your afternoons lazily hang-gliding along a scenic pacific
5526 beach, blissfully unconcerned about the state of your
5527 tests.@footnote{framboozle.com is still available. Remember, I get 10%
5528 :).}
5530 To run a Framboozle-enabled test suite, you just run the 'framboozler'
5531 command from the top of your source code tree. The 'framboozler'
5532 command emits a bunch of stuff to stdout, but the most interesting bit
5533 is that it emits the line "FNURRRGH!" every time it finishes running a
5534 test case@footnote{Framboozle gets very excited about running unit
5535 tests.}. You'd like to have a test-case counting LogObserver that
5536 watches for these lines and counts them, because counting them will
5537 help the buildbot more accurately calculate how long the build will
5538 take, and this will let you know exactly how long you can sneak out of
5539 the office for your hang-gliding lessons without anyone noticing that
5540 you're gone.
5542 This will involve writing a new BuildStep (probably named
5543 "Framboozle") which inherits from ShellCommand. The BuildStep class
5544 definition itself will look something like this:
5546 @example
5547 # START
5548 from buildbot.steps.shell import ShellCommand
5549 from buildbot.process.buildstep import LogLineObserver
5551 class FNURRRGHCounter(LogLineObserver):
5552     numTests = 0
5553     def outLineReceived(self, line):
5554         if "FNURRRGH!" in line:
5555             self.numTests += 1
5556             self.step.setProgress('tests', self.numTests)
5558 class Framboozle(ShellCommand):
5559     command = ["framboozler"]
5561     def __init__(self, **kwargs):
5562         ShellCommand.__init__(self, **kwargs)   # always upcall!
5563         counter = FNURRRGHCounter())
5564         self.addLogObserver(counter)
5565 # FINISH
5566 @end example
5568 So that's the code that we want to wind up using. How do we actually
5569 deploy it?
5571 You have a couple of different options.
5573 Option 1: The simplest technique is to simply put this text
5574 (everything from START to FINISH) in your master.cfg file, somewhere
5575 before the BuildFactory definition where you actually use it in a
5576 clause like:
5578 @example
5579 f = BuildFactory()
5580 f.addStep(SVN(svnurl="stuff"))
5581 f.addStep(Framboozle())
5582 @end example
5584 Remember that master.cfg is secretly just a python program with one
5585 job: populating the BuildmasterConfig dictionary. And python programs
5586 are allowed to define as many classes as they like. So you can define
5587 classes and use them in the same file, just as long as the class is
5588 defined before some other code tries to use it.
5590 This is easy, and it keeps the point of definition very close to the
5591 point of use, and whoever replaces you after that unfortunate
5592 hang-gliding accident will appreciate being able to easily figure out
5593 what the heck this stupid "Framboozle" step is doing anyways. The
5594 downside is that every time you reload the config file, the Framboozle
5595 class will get redefined, which means that the buildmaster will think
5596 that you've reconfigured all the Builders that use it, even though
5597 nothing changed. Bleh.
5599 Option 2: Instead, we can put this code in a separate file, and import
5600 it into the master.cfg file just like we would the normal buildsteps
5601 like ShellCommand and SVN.
5603 Create a directory named ~/lib/python, put everything from START to
5604 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
5606 @example
5607  PYTHONPATH=~/lib/python buildbot start MASTERDIR
5608 @end example
5610 or use the @file{Makefile.buildbot} to control the way
5611 @command{buildbot start} works. Or add something like this to
5612 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
5614 @example
5615  export PYTHONPATH=~/lib/python
5616 @end example
5618 Once we've done this, our master.cfg can look like:
5620 @example
5621 from framboozle import Framboozle
5622 f = BuildFactory()
5623 f.addStep(SVN(svnurl="stuff"))
5624 f.addStep(Framboozle())
5625 @end example
5629 @example
5630 import framboozle
5631 f = BuildFactory()
5632 f.addStep(SVN(svnurl="stuff"))
5633 f.addStep(framboozle.Framboozle())
5634 @end example
5636 (check out the python docs for details about how "import" and "from A
5637 import B" work).
5639 What we've done here is to tell python that every time it handles an
5640 "import" statement for some named module, it should look in our
5641 ~/lib/python/ for that module before it looks anywhere else. After our
5642 directories, it will try in a bunch of standard directories too
5643 (including the one where buildbot is installed). By setting the
5644 PYTHONPATH environment variable, you can add directories to the front
5645 of this search list.
5647 Python knows that once it "import"s a file, it doesn't need to
5648 re-import it again. This means that reconfiguring the buildmaster
5649 (with "buildbot reconfig", for example) won't make it think the
5650 Framboozle class has changed every time, so the Builders that use it
5651 will not be spuriously restarted. On the other hand, you either have
5652 to start your buildmaster in a slightly weird way, or you have to
5653 modify your environment to set the PYTHONPATH variable.
5656 Option 3: Install this code into a standard python library directory
5658 Find out what your python's standard include path is by asking it:
5660 @example
5661 80:warner@@luther% python
5662 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46) 
5663 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
5664 Type "help", "copyright", "credits" or "license" for more information.
5665 >>> import sys
5666 >>> import pprint
5667 >>> pprint.pprint(sys.path)
5668 ['',
5669  '/usr/lib/python24.zip',
5670  '/usr/lib/python2.4',
5671  '/usr/lib/python2.4/plat-linux2',
5672  '/usr/lib/python2.4/lib-tk',
5673  '/usr/lib/python2.4/lib-dynload',
5674  '/usr/local/lib/python2.4/site-packages',
5675  '/usr/lib/python2.4/site-packages',
5676  '/usr/lib/python2.4/site-packages/Numeric',
5677  '/var/lib/python-support/python2.4',
5678  '/usr/lib/site-python']
5679 @end example
5681 In this case, putting the code into
5682 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
5683 fine. We can use the same master.cfg "import framboozle" statement as
5684 in Option 2. By putting it in a standard include directory (instead of
5685 the decidedly non-standard ~/lib/python), we don't even have to set
5686 PYTHONPATH to anything special. The downside is that you probably have
5687 to be root to write to one of those standard include directories.
5690 Option 4: Submit the code for inclusion in the Buildbot distribution
5692 Contribute the code in an Enhancement Request on SourceForge, via
5693 http://buildbot.sf.net . Lobby, convince, coerce, bribe, badger,
5694 harass, threaten, or otherwise encourage the author to accept the
5695 patch. This lets you do something like:
5697 @example
5698 from buildbot.steps import framboozle
5699 f = BuildFactory()
5700 f.addStep(SVN(svnurl="stuff"))
5701 f.addStep(framboozle.Framboozle())
5702 @end example
5704 And then you don't even have to install framboozle.py anywhere on your
5705 system, since it will ship with Buildbot. You don't have to be root,
5706 you don't have to set PYTHONPATH. But you do have to make a good case
5707 for Framboozle being worth going into the main distribution, you'll
5708 probably have to provide docs and some unit test cases, you'll need to
5709 figure out what kind of beer the author likes, and then you'll have to
5710 wait until the next release. But in some environments, all this is
5711 easier than getting root on your buildmaster box, so the tradeoffs may
5712 actually be worth it.
5716 Putting the code in master.cfg (1) makes it available to that
5717 buildmaster instance. Putting it in a file in a personal library
5718 directory (2) makes it available for any buildmasters you might be
5719 running. Putting it in a file in a system-wide shared library
5720 directory (3) makes it available for any buildmasters that anyone on
5721 that system might be running. Getting it into the buildbot's upstream
5722 repository (4) makes it available for any buildmasters that anyone in
5723 the world might be running. It's all a matter of how widely you want
5724 to deploy that new class.
5728 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
5729 @subsubsection BuildStep URLs
5731 @cindex links
5732 @cindex BuildStep URLs
5733 @cindex addURL
5735 Each BuildStep has a collection of ``links''. Like its collection of
5736 LogFiles, each link has a name and a target URL. The web status page
5737 creates HREFs for each link in the same box as it does for LogFiles,
5738 except that the target of the link is the external URL instead of an
5739 internal link to a page that shows the contents of the LogFile.
5741 These external links can be used to point at build information hosted
5742 on other servers. For example, the test process might produce an
5743 intricate description of which tests passed and failed, or some sort
5744 of code coverage data in HTML form, or a PNG or GIF image with a graph
5745 of memory usage over time. The external link can provide an easy way
5746 for users to navigate from the buildbot's status page to these
5747 external web sites or file servers. Note that the step itself is
5748 responsible for insuring that there will be a document available at
5749 the given URL (perhaps by using @command{scp} to copy the HTML output
5750 to a @file{~/public_html/} directory on a remote web server). Calling
5751 @code{addURL} does not magically populate a web server.
5753 To set one of these links, the BuildStep should call the @code{addURL}
5754 method with the name of the link and the target URL. Multiple URLs can
5755 be set.
5757 In this example, we assume that the @command{make test} command causes
5758 a collection of HTML files to be created and put somewhere on the
5759 coverage.example.org web server, in a filename that incorporates the
5760 build number.
5762 @example
5763 class TestWithCodeCoverage(BuildStep):
5764     command = ["make", "test",
5765                WithProperties("buildnum=%s" % "buildnumber")]
5767     def createSummary(self, log):
5768         buildnumber = self.getProperty("buildnumber")
5769         url = "http://coverage.example.org/builds/%s.html" % buildnumber
5770         self.addURL("coverage", url)
5771 @end example
5773 You might also want to extract the URL from some special message
5774 output by the build process itself:
5776 @example
5777 class TestWithCodeCoverage(BuildStep):
5778     command = ["make", "test",
5779                WithProperties("buildnum=%s" % "buildnumber")]
5781     def createSummary(self, log):
5782         output = StringIO(log.getText())
5783         for line in output.readlines():
5784             if line.startswith("coverage-url:"):
5785                 url = line[len("coverage-url:"):].strip()
5786                 self.addURL("coverage", url)
5787                 return
5788 @end example
5790 Note that a build process which emits both stdout and stderr might
5791 cause this line to be split or interleaved between other lines. It
5792 might be necessary to restrict the getText() call to only stdout with
5793 something like this:
5795 @example
5796         output = StringIO("".join([c[1]
5797                                    for c in log.getChunks()
5798                                    if c[0] == LOG_CHANNEL_STDOUT]))
5799 @end example
5801 Of course if the build is run under a PTY, then stdout and stderr will
5802 be merged before the buildbot ever sees them, so such interleaving
5803 will be unavoidable.
5806 @node Interlocks, Build Factories, Build Steps, Build Process
5807 @section Interlocks
5809 @cindex locks
5810 @slindex buildbot.locks.MasterLock
5811 @slindex buildbot.locks.SlaveLock
5812 @slindex buildbot.locks.LockAccess
5814 Until now, we assumed that a master can run builds at any slave whenever
5815 needed or desired.  Some times, you want to enforce additional constraints on
5816 builds. For reasons like limited network bandwidth, old slave machines, or a
5817 self-willed data base server, you may want to limit the number of builds (or
5818 build steps) that can access a resource.
5820 The mechanism used by Buildbot is known as the read/write lock.@footnote{See
5821 http://en.wikipedia.org/wiki/Read/write_lock_pattern for more information.} It
5822 allows either many readers or a single writer but not a combination of readers
5823 and writers.  The general lock has been modified and extended for use in
5824 Buildbot.  Firstly, the general lock allows an infinite number of readers. In
5825 Buildbot, we often want to put an upper limit on the number of readers, for
5826 example allowing two out of five possible builds at the same time. To do this,
5827 the lock counts the number of active readers.  Secondly, the terms @emph{read
5828 mode} and @emph{write mode} are confusing in Buildbot context. They have been
5829 replaced by @emph{counting mode} (since the lock counts them) and @{exclusive
5830 mode}.  As a result of these changes, locks in Buildbot allow a number of
5831 builds (upto some fixed number) in counting mode, or they allow one build in
5832 exclusive mode.
5834 Often, not all slaves are equal. To allow for this situation, Buildbot allows
5835 to have a separate upper limit on the count for each slave. In this way, you
5836 can have at most 3 concurrent builds at a fast slave, 2 at a slightly older
5837 slave, and 1 at all other slaves.
5839 The final thing you can specify when you introduce a new lock is its scope.
5840 Some constraints are global -- they must be enforced over all slaves. Other
5841 constraints are local to each slave.  A @emph{master lock} is used for the
5842 global constraints. You can ensure for example that at most one build (of all
5843 builds running at all slaves) accesses the data base server. With a
5844 @emph{slave lock} you can add a limit local to each slave. With such a lock,
5845 you can for example enforce an upper limit to the number of active builds at a
5846 slave, like above.
5848 Time for a few examples. Below a master lock is defined to protect a data base,
5849 and a slave lock is created to limit the number of builds at each slave.
5851 @example
5852 from buildbot import locks
5854 db_lock = locks.MasterLock("database")
5855 build_lock = locks.SlaveLock("slave_builds",
5856                              maxCount = 1,
5857                              maxCountForSlave = { 'fast': 3, 'new': 2 })
5858 @end example
5860 After importing locks from buildbot, @code{db_lock} is defined to be a master
5861 lock. The @code{"database"} string is used for uniquely identifying the lock.
5862 At the next line, a slave lock called @code{build_lock} is created. It is
5863 identified by the @code{"slave_builds"} string. Since the requirements of the
5864 lock are a bit more complicated, two optional arguments are also specified. The
5865 @code{maxCount} parameter sets the default limit for builds in counting mode to
5866 @code{1}. For the slave called @code{'fast'} however, we want to have at most
5867 three builds, and for the slave called @code{'new'} the upper limit is two
5868 builds running at the same time.
5870 The next step is using the locks in builds.  Buildbot allows a lock to be used
5871 during an entire build (from beginning to end), or only during a single build
5872 step. In the latter case, the lock is claimed for use just before the step
5873 starts, and released again when the step ends. To prevent
5874 deadlocks,@footnote{Deadlock is the situation where two or more slaves each
5875 hold a lock in exclusive mode, and in addition want to claim the lock held by
5876 the other slave exclusively as well. Since locks allow at most one exclusive
5877 user, both slaves will wait forever.} it is not possible to claim or release
5878 locks at other times.
5880 To use locks, you should add them with a @code{locks} argument.
5881 Each use of a lock is either in counting mode (that is, possibly shared with
5882 other builds) or in exclusive mode. A build or build step proceeds only when it
5883 has acquired all locks. If a build or step needs a lot of locks, it may be
5884 starved@footnote{Starving is the situation that only a few locks are available,
5885 and they are immediately grabbed by another build. As a result, it may take a
5886 long time before all locks needed by the starved build are free at the same
5887 time.} by other builds that need fewer locks.
5889 To illustrate use of locks, a few examples.
5891 @example
5892 from buildbot import locks
5893 from buildbot.steps import source, shell
5894 from buildbot.process import factory
5896 db_lock = locks.MasterLock("database")
5897 build_lock = locks.SlaveLock("slave_builds",
5898                              maxCount = 1,
5899                              maxCountForSlave = { 'fast': 3, 'new': 2 })
5901 f = factory.BuildFactory()
5902 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
5903 f.addStep(shell.ShellCommand(command="make all"))
5904 f.addStep(shell.ShellCommand(command="make test",
5905                              locks=[db_lock.access('exclusive')]))
5907 b1 = @{'name': 'full1', 'slavename': 'fast',  'builddir': 'f1', 'factory': f,
5908        'locks': [build_lock.access('counting')] @}
5910 b2 = @{'name': 'full2', 'slavename': 'new',   'builddir': 'f2', 'factory': f.
5911        'locks': [build_lock.access('counting')] @}
5913 b3 = @{'name': 'full3', 'slavename': 'old',   'builddir': 'f3', 'factory': f.
5914        'locks': [build_lock.access('counting')] @}
5916 b4 = @{'name': 'full4', 'slavename': 'other', 'builddir': 'f4', 'factory': f.
5917        'locks': [build_lock.access('counting')] @}
5919 c['builders'] = [b1, b2, b3, b4]
5920 @end example
5922 Here we have four slaves @code{b1}, @code{b2}, @code{b3}, and @code{b4}. Each
5923 slave performs the same checkout, make, and test build step sequence.
5924 We want to enforce that at most one test step is executed between all slaves due
5925 to restrictions with the data base server. This is done by adding the
5926 @code{locks=} parameter with the third step. It takes a list of locks with their
5927 access mode. In this case only the @code{db_lock} is needed. The exclusive
5928 access mode is used to ensure there is at most one slave that executes the test
5929 step.
5931 In addition to exclusive accessing the data base, we also want slaves to stay
5932 responsive even under the load of a large number of builds being triggered.
5933 For this purpose, the slave lock called @code{build_lock} is defined. Since
5934 the restraint holds for entire builds, the lock is specified in the builder
5935 with @code{'locks': [build_lock.access('counting')]}.
5936 @node Build Factories,  , Interlocks, Build Process
5937 @section Build Factories
5940 Each Builder is equipped with a ``build factory'', which is
5941 responsible for producing the actual @code{Build} objects that perform
5942 each build. This factory is created in the configuration file, and
5943 attached to a Builder through the @code{factory} element of its
5944 dictionary.
5946 The standard @code{BuildFactory} object creates @code{Build} objects
5947 by default. These Builds will each execute a collection of BuildSteps
5948 in a fixed sequence. Each step can affect the results of the build,
5949 but in general there is little intelligence to tie the different steps
5950 together. You can create subclasses of @code{Build} to implement more
5951 sophisticated build processes, and then use a subclass of
5952 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
5953 create instances of your new Build subclass.
5956 @menu
5957 * BuildStep Objects::           
5958 * BuildFactory::                
5959 * Process-Specific build factories::  
5960 @end menu
5962 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
5963 @subsection BuildStep Objects
5965 The steps used by these builds are all subclasses of @code{BuildStep}.
5966 The standard ones provided with Buildbot are documented later,
5967 @xref{Build Steps}. You can also write your own subclasses to use in
5968 builds.
5970 The basic behavior for a @code{BuildStep} is to:
5972 @itemize @bullet
5973 @item
5974 run for a while, then stop
5975 @item
5976 possibly invoke some RemoteCommands on the attached build slave
5977 @item
5978 possibly produce a set of log files
5979 @item
5980 finish with a status described by one of four values defined in
5981 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
5982 @item
5983 provide a list of short strings to describe the step
5984 @item
5985 define a color (generally green, orange, or red) with which the
5986 step should be displayed
5987 @end itemize
5990 More sophisticated steps may produce additional information and
5991 provide it to later build steps, or store it in the factory to provide
5992 to later builds.
5995 @menu
5996 * BuildFactory Attributes::     
5997 * Quick builds::                
5998 @end menu
6000 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
6001 @subsection BuildFactory
6003 @bfindex buildbot.process.factory.BuildFactory
6004 @bfindex buildbot.process.factory.BasicBuildFactory
6005 @c TODO: what is BasicSVN anyway?
6006 @bfindex buildbot.process.factory.BasicSVN
6008 The default @code{BuildFactory}, provided in the
6009 @code{buildbot.process.factory} module, contains an internal list of
6010 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
6011 tuples for each. These specification tuples are constructed when the
6012 config file is read, by asking the instances passed to @code{addStep}
6013 for their subclass and arguments.
6015 When asked to create a Build, the @code{BuildFactory} puts a copy of
6016 the list of step specifications into the new Build object. When the
6017 Build is actually started, these step specifications are used to
6018 create the actual set of BuildSteps, which are then executed one at a
6019 time. This serves to give each Build an independent copy of each step.
6020 For example, a build which consists of a CVS checkout followed by a
6021 @code{make build} would be constructed as follows:
6023 @example
6024 from buildbot.steps import source, shell
6025 from buildbot.process import factory
6027 f = factory.BuildFactory()
6028 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
6029 f.addStep(shell.Compile(command=["make", "build"]))
6030 @end example
6032 (To support config files from buildbot-0.7.5 and earlier,
6033 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
6034 command=["make","build"])} form, although its use is discouraged
6035 because then the @code{Compile} step doesn't get to validate or
6036 complain about its arguments until build time. The modern
6037 pass-by-instance approach allows this validation to occur while the
6038 config file is being loaded, where the admin has a better chance of
6039 noticing problems).
6041 It is also possible to pass a list of steps into the
6042 @code{BuildFactory} when it is created. Using @code{addStep} is
6043 usually simpler, but there are cases where is is more convenient to
6044 create the list of steps ahead of time.:
6046 @example
6047 from buildbot.steps import source, shell
6048 from buildbot.process import factory
6050 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
6051              shell.Compile(command=["make", "build"]),
6052             ]
6053 f = factory.BuildFactory(all_steps)
6054 @end example
6057 Each step can affect the build process in the following ways:
6059 @itemize @bullet
6060 @item
6061 If the step's @code{haltOnFailure} attribute is True, then a failure
6062 in the step (i.e. if it completes with a result of FAILURE) will cause
6063 the whole build to be terminated immediately: no further steps will be
6064 executed. This is useful for setup steps upon which the rest of the
6065 build depends: if the CVS checkout or @code{./configure} process
6066 fails, there is no point in trying to compile or test the resulting
6067 tree.
6069 @item
6070 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
6071 then a result of FAILURE or WARNINGS will mark the build as a whole as
6072 FAILED. However, the remaining steps will still be executed. This is
6073 appropriate for things like multiple testing steps: a failure in any
6074 one of them will indicate that the build has failed, however it is
6075 still useful to run them all to completion.
6077 @item
6078 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
6079 is set, then a result of FAILURE or WARNINGS will mark the build as
6080 having WARNINGS, and the remaining steps will still be executed. This
6081 may be appropriate for certain kinds of optional build or test steps.
6082 For example, a failure experienced while building documentation files
6083 should be made visible with a WARNINGS result but not be serious
6084 enough to warrant marking the whole build with a FAILURE.
6086 @end itemize
6088 In addition, each Step produces its own results, may create logfiles,
6089 etc. However only the flags described above have any effect on the
6090 build as a whole.
6092 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
6093 reasonably appropriate flags set on them already. For example, without
6094 a source tree there is no point in continuing the build, so the
6095 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
6096 in @file{buildbot/steps/*.py} to see how the other Steps are
6097 marked.
6099 Each Step is created with an additional @code{workdir} argument that
6100 indicates where its actions should take place. This is specified as a
6101 subdirectory of the slave builder's base directory, with a default
6102 value of @code{build}. This is only implemented as a step argument (as
6103 opposed to simply being a part of the base directory) because the
6104 CVS/SVN steps need to perform their checkouts from the parent
6105 directory.
6107 @menu
6108 * BuildFactory Attributes::     
6109 * Quick builds::                
6110 @end menu
6112 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
6113 @subsubsection BuildFactory Attributes
6115 Some attributes from the BuildFactory are copied into each Build.
6117 @cindex treeStableTimer
6119 @table @code
6120 @item useProgress
6121 (defaults to True): if True, the buildmaster keeps track of how long
6122 each step takes, so it can provide estimates of how long future builds
6123 will take. If builds are not expected to take a consistent amount of
6124 time (such as incremental builds in which a random set of files are
6125 recompiled or tested each time), this should be set to False to
6126 inhibit progress-tracking.
6128 @end table
6131 @node Quick builds,  , BuildFactory Attributes, BuildFactory
6132 @subsubsection Quick builds
6134 @bfindex buildbot.process.factory.QuickBuildFactory
6136 The difference between a ``full build'' and a ``quick build'' is that
6137 quick builds are generally done incrementally, starting with the tree
6138 where the previous build was performed. That simply means that the
6139 source-checkout step should be given a @code{mode='update'} flag, to
6140 do the source update in-place.
6142 In addition to that, the @code{useProgress} flag should be set to
6143 False. Incremental builds will (or at least the ought to) compile as
6144 few files as necessary, so they will take an unpredictable amount of
6145 time to run. Therefore it would be misleading to claim to predict how
6146 long the build will take.
6149 @node Process-Specific build factories,  , BuildFactory, Build Factories
6150 @subsection Process-Specific build factories
6152 Many projects use one of a few popular build frameworks to simplify
6153 the creation and maintenance of Makefiles or other compilation
6154 structures. Buildbot provides several pre-configured BuildFactory
6155 subclasses which let you build these projects with a minimum of fuss.
6157 @menu
6158 * GNUAutoconf::                 
6159 * CPAN::                        
6160 * Python distutils::            
6161 * Python/Twisted/trial projects::  
6162 @end menu
6164 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
6165 @subsubsection GNUAutoconf
6167 @bfindex buildbot.process.factory.GNUAutoconf
6169 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
6170 software portability tool, intended to make it possible to write
6171 programs in C (and other languages) which will run on a variety of
6172 UNIX-like systems. Most GNU software is built using autoconf. It is
6173 frequently used in combination with GNU automake. These tools both
6174 encourage a build process which usually looks like this:
6176 @example
6177 % CONFIG_ENV=foo ./configure --with-flags
6178 % make all
6179 % make check
6180 # make install
6181 @end example
6183 (except of course the Buildbot always skips the @code{make install}
6184 part).
6186 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
6187 designed to build projects which use GNU autoconf and/or automake. The
6188 configuration environment variables, the configure flags, and command
6189 lines used for the compile and test are all configurable, in general
6190 the default values will be suitable.
6192 Example:
6194 @example
6195 # use the s() convenience function defined earlier
6196 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
6197                         flags=["--disable-nls"])
6198 @end example
6200 Required Arguments:
6202 @table @code
6203 @item source
6204 This argument must be a step specification tuple that provides a
6205 BuildStep to generate the source tree.
6206 @end table
6208 Optional Arguments:
6210 @table @code
6211 @item configure
6212 The command used to configure the tree. Defaults to
6213 @code{./configure}. Accepts either a string or a list of shell argv
6214 elements.
6216 @item configureEnv
6217 The environment used for the initial configuration step. This accepts
6218 a dictionary which will be merged into the buildslave's normal
6219 environment. This is commonly used to provide things like
6220 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
6221 Defaults to an empty dictionary.
6223 @item configureFlags
6224 A list of flags to be appended to the argument list of the configure
6225 command. This is commonly used to enable or disable specific features
6226 of the autoconf-controlled package, like @code{["--without-x"]} to
6227 disable windowing support. Defaults to an empty list.
6229 @item compile
6230 this is a shell command or list of argv values which is used to
6231 actually compile the tree. It defaults to @code{make all}. If set to
6232 None, the compile step is skipped.
6234 @item test
6235 this is a shell command or list of argv values which is used to run
6236 the tree's self-tests. It defaults to @code{make check}. If set to
6237 None, the test step is skipped.
6239 @end table
6242 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
6243 @subsubsection CPAN
6245 @bfindex buildbot.process.factory.CPAN
6247 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
6248 archive use the @code{MakeMaker} module to provide configuration,
6249 build, and test services. The standard build routine for these modules
6250 looks like:
6252 @example
6253 % perl Makefile.PL
6254 % make
6255 % make test
6256 # make install
6257 @end example
6259 (except again Buildbot skips the install step)
6261 Buildbot provides a @code{CPAN} factory to compile and test these
6262 projects.
6265 Arguments:
6266 @table @code
6267 @item source
6268 (required): A step specification tuple, that that used by GNUAutoconf.
6270 @item perl
6271 A string which specifies the @code{perl} executable to use. Defaults
6272 to just @code{perl}.
6274 @end table
6277 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
6278 @subsubsection Python distutils
6280 @bfindex buildbot.process.factory.Distutils
6282 Most Python modules use the @code{distutils} package to provide
6283 configuration and build services. The standard build process looks
6284 like:
6286 @example
6287 % python ./setup.py build
6288 % python ./setup.py install
6289 @end example
6291 Unfortunately, although Python provides a standard unit-test framework
6292 named @code{unittest}, to the best of my knowledge @code{distutils}
6293 does not provide a standardized target to run such unit tests. (please
6294 let me know if I'm wrong, and I will update this factory).
6296 The @code{Distutils} factory provides support for running the build
6297 part of this process. It accepts the same @code{source=} parameter as
6298 the other build factories.
6301 Arguments:
6302 @table @code
6303 @item source
6304 (required): A step specification tuple, that that used by GNUAutoconf.
6305   
6306 @item python
6307 A string which specifies the @code{python} executable to use. Defaults
6308 to just @code{python}.
6310 @item test
6311 Provides a shell command which runs unit tests. This accepts either a
6312 string or a list. The default value is None, which disables the test
6313 step (since there is no common default command to run unit tests in
6314 distutils modules).
6316 @end table
6319 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
6320 @subsubsection Python/Twisted/trial projects
6322 @bfindex buildbot.process.factory.Trial
6323 @c TODO: document these steps better
6324 @bsindex buildbot.steps.python_twisted.HLint
6325 @bsindex buildbot.steps.python_twisted.Trial
6326 @bsindex buildbot.steps.python_twisted.ProcessDocs
6327 @bsindex buildbot.steps.python_twisted.BuildDebs
6328 @bsindex buildbot.steps.python_twisted.RemovePYCs
6330 Twisted provides a unit test tool named @code{trial} which provides a
6331 few improvements over Python's built-in @code{unittest} module. Many
6332 python projects which use Twisted for their networking or application
6333 services also use trial for their unit tests. These modules are
6334 usually built and tested with something like the following:
6336 @example
6337 % python ./setup.py build
6338 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
6339 % python ./setup.py install
6340 @end example
6342 Unfortunately, the @file{build/lib} directory into which the
6343 built/copied .py files are placed is actually architecture-dependent,
6344 and I do not yet know of a simple way to calculate its value. For many
6345 projects it is sufficient to import their libraries ``in place'' from
6346 the tree's base directory (@code{PYTHONPATH=.}).
6348 In addition, the @var{PROJECTNAME} value where the test files are
6349 located is project-dependent: it is usually just the project's
6350 top-level library directory, as common practice suggests the unit test
6351 files are put in the @code{test} sub-module. This value cannot be
6352 guessed, the @code{Trial} class must be told where to find the test
6353 files.
6355 The @code{Trial} class provides support for building and testing
6356 projects which use distutils and trial. If the test module name is
6357 specified, trial will be invoked. The library path used for testing
6358 can also be set.
6360 One advantage of trial is that the Buildbot happens to know how to
6361 parse trial output, letting it identify which tests passed and which
6362 ones failed. The Buildbot can then provide fine-grained reports about
6363 how many tests have failed, when individual tests fail when they had
6364 been passing previously, etc.
6366 Another feature of trial is that you can give it a series of source
6367 .py files, and it will search them for special @code{test-case-name}
6368 tags that indicate which test cases provide coverage for that file.
6369 Trial can then run just the appropriate tests. This is useful for
6370 quick builds, where you want to only run the test cases that cover the
6371 changed functionality.
6373 Arguments:
6374 @table @code
6375 @item source
6376 (required): A step specification tuple, like that used by GNUAutoconf.
6378 @item buildpython
6379 A list (argv array) of strings which specifies the @code{python}
6380 executable to use when building the package. Defaults to just
6381 @code{['python']}. It may be useful to add flags here, to supress
6382 warnings during compilation of extension modules. This list is
6383 extended with @code{['./setup.py', 'build']} and then executed in a
6384 ShellCommand.
6386 @item testpath
6387 Provides a directory to add to @code{PYTHONPATH} when running the unit
6388 tests, if tests are being run. Defaults to @code{.} to include the
6389 project files in-place. The generated build library is frequently
6390 architecture-dependent, but may simply be @file{build/lib} for
6391 pure-python modules.
6393 @item trialpython
6394 Another list of strings used to build the command that actually runs
6395 trial. This is prepended to the contents of the @code{trial} argument
6396 below. It may be useful to add @code{-W} flags here to supress
6397 warnings that occur while tests are being run. Defaults to an empty
6398 list, meaning @code{trial} will be run without an explicit
6399 interpreter, which is generally what you want if you're using
6400 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
6401 lives in the Twisted source tree.
6403 @item trial
6404 provides the name of the @code{trial} command. It is occasionally
6405 useful to use an alternate executable, such as @code{trial2.2} which
6406 might run the tests under an older version of Python. Defaults to
6407 @code{trial}.
6409 @item tests
6410 Provides a module name or names which contain the unit tests for this
6411 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
6412 list of strings. Defaults to None, indicating that no tests should be
6413 run. You must either set this or @code{useTestCaseNames} to do anyting
6414 useful with the Trial factory.
6416 @item useTestCaseNames
6417 Tells the Step to provide the names of all changed .py files to trial,
6418 so it can look for test-case-name tags and run just the matching test
6419 cases. Suitable for use in quick builds. Defaults to False.
6421 @item randomly
6422 If @code{True}, tells Trial (with the @code{--random=0} argument) to
6423 run the test cases in random order, which sometimes catches subtle
6424 inter-test dependency bugs. Defaults to @code{False}.
6426 @item recurse
6427 If @code{True}, tells Trial (with the @code{--recurse} argument) to
6428 look in all subdirectories for additional test cases. It isn't clear
6429 to me how this works, but it may be useful to deal with the
6430 unknown-PROJECTNAME problem described above, and is currently used in
6431 the Twisted buildbot to accomodate the fact that test cases are now
6432 distributed through multiple twisted.SUBPROJECT.test directories.
6434 @end table  
6436 Unless one of @code{trialModule} or @code{useTestCaseNames}
6437 are set, no tests will be run.
6439 Some quick examples follow. Most of these examples assume that the
6440 target python code (the ``code under test'') can be reached directly
6441 from the root of the target tree, rather than being in a @file{lib/}
6442 subdirectory.
6444 @example
6445 #  Trial(source, tests="toplevel.test") does:
6446 #   python ./setup.py build
6447 #   PYTHONPATH=. trial -to toplevel.test
6449 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
6450 #   python ./setup.py build
6451 #   PYTHONPATH=. trial -to toplevel.test other.test
6453 #  Trial(source, useTestCaseNames=True) does:
6454 #   python ./setup.py build
6455 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
6457 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
6458 #   python2.3 -Wall ./setup.py build
6459 #   PYTHONPATH=. trial -to foo.tests
6461 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
6462 #        tests="foo.tests") does:
6463 #   python2.3 -Wall ./setup.py build
6464 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
6466 # For running trial out of the tree being tested (only useful when the
6467 # tree being built is Twisted itself):
6468 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
6469 #        tests="foo.tests") does:
6470 #   python2.3 -Wall ./setup.py build
6471 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
6472 @end example
6474 If the output directory of @code{./setup.py build} is known, you can
6475 pull the python code from the built location instead of the source
6476 directories. This should be able to handle variations in where the
6477 source comes from, as well as accomodating binary extension modules:
6479 @example
6480 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
6481 # does:
6482 #  python ./setup.py build
6483 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
6484 @end example
6487 @node Status Delivery, Command-line tool, Build Process, Top
6488 @chapter Status Delivery
6490 More details are available in the docstrings for each class, use a
6491 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
6492 Most status delivery objects take a @code{categories=} argument, which
6493 can contain a list of ``category'' names: in this case, it will only
6494 show status for Builders that are in one of the named categories.
6496 (implementor's note: each of these objects should be a
6497 service.MultiService which will be attached to the BuildMaster object
6498 when the configuration is processed. They should use
6499 @code{self.parent.getStatus()} to get access to the top-level IStatus
6500 object, either inside @code{startService} or later. They may call
6501 @code{status.subscribe()} in @code{startService} to receive
6502 notifications of builder events, in which case they must define
6503 @code{builderAdded} and related methods. See the docstrings in
6504 @file{buildbot/interfaces.py} for full details.)
6506 @menu
6507 * WebStatus::                   
6508 * MailNotifier::                
6509 * IRC Bot::                     
6510 * PBListener::                  
6511 * Writing New Status Plugins::  
6512 @end menu
6514 @c @node Email Delivery,  , Status Delivery, Status Delivery
6515 @c @subsection Email Delivery
6517 @c DOCUMENT THIS
6520 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
6521 @section WebStatus
6523 @cindex WebStatus
6524 @stindex buildbot.status.web.baseweb.WebStatus
6526 The @code{buildbot.status.html.WebStatus} status target runs a small
6527 web server inside the buildmaster. You can point a browser at this web
6528 server and retrieve information about every build the buildbot knows
6529 about, as well as find out what the buildbot is currently working on.
6531 The first page you will see is the ``Welcome Page'', which contains
6532 links to all the other useful pages. This page is simply served from
6533 the @file{public_html/index.html} file in the buildmaster's base
6534 directory, where it is created by the @command{buildbot create-master}
6535 command along with the rest of the buildmaster.
6537 The most complex resource provided by @code{WebStatus} is the
6538 ``Waterfall Display'', which shows a time-based chart of events. This
6539 somewhat-busy display provides detailed information about all steps of
6540 all recent builds, and provides hyperlinks to look at individual build
6541 logs and source changes. By simply reloading this page on a regular
6542 basis, you will see a complete description of everything the buildbot
6543 is currently working on.
6545 There are also pages with more specialized information. For example,
6546 there is a page which shows the last 20 builds performed by the
6547 buildbot, one line each. Each line is a link to detailed information
6548 about that build. By adding query arguments to the URL used to reach
6549 this page, you can narrow the display to builds that involved certain
6550 branches, or which ran on certain Builders. These pages are described
6551 in great detail below.
6554 When the buildmaster is created, a subdirectory named
6555 @file{public_html/} is created in its base directory. By default, @code{WebStatus}
6556 will serve files from this directory: for example, when a user points
6557 their browser at the buildbot's @code{WebStatus} URL, they will see
6558 the contents of the @file{public_html/index.html} file. Likewise,
6559 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
6560 @file{public_html/favicon.ico} are all useful things to have in there.
6561 The first time a buildmaster is created, the @file{public_html}
6562 directory is populated with some sample files, which you will probably
6563 want to customize for your own project. These files are all static:
6564 the buildbot does not modify them in any way as it serves them to HTTP
6565 clients.
6567 @example
6568 from buildbot.status.html import WebStatus
6569 c['status'].append(WebStatus(8080))
6570 @end example
6572 Note that the initial robots.txt file has Disallow lines for all of
6573 the dynamically-generated buildbot pages, to discourage web spiders
6574 and search engines from consuming a lot of CPU time as they crawl
6575 through the entire history of your buildbot. If you are running the
6576 buildbot behind a reverse proxy, you'll probably need to put the
6577 robots.txt file somewhere else (at the top level of the parent web
6578 server), and replace the URL prefixes in it with more suitable values.
6580 If you would like to use an alternative root directory, add the
6581 @code{public_html=..} option to the @code{WebStatus} creation:
6583 @example
6584 c['status'].append(WebStatus(8080, public_html="/var/www/buildbot"))
6585 @end example
6587 In addition, if you are familiar with twisted.web @emph{Resource
6588 Trees}, you can write code to add additional pages at places inside
6589 this web space. Just use @code{webstatus.putChild} to place these
6590 resources.
6592 The following section describes the special URLs and the status views
6593 they provide.
6596 @menu
6597 * WebStatus Configuration Parameters::  
6598 * Buildbot Web Resources::      
6599 * XMLRPC server::               
6600 * HTML Waterfall::              
6601 @end menu
6603 @node WebStatus Configuration Parameters, Buildbot Web Resources, WebStatus, WebStatus
6604 @subsection WebStatus Configuration Parameters
6606 The most common way to run a @code{WebStatus} is on a regular TCP
6607 port. To do this, just pass in the TCP port number when you create the
6608 @code{WebStatus} instance; this is called the @code{http_port} argument:
6610 @example
6611 from buildbot.status.html import WebStatus
6612 c['status'].append(WebStatus(8080))
6613 @end example
6615 The @code{http_port} argument is actually a ``strports specification''
6616 for the port that the web server should listen on. This can be a
6617 simple port number, or a string like
6618 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
6619 loopback interface, and therefore to clients running on the same
6620 host)@footnote{It may even be possible to provide SSL access by using
6621 a specification like
6622 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
6623 completely untested}.
6625 If instead (or in addition) you provide the @code{distrib_port}
6626 argument, a twisted.web distributed server will be started either on a
6627 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
6628 likely on a UNIX socket (if @code{distrib_port} is like
6629 @code{"unix:/path/to/socket"}).
6631 The @code{distrib_port} option means that, on a host with a
6632 suitably-configured twisted-web server, you do not need to consume a
6633 separate TCP port for the buildmaster's status web page. When the web
6634 server is constructed with @code{mktap web --user}, URLs that point to
6635 @code{http://host/~username/} are dispatched to a sub-server that is
6636 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
6637 such a system, it is convenient to create a dedicated @code{buildbot}
6638 user, then set @code{distrib_port} to
6639 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
6640 configuration will make the HTML status page available at
6641 @code{http://host/~buildbot/} . Suitable URL remapping can make it
6642 appear at @code{http://host/buildbot/}, and the right virtual host
6643 setup can even place it at @code{http://buildbot.host/} .
6645 The other @code{WebStatus} argument is @code{allowForce}. If set to
6646 True, then the web page will provide a ``Force Build'' button that
6647 allows visitors to manually trigger builds. This is useful for
6648 developers to re-run builds that have failed because of intermittent
6649 problems in the test suite, or because of libraries that were not
6650 installed at the time of the previous build. You may not wish to allow
6651 strangers to cause a build to run: in that case, set this to False to
6652 remove these buttons. The default value is False.
6656 @node Buildbot Web Resources, XMLRPC server, WebStatus Configuration Parameters, WebStatus
6657 @subsection Buildbot Web Resources
6659 Certain URLs are ``magic'', and the pages they serve are created by
6660 code in various classes in the @file{buildbot.status.web} package
6661 instead of being read from disk. The most common way to access these
6662 pages is for the buildmaster admin to write or modify the
6663 @file{index.html} page to contain links to them. Of course other
6664 project web pages can contain links to these buildbot pages as well.
6666 Many pages can be modified by adding query arguments to the URL. For
6667 example, a page which shows the results of the most recent build
6668 normally does this for all builders at once. But by appending
6669 ``?builder=i386'' to the end of the URL, the page will show only the
6670 results for the ``i386'' builder. When used in this way, you can add
6671 multiple ``builder='' arguments to see multiple builders. Remembering
6672 that URL query arguments are separated @emph{from each other} with
6673 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
6674 show builds for just those two Builders.
6676 The @code{branch=} query argument can be used on some pages. This
6677 filters the information displayed by that page down to only the builds
6678 or changes which involved the given branch. Use @code{branch=trunk} to
6679 reference the trunk: if you aren't intentionally using branches,
6680 you're probably using trunk. Multiple @code{branch=} arguments can be
6681 used to examine multiple branches at once (so appending
6682 @code{?branch=foo&branch=bar} to the URL will show builds involving
6683 either branch). No @code{branch=} arguments means to show builds and
6684 changes for all branches.
6686 Some pages may include the Builder name or the build number in the
6687 main part of the URL itself. For example, a page that describes Build
6688 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
6690 The table below lists all of the internal pages and the URLs that can
6691 be used to access them.
6693 NOTE: of the pages described here, @code{/slave_status_timeline} and
6694 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
6695 has only a few methods so far. Future releases will improve this.
6697 @table @code
6699 @item /waterfall
6701 This provides a chronologically-oriented display of the activity of
6702 all builders. It is the same display used by the Waterfall display.
6704 By adding one or more ``builder='' query arguments, the Waterfall is
6705 restricted to only showing information about the given Builders. By
6706 adding one or more ``branch='' query arguments, the display is
6707 restricted to showing information about the given branches. In
6708 addition, adding one or more ``category='' query arguments to the URL
6709 will limit the display to Builders that were defined with one of the
6710 given categories.
6712 A 'show_events=true' query argument causes the display to include
6713 non-Build events, like slaves attaching and detaching, as well as
6714 reconfiguration events. 'show_events=false' hides these events. The
6715 default is to show them.
6717 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
6718 arguments will control what interval of time is displayed. The default
6719 is to show the latest events, but these can be used to look at earlier
6720 periods in history. The @code{num_events=} argument also provides a
6721 limit on the size of the displayed page.
6723 The Waterfall has references to resources many of the other portions
6724 of the URL space: @file{/builders} for access to individual builds,
6725 @file{/changes} for access to information about source code changes,
6726 etc.
6728 @item /builders/$BUILDERNAME
6730 This describes the given Builder, and provides buttons to force a build.
6732 @item /builders/$BUILDERNAME/builds/$BUILDNUM
6734 This describes a specific Build.
6736 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
6738 This describes a specific BuildStep.
6740 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
6742 This provides an HTML representation of a specific logfile.
6744 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
6746 This returns the logfile as plain text, without any HTML coloring
6747 markup. It also removes the ``headers'', which are the lines that
6748 describe what command was run and what the environment variable
6749 settings were like. This maybe be useful for saving to disk and
6750 feeding to tools like 'grep'.
6752 @item /changes
6754 This provides a brief description of the ChangeSource in use
6755 (@pxref{Change Sources}).
6757 @item /changes/NN
6759 This shows detailed information about the numbered Change: who was the
6760 author, what files were changed, what revision number was represented,
6761 etc.
6763 @item /buildslaves
6765 This summarizes each BuildSlave, including which Builders are
6766 configured to use it, whether the buildslave is currently connected or
6767 not, and host information retrieved from the buildslave itself.
6769 @item /one_line_per_build
6771 This page shows one line of text for each build, merging information
6772 from all Builders@footnote{Apparently this is the same way
6773 http://buildd.debian.org displays build status}. Each line specifies
6774 the name of the Builder, the number of the Build, what revision it
6775 used, and a summary of the results. Successful builds are in green,
6776 while failing builds are in red. The date and time of the build are
6777 added to the right-hand edge of the line. The lines are ordered by
6778 build finish timestamp.
6780 One or more @code{builder=} or @code{branch=} arguments can be used to
6781 restrict the list. In addition, a @code{numbuilds=} argument will
6782 control how many lines are displayed (20 by default).
6784 @item /one_box_per_builder
6786 This page shows a small table, with one box for each Builder,
6787 containing the results of the most recent Build. It does not show the
6788 individual steps, or the current status. This is a simple summary of
6789 buildbot status: if this page is green, then all tests are passing.
6791 As with @code{/one_line_per_build}, this page will also honor
6792 @code{builder=} and @code{branch=} arguments.
6794 @item /about
6796 This page gives a brief summary of the Buildbot itself: software
6797 version, versions of some libraries that the Buildbot depends upon,
6798 etc. It also contains a link to the buildbot.net home page.
6800 @item /slave_status_timeline
6802 (note: this page has not yet been implemented)
6804 This provides a chronological display of configuration and operational
6805 events: master startup/shutdown, slave connect/disconnect, and
6806 config-file changes. When a config-file reload is abandoned because of
6807 an error in the config file, the error is displayed on this page.
6809 This page does not show any builds.
6811 @item /last_build/$BUILDERNAME/status.png
6813 This returns a PNG image that describes the results of the most recent
6814 build, which can be referenced in an IMG tag by other pages, perhaps
6815 from a completely different site. Use it as you would a webcounter.
6817 @end table
6819 There are also a set of web-status resources that are intended for use
6820 by other programs, rather than humans.
6822 @table @code
6824 @item /xmlrpc
6826 This runs an XML-RPC server which can be used to query status
6827 information about various builds. See @ref{XMLRPC server} for more
6828 details.
6830 @end table
6832 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
6833 @subsection XMLRPC server
6835 When using WebStatus, the buildbot runs an XML-RPC server at
6836 @file{/xmlrpc} that can be used by other programs to query build
6837 status. The following table lists the methods that can be invoked
6838 using this interface.
6840 @table @code
6841 @item getAllBuildsInInterval(start, stop)
6843 Return a list of builds that have completed after the 'start'
6844 timestamp and before the 'stop' timestamp. This looks at all Builders.
6846 The timestamps are integers, interpreted as standard unix timestamps
6847 (seconds since epoch).
6849 Each Build is returned as a tuple in the form: @code{(buildername,
6850 buildnumber, build_end, branchname, revision, results, text)}
6852 The buildnumber is an integer. 'build_end' is an integer (seconds
6853 since epoch) specifying when the build finished.
6855 The branchname is a string, which may be an empty string to indicate
6856 None (i.e. the default branch). The revision is a string whose meaning
6857 is specific to the VC system in use, and comes from the 'got_revision'
6858 build property. The results are expressed as a string, one of
6859 ('success', 'warnings', 'failure', 'exception'). The text is a list of
6860 short strings that ought to be joined by spaces and include slightly
6861 more data about the results of the build.
6863 @item getBuild(builder_name, build_number)
6865 Return information about a specific build.
6867 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
6868 complete information about the build. It does not include the contents
6869 of the log files, but it has just about everything else.
6871 @end table
6873 @node HTML Waterfall,  , XMLRPC server, WebStatus
6874 @subsection HTML Waterfall
6876 @cindex Waterfall
6877 @stindex buildbot.status.html.Waterfall
6879 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
6880 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
6881 This section (and the @code{Waterfall} class itself) will be removed
6882 from a future release.
6884 @example
6885 from buildbot.status import html
6886 w = html.WebStatus(http_port=8080)
6887 c['status'].append(w)
6888 @end example
6892 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
6893 @section MailNotifier
6895 @cindex email
6896 @cindex mail
6897 @stindex buildbot.status.mail.MailNotifier
6899 The buildbot can also send email when builds finish. The most common
6900 use of this is to tell developers when their change has caused the
6901 build to fail. It is also quite common to send a message to a mailing
6902 list (usually named ``builds'' or similar) about every build.
6904 The @code{MailNotifier} status target is used to accomplish this. You
6905 configure it by specifying who mail should be sent to, under what
6906 circumstances mail should be sent, and how to deliver the mail. It can
6907 be configured to only send out mail for certain builders, and only
6908 send messages when the build fails, or when the builder transitions
6909 from success to failure. It can also be configured to include various
6910 build logs in each message.
6913 By default, the message will be sent to the Interested Users list
6914 (@pxref{Doing Things With Users}), which includes all developers who
6915 made changes in the build. You can add additional recipients with the
6916 extraRecipients argument.
6918 Each MailNotifier sends mail to a single set of recipients. To send
6919 different kinds of mail to different recipients, use multiple
6920 MailNotifiers.
6922 The following simple example will send an email upon the completion of
6923 each build, to just those developers whose Changes were included in
6924 the build. The email contains a description of the Build, its results,
6925 and URLs where more information can be obtained.
6927 @example
6928 from buildbot.status.mail import MailNotifier
6929 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
6930 c['status'].append(mn)
6931 @end example
6933 To get a simple one-message-per-build (say, for a mailing list), use
6934 the following form instead. This form does not send mail to individual
6935 developers (and thus does not need the @code{lookup=} argument,
6936 explained below), instead it only ever sends mail to the ``extra
6937 recipients'' named in the arguments:
6939 @example
6940 mn = MailNotifier(fromaddr="buildbot@@example.org",
6941                   sendToInterestedUsers=False,
6942                   extraRecipients=['listaddr@@example.org'])
6943 @end example
6945 @heading MailNotifier arguments
6947 @table @code
6948 @item fromaddr
6949 The email address to be used in the 'From' header.
6951 @item sendToInterestedUsers
6952 (boolean). If True (the default), send mail to all of the Interested
6953 Users. If False, only send mail to the extraRecipients list.
6955 @item extraRecipients
6956 (tuple of strings). A list of email addresses to which messages should
6957 be sent (in addition to the InterestedUsers list, which includes any
6958 developers who made Changes that went into this build). It is a good
6959 idea to create a small mailing list and deliver to that, then let
6960 subscribers come and go as they please.
6962 @item subject
6963 (string). A string to be used as the subject line of the message.
6964 @code{%(builder)s} will be replaced with the name of the builder which
6965 provoked the message.
6967 @item mode
6968 (string). Default to 'all'. One of:
6969 @table @code
6970 @item all
6971 Send mail about all builds, bothpassing and failing
6972 @item failing
6973 Only send mail about builds which fail
6974 @item problem
6975 Only send mail about a build which failed when the previous build has passed.
6976 If your builds usually pass, then this will only send mail when a problem
6977 occurs.
6978 @end table
6980 @item builders
6981 (list of strings). A list of builder names for which mail should be
6982 sent. Defaults to None (send mail for all builds). Use either builders
6983 or categories, but not both.
6985 @item categories
6986 (list of strings). A list of category names to serve status
6987 information for. Defaults to None (all categories). Use either
6988 builders or categories, but not both.
6990 @item addLogs
6991 (boolean). If True, include all build logs as attachments to the
6992 messages. These can be quite large. This can also be set to a list of
6993 log names, to send a subset of the logs. Defaults to False.
6995 @item relayhost
6996 (string). The host to which the outbound SMTP connection should be
6997 made. Defaults to 'localhost'
6999 @item lookup
7000 (implementor of @code{IEmailLookup}). Object which provides
7001 IEmailLookup, which is responsible for mapping User names (which come
7002 from the VC system) into valid email addresses. If not provided, the
7003 notifier will only be able to send mail to the addresses in the
7004 extraRecipients list. Most of the time you can use a simple Domain
7005 instance. As a shortcut, you can pass as string: this will be treated
7006 as if you had provided Domain(str). For example,
7007 lookup='twistedmatrix.com' will allow mail to be sent to all
7008 developers whose SVN usernames match their twistedmatrix.com account
7009 names. See buildbot/status/mail.py for more details.
7011 @end table
7014 @node IRC Bot, PBListener, MailNotifier, Status Delivery
7015 @section IRC Bot
7017 @cindex IRC
7018 @stindex buildbot.status.words.IRC
7021 The @code{buildbot.status.words.IRC} status target creates an IRC bot
7022 which will attach to certain channels and be available for status
7023 queries. It can also be asked to announce builds as they occur, or be
7024 told to shut up.
7026 @example
7027 from buildbot.status import words
7028 irc = words.IRC("irc.example.org", "botnickname", 
7029                 channels=["channel1", "channel2"],
7030                 password="mysecretpassword")
7031 c['status'].append(irc)
7032 @end example
7034 Take a look at the docstring for @code{words.IRC} for more details on
7035 configuring this service. The @code{password} argument, if provided,
7036 will be sent to Nickserv to claim the nickname: some IRC servers will
7037 not allow clients to send private messages until they have logged in
7038 with a password.
7040 To use the service, you address messages at the buildbot, either
7041 normally (@code{botnickname: status}) or with private messages
7042 (@code{/msg botnickname status}). The buildbot will respond in kind.
7044 Some of the commands currently available:
7046 @table @code
7048 @item list builders
7049 Emit a list of all configured builders
7050 @item status BUILDER
7051 Announce the status of a specific Builder: what it is doing right now.
7052 @item status all
7053 Announce the status of all Builders
7054 @item watch BUILDER
7055 If the given Builder is currently running, wait until the Build is
7056 finished and then announce the results.
7057 @item last BUILDER
7058 Return the results of the last build to run on the given Builder.
7059 @item join CHANNEL
7060 Join the given IRC channel
7061 @item leave CHANNEL
7062 Leave the given IRC channel
7063 @item notify on|off|list EVENT
7064 Report events relating to builds.  If the command is issued as a
7065 private message, then the report will be sent back as a private
7066 message to the user who issued the command.  Otherwise, the report
7067 will be sent to the channel.  Available events to be notified are:
7069 @table @code
7070 @item started
7071 A build has started
7072 @item finished
7073 A build has finished
7074 @item success
7075 A build finished successfully
7076 @item failed
7077 A build failed
7078 @item exception
7079 A build generated and exception
7080 @item successToFailure
7081 The previous build was successful, but this one failed
7082 @item failureToSuccess
7083 The previous build failed, but this one was successful
7084 @end table
7086 @item help COMMAND
7087 Describe a command. Use @code{help commands} to get a list of known
7088 commands.
7089 @item source
7090 Announce the URL of the Buildbot's home page.
7091 @item version
7092 Announce the version of this Buildbot.
7093 @end table
7095 If the @code{allowForce=True} option was used, some addtional commands
7096 will be available:
7098 @table @code
7099 @item force build BUILDER REASON
7100 Tell the given Builder to start a build of the latest code. The user
7101 requesting the build and REASON are recorded in the Build status. The
7102 buildbot will announce the build's status when it finishes.
7104 @item stop build BUILDER REASON
7105 Terminate any running build in the given Builder. REASON will be added
7106 to the build status to explain why it was stopped. You might use this
7107 if you committed a bug, corrected it right away, and don't want to
7108 wait for the first build (which is destined to fail) to complete
7109 before starting the second (hopefully fixed) build.
7110 @end table
7112 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
7113 @section PBListener
7115 @cindex PBListener
7116 @stindex buildbot.status.client.PBListener
7119 @example
7120 import buildbot.status.client
7121 pbl = buildbot.status.client.PBListener(port=int, user=str,
7122                                         passwd=str)
7123 c['status'].append(pbl)
7124 @end example
7126 This sets up a PB listener on the given TCP port, to which a PB-based
7127 status client can connect and retrieve status information.
7128 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
7129 status client. The @code{port} argument can also be a strports
7130 specification string.
7132 @node Writing New Status Plugins,  , PBListener, Status Delivery
7133 @section Writing New Status Plugins
7135 TODO: this needs a lot more examples
7137 Each status plugin is an object which provides the
7138 @code{twisted.application.service.IService} interface, which creates a
7139 tree of Services with the buildmaster at the top [not strictly true].
7140 The status plugins are all children of an object which implements
7141 @code{buildbot.interfaces.IStatus}, the main status object. From this
7142 object, the plugin can retrieve anything it wants about current and
7143 past builds. It can also subscribe to hear about new and upcoming
7144 builds.
7146 Status plugins which only react to human queries (like the Waterfall
7147 display) never need to subscribe to anything: they are idle until
7148 someone asks a question, then wake up and extract the information they
7149 need to answer it, then they go back to sleep. Plugins which need to
7150 act spontaneously when builds complete (like the MailNotifier plugin)
7151 need to subscribe to hear about new builds.
7153 If the status plugin needs to run network services (like the HTTP
7154 server used by the Waterfall plugin), they can be attached as Service
7155 children of the plugin itself, using the @code{IServiceCollection}
7156 interface.
7160 @node Command-line tool, Resources, Status Delivery, Top
7161 @chapter Command-line tool
7163 The @command{buildbot} command-line tool can be used to start or stop a
7164 buildmaster or buildbot, and to interact with a running buildmaster.
7165 Some of its subcommands are intended for buildmaster admins, while
7166 some are for developers who are editing the code that the buildbot is
7167 monitoring.
7169 @menu
7170 * Administrator Tools::         
7171 * Developer Tools::             
7172 * Other Tools::                 
7173 * .buildbot config directory::  
7174 @end menu
7176 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
7177 @section Administrator Tools
7179 The following @command{buildbot} sub-commands are intended for
7180 buildmaster administrators:
7182 @heading create-master
7184 This creates a new directory and populates it with files that allow it
7185 to be used as a buildmaster's base directory.
7187 @example
7188 buildbot create-master BASEDIR
7189 @end example
7191 @heading create-slave
7193 This creates a new directory and populates it with files that let it
7194 be used as a buildslave's base directory. You must provide several
7195 arguments, which are used to create the initial @file{buildbot.tac}
7196 file.
7198 @example
7199 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
7200 @end example
7202 @heading start
7204 This starts a buildmaster or buildslave which was already created in
7205 the given base directory. The daemon is launched in the background,
7206 with events logged to a file named @file{twistd.log}.
7208 @example
7209 buildbot start BASEDIR
7210 @end example
7212 @heading stop
7214 This terminates the daemon (either buildmaster or buildslave) running
7215 in the given directory.
7217 @example
7218 buildbot stop BASEDIR
7219 @end example
7221 @heading sighup
7223 This sends a SIGHUP to the buildmaster running in the given directory,
7224 which causes it to re-read its @file{master.cfg} file.
7226 @example
7227 buildbot sighup BASEDIR
7228 @end example
7230 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
7231 @section Developer Tools
7233 These tools are provided for use by the developers who are working on
7234 the code that the buildbot is monitoring.
7236 @menu
7237 * statuslog::                   
7238 * statusgui::                   
7239 * try::                         
7240 @end menu
7242 @node statuslog, statusgui, Developer Tools, Developer Tools
7243 @subsection statuslog
7245 @example
7246 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
7247 @end example
7249 This command starts a simple text-based status client, one which just
7250 prints out a new line each time an event occurs on the buildmaster.
7252 The @option{--master} option provides the location of the
7253 @code{buildbot.status.client.PBListener} status port, used to deliver
7254 build information to realtime status clients. The option is always in
7255 the form of a string, with hostname and port number separated by a
7256 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
7257 same as the slaveport (although a future version may allow the same
7258 port number to be used for both purposes). If you get an error message
7259 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
7260 this may indicate that you are connecting to the slaveport rather than
7261 a @code{PBListener} port.
7263 The @option{--master} option can also be provided by the
7264 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
7265 config directory}).
7267 @node statusgui, try, statuslog, Developer Tools
7268 @subsection statusgui
7270 @cindex statusgui
7272 If you have set up a PBListener (@pxref{PBListener}), you will be able
7273 to monitor your Buildbot using a simple Gtk+ application invoked with
7274 the @code{buildbot statusgui} command:
7276 @example
7277 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
7278 @end example
7280 This command starts a simple Gtk+-based status client, which contains
7281 a few boxes for each Builder that change color as events occur. It
7282 uses the same @option{--master} argument as the @command{buildbot
7283 statuslog} command (@pxref{statuslog}).
7285 @node try,  , statusgui, Developer Tools
7286 @subsection try
7288 This lets a developer to ask the question ``What would happen if I
7289 committed this patch right now?''. It runs the unit test suite (across
7290 multiple build platforms) on the developer's current code, allowing
7291 them to make sure they will not break the tree when they finally
7292 commit their changes.
7294 The @command{buildbot try} command is meant to be run from within a
7295 developer's local tree, and starts by figuring out the base revision
7296 of that tree (what revision was current the last time the tree was
7297 updated), and a patch that can be applied to that revision of the tree
7298 to make it match the developer's copy. This (revision, patch) pair is
7299 then sent to the buildmaster, which runs a build with that
7300 SourceStamp. If you want, the tool will emit status messages as the
7301 builds run, and will not terminate until the first failure has been
7302 detected (or the last success).
7304 There is an alternate form which accepts a pre-made patch file
7305 (typically the output of a command like 'svn diff'). This ``--diff''
7306 form does not require a local tree to run from. See @xref{try --diff}.
7308 For this command to work, several pieces must be in place:
7311 @heading TryScheduler
7313 @slindex buildbot.scheduler.Try_Jobdir
7314 @slindex buildbot.scheduler.Try_Userpass
7316 The buildmaster must have a @code{scheduler.Try} instance in
7317 the config file's @code{c['schedulers']} list. This lets the
7318 administrator control who may initiate these ``trial'' builds, which
7319 branches are eligible for trial builds, and which Builders should be
7320 used for them.
7322 The @code{TryScheduler} has various means to accept build requests:
7323 all of them enforce more security than the usual buildmaster ports do.
7324 Any source code being built can be used to compromise the buildslave
7325 accounts, but in general that code must be checked out from the VC
7326 repository first, so only people with commit privileges can get
7327 control of the buildslaves. The usual force-build control channels can
7328 waste buildslave time but do not allow arbitrary commands to be
7329 executed by people who don't have those commit privileges. However,
7330 the source code patch that is provided with the trial build does not
7331 have to go through the VC system first, so it is important to make
7332 sure these builds cannot be abused by a non-committer to acquire as
7333 much control over the buildslaves as a committer has. Ideally, only
7334 developers who have commit access to the VC repository would be able
7335 to start trial builds, but unfortunately the buildmaster does not, in
7336 general, have access to VC system's user list.
7338 As a result, the @code{TryScheduler} requires a bit more
7339 configuration. There are currently two ways to set this up:
7341 @table @strong
7342 @item jobdir (ssh)
7344 This approach creates a command queue directory, called the
7345 ``jobdir'', in the buildmaster's working directory. The buildmaster
7346 admin sets the ownership and permissions of this directory to only
7347 grant write access to the desired set of developers, all of whom must
7348 have accounts on the machine. The @code{buildbot try} command creates
7349 a special file containing the source stamp information and drops it in
7350 the jobdir, just like a standard maildir. When the buildmaster notices
7351 the new file, it unpacks the information inside and starts the builds.
7353 The config file entries used by 'buildbot try' either specify a local
7354 queuedir (for which write and mv are used) or a remote one (using scp
7355 and ssh).
7357 The advantage of this scheme is that it is quite secure, the
7358 disadvantage is that it requires fiddling outside the buildmaster
7359 config (to set the permissions on the jobdir correctly). If the
7360 buildmaster machine happens to also house the VC repository, then it
7361 can be fairly easy to keep the VC userlist in sync with the
7362 trial-build userlist. If they are on different machines, this will be
7363 much more of a hassle. It may also involve granting developer accounts
7364 on a machine that would not otherwise require them.
7366 To implement this, the buildslave invokes 'ssh -l username host
7367 buildbot tryserver ARGS', passing the patch contents over stdin. The
7368 arguments must include the inlet directory and the revision
7369 information.
7371 @item user+password (PB)
7373 In this approach, each developer gets a username/password pair, which
7374 are all listed in the buildmaster's configuration file. When the
7375 developer runs @code{buildbot try}, their machine connects to the
7376 buildmaster via PB and authenticates themselves using that username
7377 and password, then sends a PB command to start the trial build.
7379 The advantage of this scheme is that the entire configuration is
7380 performed inside the buildmaster's config file. The disadvantages are
7381 that it is less secure (while the ``cred'' authentication system does
7382 not expose the password in plaintext over the wire, it does not offer
7383 most of the other security properties that SSH does). In addition, the
7384 buildmaster admin is responsible for maintaining the username/password
7385 list, adding and deleting entries as developers come and go.
7387 @end table
7390 For example, to set up the ``jobdir'' style of trial build, using a
7391 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
7392 all your project developers were members of the @code{developers} unix
7393 group), you would first create that directory (with @command{mkdir
7394 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
7395 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
7396 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
7397 MASTERDIR/jobdir/*}), and then use the following scheduler in the
7398 buildmaster's config file:
7400 @example
7401 from buildbot.scheduler import Try_Jobdir
7402 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
7403                jobdir="jobdir")
7404 c['schedulers'] = [s]
7405 @end example
7407 Note that you must create the jobdir before telling the buildmaster to
7408 use this configuration, otherwise you will get an error. Also remember
7409 that the buildmaster must be able to read and write to the jobdir as
7410 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
7411 as you start using the jobdir, to make sure the buildmaster is happy
7412 with it.
7414 To use the username/password form of authentication, create a
7415 @code{Try_Userpass} instance instead. It takes the same
7416 @code{builderNames} argument as the @code{Try_Jobdir} form, but
7417 accepts an addtional @code{port} argument (to specify the TCP port to
7418 listen on) and a @code{userpass} list of username/password pairs to
7419 accept. Remember to use good passwords for this: the security of the
7420 buildslave accounts depends upon it:
7422 @example
7423 from buildbot.scheduler import Try_Userpass
7424 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
7425                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
7426 c['schedulers'] = [s]
7427 @end example
7429 Like most places in the buildbot, the @code{port} argument takes a
7430 strports specification. See @code{twisted.application.strports} for
7431 details.
7434 @heading locating the master
7436 The @command{try} command needs to be told how to connect to the
7437 @code{TryScheduler}, and must know which of the authentication
7438 approaches described above is in use by the buildmaster. You specify
7439 the approach by using @option{--connect=ssh} or @option{--connect=pb}
7440 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
7441 @file{.buildbot/options}).
7443 For the PB approach, the command must be given a @option{--master}
7444 argument (in the form HOST:PORT) that points to TCP port that you
7445 picked in the @code{Try_Userpass} scheduler. It also takes a
7446 @option{--username} and @option{--passwd} pair of arguments that match
7447 one of the entries in the buildmaster's @code{userpass} list. These
7448 arguments can also be provided as @code{try_master},
7449 @code{try_username}, and @code{try_password} entries in the
7450 @file{.buildbot/options} file.
7452 For the SSH approach, the command must be given @option{--tryhost},
7453 @option{--username}, and optionally @option{--password} (TODO:
7454 really?) to get to the buildmaster host. It must also be given
7455 @option{--trydir}, which points to the inlet directory configured
7456 above. The trydir can be relative to the user's home directory, but
7457 most of the time you will use an explicit path like
7458 @file{~buildbot/project/trydir}. These arguments can be provided in
7459 @file{.buildbot/options} as @code{try_host}, @code{try_username},
7460 @code{try_password}, and @code{try_dir}.
7462 In addition, the SSH approach needs to connect to a PBListener status
7463 port, so it can retrieve and report the results of the build (the PB
7464 approach uses the existing connection to retrieve status information,
7465 so this step is not necessary). This requires a @option{--master}
7466 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
7467 in the form of a HOSTNAME:PORT string.
7470 @heading choosing the Builders
7472 A trial build is performed on multiple Builders at the same time, and
7473 the developer gets to choose which Builders are used (limited to a set
7474 selected by the buildmaster admin with the TryScheduler's
7475 @code{builderNames=} argument). The set you choose will depend upon
7476 what your goals are: if you are concerned about cross-platform
7477 compatibility, you should use multiple Builders, one from each
7478 platform of interest. You might use just one builder if that platform
7479 has libraries or other facilities that allow better test coverage than
7480 what you can accomplish on your own machine, or faster test runs.
7482 The set of Builders to use can be specified with multiple
7483 @option{--builder} arguments on the command line. It can also be
7484 specified with a single @code{try_builders} option in
7485 @file{.buildbot/options} that uses a list of strings to specify all
7486 the Builder names:
7488 @example
7489 try_builders = ["full-OSX", "full-win32", "full-linux"]
7490 @end example
7492 @heading specifying the VC system
7494 The @command{try} command also needs to know how to take the
7495 developer's current tree and extract the (revision, patch)
7496 source-stamp pair. Each VC system uses a different process, so you
7497 start by telling the @command{try} command which VC system you are
7498 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
7499 This can also be provided as @code{try_vc} in
7500 @file{.buildbot/options}.
7502 The following names are recognized: @code{cvs} @code{svn} @code{baz}
7503 @code{tla} @code{hg} @code{darcs}
7506 @heading finding the top of the tree
7508 Some VC systems (notably CVS and SVN) track each directory
7509 more-or-less independently, which means the @command{try} command
7510 needs to move up to the top of the project tree before it will be able
7511 to construct a proper full-tree patch. To accomplish this, the
7512 @command{try} command will crawl up through the parent directories
7513 until it finds a marker file. The default name for this marker file is
7514 @file{.buildbot-top}, so when you are using CVS or SVN you should
7515 @code{touch .buildbot-top} from the top of your tree before running
7516 @command{buildbot try}. Alternatively, you can use a filename like
7517 @file{ChangeLog} or @file{README}, since many projects put one of
7518 these files in their top-most directory (and nowhere else). To set
7519 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
7520 options file with @code{try_topfile = 'ChangeLog'}.
7522 You can also manually set the top of the tree with
7523 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
7524 '~/trees/mytree'}. If you use @code{try_topdir}, in a
7525 @file{.buildbot/options} file, you will need a separate options file
7526 for each tree you use, so it may be more convenient to use the
7527 @code{try_topfile} approach instead.
7529 Other VC systems which work on full projects instead of individual
7530 directories (tla, baz, darcs, monotone, mercurial, git) do not require
7531 @command{try} to know the top directory, so the @option{--try-topfile}
7532 and @option{--try-topdir} arguments will be ignored.
7533 @c is this true? I think I currently require topdirs all the time.
7535 If the @command{try} command cannot find the top directory, it will
7536 abort with an error message.
7538 @heading determining the branch name
7540 Some VC systems record the branch information in a way that ``try''
7541 can locate it, in particular Arch (both @command{tla} and
7542 @command{baz}). For the others, if you are using something other than
7543 the default branch, you will have to tell the buildbot which branch
7544 your tree is using. You can do this with either the @option{--branch}
7545 argument, or a @option{try_branch} entry in the
7546 @file{.buildbot/options} file.
7548 @heading determining the revision and patch
7550 Each VC system has a separate approach for determining the tree's base
7551 revision and computing a patch.
7553 @table @code
7555 @item CVS
7557 @command{try} pretends that the tree is up to date. It converts the
7558 current time into a @code{-D} time specification, uses it as the base
7559 revision, and computes the diff between the upstream tree as of that
7560 point in time versus the current contents. This works, more or less,
7561 but requires that the local clock be in reasonably good sync with the
7562 repository.
7564 @item SVN
7565 @command{try} does a @code{svn status -u} to find the latest
7566 repository revision number (emitted on the last line in the ``Status
7567 against revision: NN'' message). It then performs an @code{svn diff
7568 -rNN} to find out how your tree differs from the repository version,
7569 and sends the resulting patch to the buildmaster. If your tree is not
7570 up to date, this will result in the ``try'' tree being created with
7571 the latest revision, then @emph{backwards} patches applied to bring it
7572 ``back'' to the version you actually checked out (plus your actual
7573 code changes), but this will still result in the correct tree being
7574 used for the build.
7576 @item baz
7577 @command{try} does a @code{baz tree-id} to determine the
7578 fully-qualified version and patch identifier for the tree
7579 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
7580 as the base revision. It then does a @code{baz diff} to obtain the
7581 patch.
7583 @item tla
7584 @command{try} does a @code{tla tree-version} to get the
7585 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
7586 first line of @code{tla logs --reverse} to figure out the base
7587 revision. Then it does @code{tla changes --diffs} to obtain the patch.
7589 @item Darcs
7590 @code{darcs changes --context} emits a text file that contains a list
7591 of all patches back to and including the last tag was made. This text
7592 file (plus the location of a repository that contains all these
7593 patches) is sufficient to re-create the tree. Therefore the contents
7594 of this ``context'' file @emph{are} the revision stamp for a
7595 Darcs-controlled source tree.
7597 So @command{try} does a @code{darcs changes --context} to determine
7598 what your tree's base revision is, and then does a @code{darcs diff
7599 -u} to compute the patch relative to that revision.
7601 @item Mercurial
7602 @code{hg identify} emits a short revision ID (basically a truncated
7603 SHA1 hash of the current revision's contents), which is used as the
7604 base revision. @code{hg diff} then provides the patch relative to that
7605 revision. For @command{try} to work, your working directory must only
7606 have patches that are available from the same remotely-available
7607 repository that the build process' @code{step.Mercurial} will use.
7609 @item Git
7610 @code{git branch -v} lists all the branches available in the local
7611 repository along with the revision ID it points to and a short summary
7612 of the last commit. The line containing the currently checked out
7613 branch begins with '* ' (star and space) while all the others start
7614 with '  ' (two spaces). @command{try} scans for this line and extracts
7615 the branch name and revision from it. Then it generates a diff against
7616 the base revision.
7617 @c TODO: I'm not sure if this actually works the way it's intended
7618 @c since the extracted base revision might not actually exist in the
7619 @c upstream repository. Perhaps we need to add a --remote option to
7620 @c specify the remote tracking branch to generate a diff against.
7622 @c TODO: monotone
7623 @end table
7625 @heading waiting for results
7627 If you provide the @option{--wait} option (or @code{try_wait = True}
7628 in @file{.buildbot/options}), the @command{buildbot try} command will
7629 wait until your changes have either been proven good or bad before
7630 exiting. Unless you use the @option{--quiet} option (or
7631 @code{try_quiet=True}), it will emit a progress message every 60
7632 seconds until the builds have completed.
7634 @menu
7635 * try --diff::                  
7636 @end menu
7638 @node try --diff,  , try, try
7639 @subsubsection try --diff
7641 Sometimes you might have a patch from someone else that you want to
7642 submit to the buildbot. For example, a user may have created a patch
7643 to fix some specific bug and sent it to you by email. You've inspected
7644 the patch and suspect that it might do the job (and have at least
7645 confirmed that it doesn't do anything evil). Now you want to test it
7646 out.
7648 One approach would be to check out a new local tree, apply the patch,
7649 run your local tests, then use ``buildbot try'' to run the tests on
7650 other platforms. An alternate approach is to use the @command{buildbot
7651 try --diff} form to have the buildbot test the patch without using a
7652 local tree.
7654 This form takes a @option{--diff} argument which points to a file that
7655 contains the patch you want to apply. By default this patch will be
7656 applied to the TRUNK revision, but if you give the optional
7657 @option{--baserev} argument, a tree of the given revision will be used
7658 as a starting point instead of TRUNK.
7660 You can also use @command{buildbot try --diff=-} to read the patch
7661 from stdin.
7663 Each patch has a ``patchlevel'' associated with it. This indicates the
7664 number of slashes (and preceding pathnames) that should be stripped
7665 before applying the diff. This exactly corresponds to the @option{-p}
7666 or @option{--strip} argument to the @command{patch} utility. By
7667 default @command{buildbot try --diff} uses a patchlevel of 0, but you
7668 can override this with the @option{-p} argument.
7670 When you use @option{--diff}, you do not need to use any of the other
7671 options that relate to a local tree, specifically @option{--vc},
7672 @option{--try-topfile}, or @option{--try-topdir}. These options will
7673 be ignored. Of course you must still specify how to get to the
7674 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
7677 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
7678 @section Other Tools
7680 These tools are generally used by buildmaster administrators.
7682 @menu
7683 * sendchange::                  
7684 * debugclient::                 
7685 @end menu
7687 @node sendchange, debugclient, Other Tools, Other Tools
7688 @subsection sendchange
7690 This command is used to tell the buildmaster about source changes. It
7691 is intended to be used from within a commit script, installed on the
7692 VC server. It requires that you have a PBChangeSource
7693 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
7694 @code{c['change_source']}).
7697 @example
7698 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
7699 @end example
7701 There are other (optional) arguments which can influence the
7702 @code{Change} that gets submitted:
7704 @table @code
7705 @item --branch
7706 This provides the (string) branch specifier. If omitted, it defaults
7707 to None, indicating the ``default branch''. All files included in this
7708 Change must be on the same branch.
7710 @item --revision_number
7711 This provides a (numeric) revision number for the change, used for VC systems
7712 that use numeric transaction numbers (like Subversion).
7714 @item --revision
7715 This provides a (string) revision specifier, for VC systems that use
7716 strings (Arch would use something like patch-42 etc).
7718 @item --revision_file
7719 This provides a filename which will be opened and the contents used as
7720 the revision specifier. This is specifically for Darcs, which uses the
7721 output of @command{darcs changes --context} as a revision specifier.
7722 This context file can be a couple of kilobytes long, spanning a couple
7723 lines per patch, and would be a hassle to pass as a command-line
7724 argument.
7726 @item --comments
7727 This provides the change comments as a single argument. You may want
7728 to use @option{--logfile} instead.
7730 @item --logfile
7731 This instructs the tool to read the change comments from the given
7732 file. If you use @code{-} as the filename, the tool will read the
7733 change comments from stdin.
7734 @end table
7737 @node debugclient,  , sendchange, Other Tools
7738 @subsection debugclient
7740 @example
7741 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
7742 @end example
7744 This launches a small Gtk+/Glade-based debug tool, connecting to the
7745 buildmaster's ``debug port''. This debug port shares the same port
7746 number as the slaveport (@pxref{Setting the slaveport}), but the
7747 @code{debugPort} is only enabled if you set a debug password in the
7748 buildmaster's config file (@pxref{Debug options}). The
7749 @option{--passwd} option must match the @code{c['debugPassword']}
7750 value.
7752 @option{--master} can also be provided in @file{.debug/options} by the
7753 @code{master} key. @option{--passwd} can be provided by the
7754 @code{debugPassword} key.
7756 The @code{Connect} button must be pressed before any of the other
7757 buttons will be active. This establishes the connection to the
7758 buildmaster. The other sections of the tool are as follows:
7760 @table @code
7761 @item Reload .cfg
7762 Forces the buildmaster to reload its @file{master.cfg} file. This is
7763 equivalent to sending a SIGHUP to the buildmaster, but can be done
7764 remotely through the debug port. Note that it is a good idea to be
7765 watching the buildmaster's @file{twistd.log} as you reload the config
7766 file, as any errors which are detected in the config file will be
7767 announced there.
7769 @item Rebuild .py
7770 (not yet implemented). The idea here is to use Twisted's ``rebuild''
7771 facilities to replace the buildmaster's running code with a new
7772 version. Even if this worked, it would only be used by buildbot
7773 developers.
7775 @item poke IRC
7776 This locates a @code{words.IRC} status target and causes it to emit a
7777 message on all the channels to which it is currently connected. This
7778 was used to debug a problem in which the buildmaster lost the
7779 connection to the IRC server and did not attempt to reconnect.
7781 @item Commit
7782 This allows you to inject a Change, just as if a real one had been
7783 delivered by whatever VC hook you are using. You can set the name of
7784 the committed file and the name of the user who is doing the commit.
7785 Optionally, you can also set a revision for the change. If the
7786 revision you provide looks like a number, it will be sent as an
7787 integer, otherwise it will be sent as a string.
7789 @item Force Build
7790 This lets you force a Builder (selected by name) to start a build of
7791 the current source tree.
7793 @item Currently
7794 (obsolete). This was used to manually set the status of the given
7795 Builder, but the status-assignment code was changed in an incompatible
7796 way and these buttons are no longer meaningful.
7798 @end table
7801 @node .buildbot config directory,  , Other Tools, Command-line tool
7802 @section .buildbot config directory
7804 Many of the @command{buildbot} tools must be told how to contact the
7805 buildmaster that they interact with. This specification can be
7806 provided as a command-line argument, but most of the time it will be
7807 easier to set them in an ``options'' file. The @command{buildbot}
7808 command will look for a special directory named @file{.buildbot},
7809 starting from the current directory (where the command was run) and
7810 crawling upwards, eventually looking in the user's home directory. It
7811 will look for a file named @file{options} in this directory, and will
7812 evaluate it as a python script, looking for certain names to be set.
7813 You can just put simple @code{name = 'value'} pairs in this file to
7814 set the options.
7816 For a description of the names used in this file, please see the
7817 documentation for the individual @command{buildbot} sub-commands. The
7818 following is a brief sample of what this file's contents could be.
7820 @example
7821 # for status-reading tools
7822 masterstatus = 'buildbot.example.org:12345'
7823 # for 'sendchange' or the debug port
7824 master = 'buildbot.example.org:18990'
7825 debugPassword = 'eiv7Po'
7826 @end example
7828 @table @code
7829 @item masterstatus
7830 Location of the @code{client.PBListener} status port, used by
7831 @command{statuslog} and @command{statusgui}.
7833 @item master
7834 Location of the @code{debugPort} (for @command{debugclient}). Also the
7835 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
7836 Usually shares the slaveport, but a future version may make it
7837 possible to have these listen on a separate port number.
7839 @item debugPassword
7840 Must match the value of @code{c['debugPassword']}, used to protect the
7841 debug port, for the @command{debugclient} command.
7843 @item username
7844 Provides a default username for the @command{sendchange} command.
7846 @end table
7849 The following options are used by the @code{buildbot try} command
7850 (@pxref{try}):
7852 @table @code
7853 @item try_connect
7854 This specifies how the ``try'' command should deliver its request to
7855 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
7856 @item try_builders
7857 Which builders should be used for the ``try'' build.
7858 @item try_vc
7859 This specifies the version control system being used.
7860 @item try_branch
7861 This indicates that the current tree is on a non-trunk branch.
7862 @item try_topdir
7863 @item try_topfile
7864 Use @code{try_topdir} to explicitly indicate the top of your working
7865 tree, or @code{try_topfile} to name a file that will only be found in
7866 that top-most directory.
7868 @item try_host
7869 @item try_username
7870 @item try_dir
7871 When try_connect is ``ssh'', the command will pay attention to
7872 @code{try_host}, @code{try_username}, and @code{try_dir}.
7874 @item try_username
7875 @item try_password
7876 @item try_master
7877 Instead, when @code{try_connect} is ``pb'', the command will pay
7878 attention to @code{try_username}, @code{try_password}, and
7879 @code{try_master}.
7881 @item try_wait
7882 @item masterstatus
7883 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
7884 command to wait for the requested build to complete.
7886 @end table
7890 @node Resources, Developer's Appendix, Command-line tool, Top
7891 @chapter Resources
7893 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
7895 For configuration questions and general discussion, please use the
7896 @code{buildbot-devel} mailing list. The subscription instructions and
7897 archives are available at
7898 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
7900 @node Developer's Appendix, Index of Useful Classes, Resources, Top
7901 @unnumbered Developer's Appendix
7903 This appendix contains random notes about the implementation of the
7904 Buildbot, and is likely to only be of use to people intending to
7905 extend the Buildbot's internals.
7907 The buildmaster consists of a tree of Service objects, which is shaped
7908 as follows:
7910 @example
7911 BuildMaster
7912  ChangeMaster  (in .change_svc)
7913   [IChangeSource instances]
7914  [IScheduler instances]  (in .schedulers)
7915  BotMaster  (in .botmaster)
7916   [IBuildSlave instances]
7917  [IStatusTarget instances]  (in .statusTargets)
7918 @end example
7920 The BotMaster has a collection of Builder objects as values of its
7921 @code{.builders} dictionary.
7924 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
7925 @unnumbered Index of Useful Classes
7927 This is a list of all user-visible classes. There are the ones that
7928 are useful in @file{master.cfg}, the buildmaster's configuration file.
7929 Classes that are not listed here are generally internal things that
7930 admins are unlikely to have much use for.
7933 @heading Change Sources
7934 @printindex cs
7936 @heading Schedulers and Locks
7937 @printindex sl
7939 @heading Build Factories
7940 @printindex bf
7942 @heading Build Steps
7943 @printindex bs
7945 @c undocumented steps
7946 @bsindex buildbot.steps.source.Git
7947 @bsindex buildbot.steps.maxq.MaxQ
7950 @heading Status Targets
7951 @printindex st
7953 @c TODO: undocumented targets
7955 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
7956 @unnumbered Index of master.cfg keys
7958 This is a list of all of the significant keys in master.cfg . Recall
7959 that master.cfg is effectively a small python program with exactly one
7960 responsibility: create a dictionary named @code{BuildmasterConfig}.
7961 The keys of this dictionary are listed here. The beginning of the
7962 master.cfg file typically starts with something like:
7964 @example
7965 BuildmasterConfig = c = @{@}
7966 @end example
7968 Therefore a config key of @code{change_source} will usually appear in
7969 master.cfg as @code{c['change_source']}.
7971 @printindex bc
7974 @node Index,  , Index of master.cfg keys, Top
7975 @unnumbered Index
7977 @printindex cp
7980 @bye