web: handle branch=trunk usefully
[buildbot.git] / docs / buildbot.texinfo
blob98244b039885e376eb344b4f2c0aee58ef4e875c
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.5+
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::                       
113 Version Control Systems
115 * Generalizing VC Systems::     
116 * Source Tree Specifications::  
117 * How Different VC Systems Specify Sources::  
118 * Attributes of Changes::       
120 Users
122 * Doing Things With Users::     
123 * Email Addresses::             
124 * IRC Nicknames::               
125 * Live Status Clients::         
127 Configuration
129 * Config File Format::          
130 * Loading the Config File::     
131 * Defining the Project::        
132 * Listing Change Sources and Schedulers::  
133 * Setting the slaveport::       
134 * Buildslave Specifiers::       
135 * Defining Builders::           
136 * Defining Status Targets::     
137 * Debug options::               
139 Listing Change Sources and Schedulers
141 * Scheduler Types::             
142 * Build Dependencies::          
144 Buildslave Specifiers
146 * When Buildslaves Go Missing::  
148 Getting Source Code Changes
150 * Change Sources::              
151 * Choosing ChangeSources::      
152 * CVSToys - PBService::         
153 * Mail-parsing ChangeSources::  
154 * PBChangeSource::              
155 * P4Source::                    
156 * BonsaiPoller::                
157 * SVNPoller::                   
158 * MercurialHook::               
160 Mail-parsing ChangeSources
162 * Subscribing the Buildmaster::  
163 * Using Maildirs::              
164 * Parsing Email Change Messages::  
166 Parsing Email Change Messages
168 * FCMaildirSource::             
169 * SyncmailMaildirSource::       
170 * BonsaiMaildirSource::         
171 * SVNCommitEmailMaildirSource::  
173 Build Process
175 * Build Steps::                 
176 * Interlocks::                  
177 * Build Factories::             
179 Build Steps
181 * Common Parameters::           
182 * Source Checkout::             
183 * ShellCommand::                
184 * Simple ShellCommand Subclasses::  
185 * Python BuildSteps::           
186 * Transferring Files::          
187 * Writing New BuildSteps::      
189 Source Checkout
191 * CVS::                         
192 * SVN::                         
193 * Darcs::                       
194 * Mercurial::                   
195 * Arch::                        
196 * Bazaar::                      
197 * Bzr::                         
198 * P4::                          
200 Simple ShellCommand Subclasses
202 * Configure::                   
203 * Compile::                     
204 * Test::                        
205 * Build Properties::            
207 Python BuildSteps
209 * BuildEPYDoc::                 
210 * PyFlakes::                    
212 Writing New BuildSteps
214 * BuildStep LogFiles::          
215 * Reading Logfiles::            
216 * Adding LogObservers::         
217 * BuildStep URLs::              
219 Build Factories
221 * BuildStep Objects::           
222 * BuildFactory::                
223 * Process-Specific build factories::  
225 BuildStep Objects
227 * BuildFactory Attributes::     
228 * Quick builds::                
230 BuildFactory
232 * BuildFactory Attributes::     
233 * Quick builds::                
235 Process-Specific build factories
237 * GNUAutoconf::                 
238 * CPAN::                        
239 * Python distutils::            
240 * Python/Twisted/trial projects::  
242 Status Delivery
244 * WebStatus::                   
245 * MailNotifier::                
246 * IRC Bot::                     
247 * PBListener::                  
248 * Writing New Status Plugins::  
250 WebStatus
252 * WebStatus Configuration Parameters::  
253 * Buildbot Web Resources::      
254 * XMLRPC server::               
255 * HTML Waterfall::              
257 Command-line tool
259 * Administrator Tools::         
260 * Developer Tools::             
261 * Other Tools::                 
262 * .buildbot config directory::  
264 Developer Tools
266 * statuslog::                   
267 * statusgui::                   
268 * try::                         
270 waiting for results
272 * try --diff::                  
274 Other Tools
276 * sendchange::                  
277 * debugclient::                 
279 @end detailmenu
280 @end menu
282 @node Introduction, Installation, Top, Top
283 @chapter Introduction
285 @cindex introduction
287 The BuildBot is a system to automate the compile/test cycle required by most
288 software projects to validate code changes. By automatically rebuilding and
289 testing the tree each time something has changed, build problems are
290 pinpointed quickly, before other developers are inconvenienced by the
291 failure. The guilty developer can be identified and harassed without human
292 intervention. By running the builds on a variety of platforms, developers
293 who do not have the facilities to test their changes everywhere before
294 checkin will at least know shortly afterwards whether they have broken the
295 build or not. Warning counts, lint checks, image size, compile time, and
296 other build parameters can be tracked over time, are more visible, and
297 are therefore easier to improve.
299 The overall goal is to reduce tree breakage and provide a platform to
300 run tests or code-quality checks that are too annoying or pedantic for
301 any human to waste their time with. Developers get immediate (and
302 potentially public) feedback about their changes, encouraging them to
303 be more careful about testing before checkin.
305 Features:
307 @itemize @bullet
308 @item
309 run builds on a variety of slave platforms
310 @item
311 arbitrary build process: handles projects using C, Python, whatever
312 @item
313 minimal host requirements: python and Twisted
314 @item
315 slaves can be behind a firewall if they can still do checkout
316 @item
317 status delivery through web page, email, IRC, other protocols
318 @item
319 track builds in progress, provide estimated completion time
320 @item
321 flexible configuration by subclassing generic build process classes
322 @item
323 debug tools to force a new build, submit fake Changes, query slave status
324 @item
325 released under the GPL
326 @end itemize
328 @menu
329 * History and Philosophy::      
330 * System Architecture::         
331 * Control Flow::                
332 @end menu
335 @node History and Philosophy, System Architecture, Introduction, Introduction
336 @section History and Philosophy
338 @cindex Philosophy of operation
340 The Buildbot was inspired by a similar project built for a development
341 team writing a cross-platform embedded system. The various components
342 of the project were supposed to compile and run on several flavors of
343 unix (linux, solaris, BSD), but individual developers had their own
344 preferences and tended to stick to a single platform. From time to
345 time, incompatibilities would sneak in (some unix platforms want to
346 use @code{string.h}, some prefer @code{strings.h}), and then the tree
347 would compile for some developers but not others. The buildbot was
348 written to automate the human process of walking into the office,
349 updating a tree, compiling (and discovering the breakage), finding the
350 developer at fault, and complaining to them about the problem they had
351 introduced. With multiple platforms it was difficult for developers to
352 do the right thing (compile their potential change on all platforms);
353 the buildbot offered a way to help.
355 Another problem was when programmers would change the behavior of a
356 library without warning its users, or change internal aspects that
357 other code was (unfortunately) depending upon. Adding unit tests to
358 the codebase helps here: if an application's unit tests pass despite
359 changes in the libraries it uses, you can have more confidence that
360 the library changes haven't broken anything. Many developers
361 complained that the unit tests were inconvenient or took too long to
362 run: having the buildbot run them reduces the developer's workload to
363 a minimum.
365 In general, having more visibility into the project is always good,
366 and automation makes it easier for developers to do the right thing.
367 When everyone can see the status of the project, developers are
368 encouraged to keep the tree in good working order. Unit tests that
369 aren't run on a regular basis tend to suffer from bitrot just like
370 code does: exercising them on a regular basis helps to keep them
371 functioning and useful.
373 The current version of the Buildbot is additionally targeted at
374 distributed free-software projects, where resources and platforms are
375 only available when provided by interested volunteers. The buildslaves
376 are designed to require an absolute minimum of configuration, reducing
377 the effort a potential volunteer needs to expend to be able to
378 contribute a new test environment to the project. The goal is for
379 anyone who wishes that a given project would run on their favorite
380 platform should be able to offer that project a buildslave, running on
381 that platform, where they can verify that their portability code
382 works, and keeps working.
384 @node System Architecture, Control Flow, History and Philosophy, Introduction
385 @comment  node-name,  next,  previous,  up
386 @section System Architecture
388 The Buildbot consists of a single @code{buildmaster} and one or more
389 @code{buildslaves}, connected in a star topology. The buildmaster
390 makes all decisions about what, when, and how to build. It sends
391 commands to be run on the build slaves, which simply execute the
392 commands and return the results. (certain steps involve more local
393 decision making, where the overhead of sending a lot of commands back
394 and forth would be inappropriate, but in general the buildmaster is
395 responsible for everything).
397 The buildmaster is usually fed @code{Changes} by some sort of version
398 control system (@pxref{Change Sources}), which may cause builds to be
399 run. As the builds are performed, various status messages are
400 produced, which are then sent to any registered Status Targets
401 (@pxref{Status Delivery}).
403 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
404 @image{images/overview,,,Overview Diagram,}
406 The buildmaster is configured and maintained by the ``buildmaster
407 admin'', who is generally the project team member responsible for
408 build process issues. Each buildslave is maintained by a ``buildslave
409 admin'', who do not need to be quite as involved. Generally slaves are
410 run by anyone who has an interest in seeing the project work well on
411 their favorite platform.
413 @menu
414 * BuildSlave Connections::      
415 * Buildmaster Architecture::    
416 * Status Delivery Architecture::  
417 @end menu
419 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
420 @subsection BuildSlave Connections
422 The buildslaves are typically run on a variety of separate machines,
423 at least one per platform of interest. These machines connect to the
424 buildmaster over a TCP connection to a publically-visible port. As a
425 result, the buildslaves can live behind a NAT box or similar
426 firewalls, as long as they can get to buildmaster. The TCP connections
427 are initiated by the buildslave and accepted by the buildmaster, but
428 commands and results travel both ways within this connection. The
429 buildmaster is always in charge, so all commands travel exclusively
430 from the buildmaster to the buildslave.
432 To perform builds, the buildslaves must typically obtain source code
433 from a CVS/SVN/etc repository. Therefore they must also be able to
434 reach the repository. The buildmaster provides instructions for
435 performing builds, but does not provide the source code itself.
437 @image{images/slaves,,,BuildSlave Connections,}
439 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
440 @subsection Buildmaster Architecture
442 The Buildmaster consists of several pieces:
444 @image{images/master,,,BuildMaster Architecture,}
446 @itemize @bullet
448 @item
449 Change Sources, which create a Change object each time something is
450 modified in the VC repository. Most ChangeSources listen for messages
451 from a hook script of some sort. Some sources actively poll the
452 repository on a regular basis. All Changes are fed to the Schedulers.
454 @item
455 Schedulers, which decide when builds should be performed. They collect
456 Changes into BuildRequests, which are then queued for delivery to
457 Builders until a buildslave is available.
459 @item
460 Builders, which control exactly @emph{how} each build is performed
461 (with a series of BuildSteps, configured in a BuildFactory). Each
462 Build is run on a single buildslave.
464 @item
465 Status plugins, which deliver information about the build results
466 through protocols like HTTP, mail, and IRC.
468 @end itemize
470 @image{images/slavebuilder,,,SlaveBuilders,}
472 Each Builder is configured with a list of BuildSlaves that it will use
473 for its builds. These buildslaves are expected to behave identically:
474 the only reason to use multiple BuildSlaves for a single Builder is to
475 provide a measure of load-balancing.
477 Within a single BuildSlave, each Builder creates its own SlaveBuilder
478 instance. These SlaveBuilders operate independently from each other.
479 Each gets its own base directory to work in. It is quite common to
480 have many Builders sharing the same buildslave. For example, there
481 might be two buildslaves: one for i386, and a second for PowerPC.
482 There may then be a pair of Builders that do a full compile/test run,
483 one for each architecture, and a lone Builder that creates snapshot
484 source tarballs if the full builders complete successfully. The full
485 builders would each run on a single buildslave, whereas the tarball
486 creation step might run on either buildslave (since the platform
487 doesn't matter when creating source tarballs). In this case, the
488 mapping would look like:
490 @example
491 Builder(full-i386)  ->  BuildSlaves(slave-i386)
492 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
493 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
494 @end example
496 and each BuildSlave would have two SlaveBuilders inside it, one for a
497 full builder, and a second for the source-tarball builder.
499 Once a SlaveBuilder is available, the Builder pulls one or more
500 BuildRequests off its incoming queue. (It may pull more than one if it
501 determines that it can merge the requests together; for example, there
502 may be multiple requests to build the current HEAD revision). These
503 requests are merged into a single Build instance, which includes the
504 SourceStamp that describes what exact version of the source code
505 should be used for the build. The Build is then randomly assigned to a
506 free SlaveBuilder and the build begins.
509 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
510 @subsection Status Delivery Architecture
512 The buildmaster maintains a central Status object, to which various
513 status plugins are connected. Through this Status object, a full
514 hierarchy of build status objects can be obtained.
516 @image{images/status,,,Status Delivery,}
518 The configuration file controls which status plugins are active. Each
519 status plugin gets a reference to the top-level Status object. From
520 there they can request information on each Builder, Build, Step, and
521 LogFile. This query-on-demand interface is used by the html.Waterfall
522 plugin to create the main status page each time a web browser hits the
523 main URL.
525 The status plugins can also subscribe to hear about new Builds as they
526 occur: this is used by the MailNotifier to create new email messages
527 for each recently-completed Build.
529 The Status object records the status of old builds on disk in the
530 buildmaster's base directory. This allows it to return information
531 about historical builds.
533 There are also status objects that correspond to Schedulers and
534 BuildSlaves. These allow status plugins to report information about
535 upcoming builds, and the online/offline status of each buildslave.
538 @node Control Flow,  , System Architecture, Introduction
539 @comment  node-name,  next,  previous,  up
540 @section Control Flow
542 A day in the life of the buildbot:
544 @itemize @bullet
546 @item
547 A developer commits some source code changes to the repository. A hook
548 script or commit trigger of some sort sends information about this
549 change to the buildmaster through one of its configured Change
550 Sources. This notification might arrive via email, or over a network
551 connection (either initiated by the buildmaster as it ``subscribes''
552 to changes, or by the commit trigger as it pushes Changes towards the
553 buildmaster). The Change contains information about who made the
554 change, what files were modified, which revision contains the change,
555 and any checkin comments.
557 @item
558 The buildmaster distributes this change to all of its configured
559 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
560 to be started, and the Change is added to a list of those that will go
561 into a new Build. When the timer expires, a Build is started on each
562 of a set of configured Builders, all compiling/testing the same source
563 code. Unless configured otherwise, all Builds run in parallel on the
564 various buildslaves.
566 @item
567 The Build consists of a series of Steps. Each Step causes some number
568 of commands to be invoked on the remote buildslave associated with
569 that Builder. The first step is almost always to perform a checkout of
570 the appropriate revision from the same VC system that produced the
571 Change. The rest generally perform a compile and run unit tests. As
572 each Step runs, the buildslave reports back command output and return
573 status to the buildmaster.
575 @item
576 As the Build runs, status messages like ``Build Started'', ``Step
577 Started'', ``Build Finished'', etc, are published to a collection of
578 Status Targets. One of these targets is usually the HTML ``Waterfall''
579 display, which shows a chronological list of events, and summarizes
580 the results of the most recent build at the top of each column.
581 Developers can periodically check this page to see how their changes
582 have fared. If they see red, they know that they've made a mistake and
583 need to fix it. If they see green, they know that they've done their
584 duty and don't need to worry about their change breaking anything.
586 @item
587 If a MailNotifier status target is active, the completion of a build
588 will cause email to be sent to any developers whose Changes were
589 incorporated into this Build. The MailNotifier can be configured to
590 only send mail upon failing builds, or for builds which have just
591 transitioned from passing to failing. Other status targets can provide
592 similar real-time notification via different communication channels,
593 like IRC.
595 @end itemize
598 @node Installation, Concepts, Introduction, Top
599 @chapter Installation
601 @menu
602 * Requirements::                
603 * Installing the code::         
604 * Creating a buildmaster::      
605 * Upgrading an Existing Buildmaster::  
606 * Creating a buildslave::       
607 * Launching the daemons::       
608 * Logfiles::                    
609 * Shutdown::                    
610 * Maintenance::                 
611 * Troubleshooting::             
612 @end menu
614 @node Requirements, Installing the code, Installation, Installation
615 @section Requirements
617 At a bare minimum, you'll need the following (for both the buildmaster
618 and a buildslave):
620 @itemize @bullet
621 @item
622 Python: http://www.python.org
624 Buildbot requires python-2.3 or later, and is primarily developed
625 against python-2.4. It is also tested against python-2.5 .
627 @item
628 Twisted: http://twistedmatrix.com
630 Both the buildmaster and the buildslaves require Twisted-2.0.x or
631 later. It has been tested against all releases of Twisted up to
632 Twisted-2.5.0 (the most recent as of this writing). As always, the
633 most recent version is recommended.
635 Twisted is delivered as a collection of subpackages. You'll need at
636 least "Twisted" (the core package), and you'll also want TwistedMail,
637 TwistedWeb, and TwistedWords (for sending email, serving a web status
638 page, and delivering build status via IRC, respectively). You might
639 also want TwistedConch (for the encrypted Manhole debug port). Note
640 that Twisted requires ZopeInterface to be installed as well.
642 @end itemize
644 Certain other packages may be useful on the system running the
645 buildmaster:
647 @itemize @bullet
648 @item
649 CVSToys: http://purl.net/net/CVSToys
651 If your buildmaster uses FreshCVSSource to receive change notification
652 from a cvstoys daemon, it will require CVSToys be installed (tested
653 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
654 only use a mail-parsing change source, or the SVN notification
655 script), you will not need CVSToys.
657 @end itemize
659 And of course, your project's build process will impose additional
660 requirements on the buildslaves. These hosts must have all the tools
661 necessary to compile and test your project's source code.
664 @node Installing the code, Creating a buildmaster, Requirements, Installation
665 @section Installing the code
667 @cindex installation
669 The Buildbot is installed using the standard python @code{distutils}
670 module. After unpacking the tarball, the process is:
672 @example
673 python setup.py build
674 python setup.py install
675 @end example
677 where the install step may need to be done as root. This will put the
678 bulk of the code in somewhere like
679 /usr/lib/python2.3/site-packages/buildbot . It will also install the
680 @code{buildbot} command-line tool in /usr/bin/buildbot.
682 To test this, shift to a different directory (like /tmp), and run:
684 @example
685 buildbot --version
686 @end example
688 If it shows you the versions of Buildbot and Twisted, the install went
689 ok. If it says @code{no such command} or it gets an @code{ImportError}
690 when it tries to load the libaries, then something went wrong.
691 @code{pydoc buildbot} is another useful diagnostic tool.
693 Windows users will find these files in other places. You will need to
694 make sure that python can find the libraries, and will probably find
695 it convenient to have @code{buildbot} on your PATH.
697 If you wish, you can run the buildbot unit test suite like this:
699 @example
700 PYTHONPATH=. trial buildbot.test
701 @end example
703 This should run up to 192 tests, depending upon what VC tools you have
704 installed. On my desktop machine it takes about five minutes to
705 complete. Nothing should fail, a few might be skipped. If any of the
706 tests fail, you should stop and investigate the cause before
707 continuing the installation process, as it will probably be easier to
708 track down the bug early.
710 If you cannot or do not wish to install the buildbot into a site-wide
711 location like @file{/usr} or @file{/usr/local}, you can also install
712 it into the account's home directory. Do the install command like
713 this:
715 @example
716 python setup.py install --home=~
717 @end example
719 That will populate @file{~/lib/python} and create
720 @file{~/bin/buildbot}. Make sure this lib directory is on your
721 @code{PYTHONPATH}.
724 @node Creating a buildmaster, Upgrading an Existing Buildmaster, Installing the code, Installation
725 @section Creating a buildmaster
727 As you learned earlier (@pxref{System Architecture}), the buildmaster
728 runs on a central host (usually one that is publically visible, so
729 everybody can check on the status of the project), and controls all
730 aspects of the buildbot system. Let us call this host
731 @code{buildbot.example.org}.
733 You may wish to create a separate user account for the buildmaster,
734 perhaps named @code{buildmaster}. This can help keep your personal
735 configuration distinct from that of the buildmaster and is useful if
736 you have to use a mail-based notification system (@pxref{Change
737 Sources}). However, the Buildbot will work just fine with your regular
738 user account.
740 You need to choose a directory for the buildmaster, called the
741 @code{basedir}. This directory will be owned by the buildmaster, which
742 will use configuration files therein, and create status files as it
743 runs. @file{~/Buildbot} is a likely value. If you run multiple
744 buildmasters in the same account, or if you run both masters and
745 slaves, you may want a more distinctive name like
746 @file{~/Buildbot/master/gnomovision} or
747 @file{~/Buildmasters/fooproject}. If you are using a separate user
748 account, this might just be @file{~buildmaster/masters/fooproject}.
750 Once you've picked a directory, use the @command{buildbot
751 create-master} command to create the directory and populate it with
752 startup files:
754 @example
755 buildbot create-master @var{basedir}
756 @end example
758 You will need to create a configuration file (@pxref{Configuration})
759 before starting the buildmaster. Most of the rest of this manual is
760 dedicated to explaining how to do this. A sample configuration file is
761 placed in the working directory, named @file{master.cfg.sample}, which
762 can be copied to @file{master.cfg} and edited to suit your purposes.
764 (Internal details: This command creates a file named
765 @file{buildbot.tac} that contains all the state necessary to create
766 the buildmaster. Twisted has a tool called @code{twistd} which can use
767 this .tac file to create and launch a buildmaster instance. twistd
768 takes care of logging and daemonization (running the program in the
769 background). @file{/usr/bin/buildbot} is a front end which runs twistd
770 for you.)
772 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
773 installed. This can be used as the basis for customized daemon startup,
774 @xref{Launching the daemons}.
776 @node Upgrading an Existing Buildmaster, Creating a buildslave, Creating a buildmaster, Installation
777 @section Upgrading an Existing Buildmaster
779 If you have just installed a new version of the Buildbot code, and you
780 have buildmasters that were created using an older version, you'll
781 need to upgrade these buildmasters before you can use them. The
782 upgrade process adds and modifies files in the buildmaster's base
783 directory to make it compatible with the new code.
785 @example
786 buildbot upgrade-master @var{basedir}
787 @end example
789 This command will also scan your @file{master.cfg} file for
790 incompatbilities (by loading it and printing any errors or deprecation
791 warnings that occur). Each buildbot release tries to be compatible
792 with configurations that worked cleanly (i.e. without deprecation
793 warnings) on the previous release: any functions or classes that are
794 to be removed will first be deprecated in a release, to give users a
795 chance to start using their replacement.
797 The 0.7.6 release introduced the @file{public_html/} directory, which
798 contains @file{index.html} and other files served by the
799 @code{WebStatus} and @code{Waterfall} status displays. The
800 @code{upgrade-master} command will create these files if they do not
801 already exist. It will not modify existing copies, but it will write a
802 new copy in e.g. @file{index.html.new} if the new version differs from
803 the version that already exists.
805 The @code{upgrade-master} command is idempotent. It is safe to run it
806 multiple times. After each upgrade of the buildbot code, you should
807 use @code{upgrade-master} on all your buildmasters.
810 @node Creating a buildslave, Launching the daemons, Upgrading an Existing Buildmaster, Installation
811 @section Creating a buildslave
813 Typically, you will be adding a buildslave to an existing buildmaster,
814 to provide additional architecture coverage. The buildbot
815 administrator will give you several pieces of information necessary to
816 connect to the buildmaster. You should also be somewhat familiar with
817 the project being tested, so you can troubleshoot build problems
818 locally.
820 The buildbot exists to make sure that the project's stated ``how to
821 build it'' process actually works. To this end, the buildslave should
822 run in an environment just like that of your regular developers.
823 Typically the project build process is documented somewhere
824 (@file{README}, @file{INSTALL}, etc), in a document that should
825 mention all library dependencies and contain a basic set of build
826 instructions. This document will be useful as you configure the host
827 and account in which the buildslave runs.
829 Here's a good checklist for setting up a buildslave:
831 @enumerate
832 @item
833 Set up the account
835 It is recommended (although not mandatory) to set up a separate user
836 account for the buildslave. This account is frequently named
837 @code{buildbot} or @code{buildslave}. This serves to isolate your
838 personal working environment from that of the slave's, and helps to
839 minimize the security threat posed by letting possibly-unknown
840 contributors run arbitrary code on your system. The account should
841 have a minimum of fancy init scripts.
843 @item
844 Install the buildbot code
846 Follow the instructions given earlier (@pxref{Installing the code}).
847 If you use a separate buildslave account, and you didn't install the
848 buildbot code to a shared location, then you will need to install it
849 with @code{--home=~} for each account that needs it.
851 @item
852 Set up the host
854 Make sure the host can actually reach the buildmaster. Usually the
855 buildmaster is running a status webserver on the same machine, so
856 simply point your web browser at it and see if you can get there.
857 Install whatever additional packages or libraries the project's
858 INSTALL document advises. (or not: if your buildslave is supposed to
859 make sure that building without optional libraries still works, then
860 don't install those libraries).
862 Again, these libraries don't necessarily have to be installed to a
863 site-wide shared location, but they must be available to your build
864 process. Accomplishing this is usually very specific to the build
865 process, so installing them to @file{/usr} or @file{/usr/local} is
866 usually the best approach.
868 @item
869 Test the build process
871 Follow the instructions in the INSTALL document, in the buildslave's
872 account. Perform a full CVS (or whatever) checkout, configure, make,
873 run tests, etc. Confirm that the build works without manual fussing.
874 If it doesn't work when you do it by hand, it will be unlikely to work
875 when the buildbot attempts to do it in an automated fashion.
877 @item
878 Choose a base directory
880 This should be somewhere in the buildslave's account, typically named
881 after the project which is being tested. The buildslave will not touch
882 any file outside of this directory. Something like @file{~/Buildbot}
883 or @file{~/Buildslaves/fooproject} is appropriate.
885 @item
886 Get the buildmaster host/port, botname, and password
888 When the buildbot admin configures the buildmaster to accept and use
889 your buildslave, they will provide you with the following pieces of
890 information:
892 @itemize @bullet
893 @item
894 your buildslave's name
895 @item
896 the password assigned to your buildslave
897 @item
898 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
899 @end itemize
901 @item
902 Create the buildslave
904 Now run the 'buildbot' command as follows:
906 @example
907 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
908 @end example
910 This will create the base directory and a collection of files inside,
911 including the @file{buildbot.tac} file that contains all the
912 information you passed to the @code{buildbot} command.
914 @item
915 Fill in the hostinfo files
917 When it first connects, the buildslave will send a few files up to the
918 buildmaster which describe the host that it is running on. These files
919 are presented on the web status display so that developers have more
920 information to reproduce any test failures that are witnessed by the
921 buildbot. There are sample files in the @file{info} subdirectory of
922 the buildbot's base directory. You should edit these to correctly
923 describe you and your host.
925 @file{BASEDIR/info/admin} should contain your name and email address.
926 This is the ``buildslave admin address'', and will be visible from the
927 build status page (so you may wish to munge it a bit if
928 address-harvesting spambots are a concern).
930 @file{BASEDIR/info/host} should be filled with a brief description of
931 the host: OS, version, memory size, CPU speed, versions of relevant
932 libraries installed, and finally the version of the buildbot code
933 which is running the buildslave.
935 If you run many buildslaves, you may want to create a single
936 @file{~buildslave/info} file and share it among all the buildslaves
937 with symlinks.
939 @end enumerate
941 @menu
942 * Buildslave Options::          
943 @end menu
945 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
946 @subsection Buildslave Options
948 There are a handful of options you might want to use when creating the
949 buildslave with the @command{buildbot create-slave <options> DIR <params>}
950 command. You can type @command{buildbot create-slave --help} for a summary.
951 To use these, just include them on the @command{buildbot create-slave}
952 command line, like this:
954 @example
955 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
956 @end example
958 @table @code
959 @item --usepty
960 This is a boolean flag that tells the buildslave whether to launch
961 child processes in a PTY (the default) or with regular pipes. The
962 advantage of using a PTY is that ``grandchild'' processes are more
963 likely to be cleaned up if the build is interrupted or times out
964 (since it enables the use of a ``process group'' in which all child
965 processes will be placed). The disadvantages: some forms of Unix have
966 problems with PTYs, some of your unit tests may behave differently
967 when run under a PTY (generally those which check to see if they are
968 being run interactively), and PTYs will merge the stdout and stderr
969 streams into a single output stream (which means the red-vs-black
970 coloring in the logfiles will be lost). If you encounter problems, you
971 can add @code{--usepty=0} to disable the use of PTYs. Note that
972 windows buildslaves never use PTYs.
974 @item --umask
975 This is a string (generally an octal representation of an integer)
976 which will cause the buildslave process' ``umask'' value to be set
977 shortly after initialization. The ``twistd'' daemonization utility
978 forces the umask to 077 at startup (which means that all files created
979 by the buildslave or its child processes will be unreadable by any
980 user other than the buildslave account). If you want build products to
981 be readable by other accounts, you can add @code{--umask=022} to tell
982 the buildslave to fix the umask after twistd clobbers it. If you want
983 build products to be @emph{writable} by other accounts too, use
984 @code{--umask=000}, but this is likely to be a security problem.
986 @item --keepalive
987 This is a number that indicates how frequently ``keepalive'' messages
988 should be sent from the buildslave to the buildmaster, expressed in
989 seconds. The default (600) causes a message to be sent to the
990 buildmaster at least once every 10 minutes. To set this to a lower
991 value, use e.g. @code{--keepalive=120}.
993 If the buildslave is behind a NAT box or stateful firewall, these
994 messages may help to keep the connection alive: some NAT boxes tend to
995 forget about a connection if it has not been used in a while. When
996 this happens, the buildmaster will think that the buildslave has
997 disappeared, and builds will time out. Meanwhile the buildslave will
998 not realize than anything is wrong.
1000 @end table
1003 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
1004 @section Launching the daemons
1006 Both the buildmaster and the buildslave run as daemon programs. To
1007 launch them, pass the working directory to the @code{buildbot}
1008 command:
1010 @example
1011 buildbot start @var{BASEDIR}
1012 @end example
1014 This command will start the daemon and then return, so normally it
1015 will not produce any output. To verify that the programs are indeed
1016 running, look for a pair of files named @file{twistd.log} and
1017 @file{twistd.pid} that should be created in the working directory.
1018 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
1020 When the buildslave connects to the buildmaster, new directories will
1021 start appearing in its base directory. The buildmaster tells the slave
1022 to create a directory for each Builder which will be using that slave.
1023 All build operations are performed within these directories: CVS
1024 checkouts, compiles, and tests.
1026 Once you get everything running, you will want to arrange for the
1027 buildbot daemons to be started at boot time. One way is to use
1028 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
1029 @@reboot syntax is understood by Vixie cron, which is the flavor
1030 usually provided with linux systems. Other unices may have a cron that
1031 doesn't understand @@reboot}:
1033 @example
1034 @@reboot buildbot start @var{BASEDIR}
1035 @end example
1037 When you run @command{crontab} to set this up, remember to do it as
1038 the buildmaster or buildslave account! If you add this to your crontab
1039 when running as your regular account (or worse yet, root), then the
1040 daemon will run as the wrong user, quite possibly as one with more
1041 authority than you intended to provide.
1043 It is important to remember that the environment provided to cron jobs
1044 and init scripts can be quite different that your normal runtime.
1045 There may be fewer environment variables specified, and the PATH may
1046 be shorter than usual. It is a good idea to test out this method of
1047 launching the buildslave by using a cron job with a time in the near
1048 future, with the same command, and then check @file{twistd.log} to
1049 make sure the slave actually started correctly. Common problems here
1050 are for @file{/usr/local} or @file{~/bin} to not be on your
1051 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
1052 Sometimes @code{HOME} is messed up too.
1054 To modify the way the daemons are started (perhaps you want to set
1055 some environment variables first, or perform some cleanup each time),
1056 you can create a file named @file{Makefile.buildbot} in the base
1057 directory. When the @file{buildbot} front-end tool is told to
1058 @command{start} the daemon, and it sees this file (and
1059 @file{/usr/bin/make} exists), it will do @command{make -f
1060 Makefile.buildbot start} instead of its usual action (which involves
1061 running @command{twistd}). When the buildmaster or buildslave is
1062 installed, a @file{Makefile.sample} is created which implements the
1063 same behavior as the the @file{buildbot} tool uses, so if you want to
1064 customize the process, just copy @file{Makefile.sample} to
1065 @file{Makefile.buildbot} and edit it as necessary.
1067 @node Logfiles, Shutdown, Launching the daemons, Installation
1068 @section Logfiles
1070 @cindex logfiles
1072 While a buildbot daemon runs, it emits text to a logfile, named
1073 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1074 to watch the command output as it runs.
1076 The buildmaster will announce any errors with its configuration file
1077 in the logfile, so it is a good idea to look at the log at startup
1078 time to check for any problems. Most buildmaster activities will cause
1079 lines to be added to the log.
1081 @node Shutdown, Maintenance, Logfiles, Installation
1082 @section Shutdown
1084 To stop a buildmaster or buildslave manually, use:
1086 @example
1087 buildbot stop @var{BASEDIR}
1088 @end example
1090 This simply looks for the @file{twistd.pid} file and kills whatever
1091 process is identified within.
1093 At system shutdown, all processes are sent a @code{SIGKILL}. The
1094 buildmaster and buildslave will respond to this by shutting down
1095 normally.
1097 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1098 config file. The following shortcut is available:
1100 @example
1101 buildbot reconfig @var{BASEDIR}
1102 @end example
1104 When you update the Buildbot code to a new release, you will need to
1105 restart the buildmaster and/or buildslave before it can take advantage
1106 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1107 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1108 use the @code{restart} shortcut, which does both steps for you:
1110 @example
1111 buildbot restart @var{BASEDIR}
1112 @end example
1115 @node Maintenance, Troubleshooting, Shutdown, Installation
1116 @section Maintenance
1118 It is a good idea to check the buildmaster's status page every once in
1119 a while, to see if your buildslave is still online. Eventually the
1120 buildbot will probably be enhanced to send you email (via the
1121 @file{info/admin} email address) when the slave has been offline for
1122 more than a few hours.
1124 If you find you can no longer provide a buildslave to the project, please
1125 let the project admins know, so they can put out a call for a
1126 replacement.
1128 The Buildbot records status and logs output continually, each time a
1129 build is performed. The status tends to be small, but the build logs
1130 can become quite large. Each build and log are recorded in a separate
1131 file, arranged hierarchically under the buildmaster's base directory.
1132 To prevent these files from growing without bound, you should
1133 periodically delete old build logs. A simple cron job to delete
1134 anything older than, say, two weeks should do the job. The only trick
1135 is to leave the @file{buildbot.tac} and other support files alone, for
1136 which find's @code{-mindepth} argument helps skip everything in the
1137 top directory. You can use something like the following:
1139 @example
1140 @@weekly cd BASEDIR && find . -mindepth 2 -type f -mtime +14 -exec rm @{@} \;
1141 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1142 @end example
1144 @node Troubleshooting,  , Maintenance, Installation
1145 @section Troubleshooting
1147 Here are a few hints on diagnosing common problems.
1149 @menu
1150 * Starting the buildslave::     
1151 * Connecting to the buildmaster::  
1152 * Forcing Builds::              
1153 @end menu
1155 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1156 @subsection Starting the buildslave
1158 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1159 @file{/bin/bash}), and tilde expansion is not always performed in such
1160 commands. You may want to use explicit paths, because the @code{PATH}
1161 is usually quite short and doesn't include anything set by your
1162 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1163 you've installed buildbot (or other python libraries) to an unusual
1164 location, you may need to add a @code{PYTHONPATH} specification (note
1165 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1166 itself). Sometimes it is safer to fully-specify everything:
1168 @example
1169 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1170 @end example
1172 Take the time to get the @@reboot job set up. Otherwise, things will work
1173 fine for a while, but the first power outage or system reboot you have will
1174 stop the buildslave with nothing but the cries of sorrowful developers to
1175 remind you that it has gone away.
1177 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1178 @subsection Connecting to the buildmaster
1180 If the buildslave cannot connect to the buildmaster, the reason should
1181 be described in the @file{twistd.log} logfile. Some common problems
1182 are an incorrect master hostname or port number, or a mistyped bot
1183 name or password. If the buildslave loses the connection to the
1184 master, it is supposed to attempt to reconnect with an
1185 exponentially-increasing backoff. Each attempt (and the time of the
1186 next attempt) will be logged. If you get impatient, just manually stop
1187 and re-start the buildslave.
1189 When the buildmaster is restarted, all slaves will be disconnected,
1190 and will attempt to reconnect as usual. The reconnect time will depend
1191 upon how long the buildmaster is offline (i.e. how far up the
1192 exponential backoff curve the slaves have travelled). Again,
1193 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1194 speed up the process.
1196 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1197 @subsection Forcing Builds
1199 From the buildmaster's main status web page, you can force a build to
1200 be run on your build slave. Figure out which column is for a builder
1201 that runs on your slave, click on that builder's name, and the page
1202 that comes up will have a ``Force Build'' button. Fill in the form,
1203 hit the button, and a moment later you should see your slave's
1204 @file{twistd.log} filling with commands being run. Using @code{pstree}
1205 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1206 run by the buildslave. Note that the same web page should also show
1207 the @file{admin} and @file{host} information files that you configured
1208 earlier.
1210 @node Concepts, Configuration, Installation, Top
1211 @chapter Concepts
1213 This chapter defines some of the basic concepts that the Buildbot
1214 uses. You'll need to understand how the Buildbot sees the world to
1215 configure it properly.
1217 @menu
1218 * Version Control Systems::     
1219 * Schedulers::                  
1220 * BuildSet::                    
1221 * BuildRequest::                
1222 * Builder::                     
1223 * Users::                       
1224 @end menu
1226 @node Version Control Systems, Schedulers, Concepts, Concepts
1227 @section Version Control Systems
1229 @cindex Version Control
1231 These source trees come from a Version Control System of some kind.
1232 CVS and Subversion are two popular ones, but the Buildbot supports
1233 others. All VC systems have some notion of an upstream
1234 @code{repository} which acts as a server@footnote{except Darcs, but
1235 since the Buildbot never modifies its local source tree we can ignore
1236 the fact that Darcs uses a less centralized model}, from which clients
1237 can obtain source trees according to various parameters. The VC
1238 repository provides source trees of various projects, for different
1239 branches, and from various points in time. The first thing we have to
1240 do is to specify which source tree we want to get.
1242 @menu
1243 * Generalizing VC Systems::     
1244 * Source Tree Specifications::  
1245 * How Different VC Systems Specify Sources::  
1246 * Attributes of Changes::       
1247 @end menu
1249 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1250 @subsection Generalizing VC Systems
1252 For the purposes of the Buildbot, we will try to generalize all VC
1253 systems as having repositories that each provide sources for a variety
1254 of projects. Each project is defined as a directory tree with source
1255 files. The individual files may each have revisions, but we ignore
1256 that and treat the project as a whole as having a set of revisions
1257 (CVS is really the only VC system still in widespread use that has
1258 per-file revisions.. everything modern has moved to atomic tree-wide
1259 changesets). Each time someone commits a change to the project, a new
1260 revision becomes available. These revisions can be described by a
1261 tuple with two items: the first is a branch tag, and the second is
1262 some kind of revision stamp or timestamp. Complex projects may have
1263 multiple branch tags, but there is always a default branch. The
1264 timestamp may be an actual timestamp (such as the -D option to CVS),
1265 or it may be a monotonically-increasing transaction number (such as
1266 the change number used by SVN and P4, or the revision number used by
1267 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1268 systems provide more complexity than this: in particular the local
1269 views that P4 and ClearCase can assemble out of various source
1270 directories are more complex than we're prepared to take advantage of
1271 here}. The SHA1 revision ID used by Monotone and Mercurial is also a
1272 kind of revision stamp, in that it specifies a unique copy of the
1273 source tree, as does a Darcs ``context'' file.
1275 When we aren't intending to make any changes to the sources we check out
1276 (at least not any that need to be committed back upstream), there are two
1277 basic ways to use a VC system:
1279 @itemize @bullet
1280 @item
1281 Retrieve a specific set of source revisions: some tag or key is used
1282 to index this set, which is fixed and cannot be changed by subsequent
1283 developers committing new changes to the tree. Releases are built from
1284 tagged revisions like this, so that they can be rebuilt again later
1285 (probably with controlled modifications).
1286 @item
1287 Retrieve the latest sources along a specific branch: some tag is used
1288 to indicate which branch is to be used, but within that constraint we want
1289 to get the latest revisions.
1290 @end itemize
1292 Build personnel or CM staff typically use the first approach: the
1293 build that results is (ideally) completely specified by the two
1294 parameters given to the VC system: repository and revision tag. This
1295 gives QA and end-users something concrete to point at when reporting
1296 bugs. Release engineers are also reportedly fond of shipping code that
1297 can be traced back to a concise revision tag of some sort.
1299 Developers are more likely to use the second approach: each morning
1300 the developer does an update to pull in the changes committed by the
1301 team over the last day. These builds are not easy to fully specify: it
1302 depends upon exactly when you did a checkout, and upon what local
1303 changes the developer has in their tree. Developers do not normally
1304 tag each build they produce, because there is usually significant
1305 overhead involved in creating these tags. Recreating the trees used by
1306 one of these builds can be a challenge. Some VC systems may provide
1307 implicit tags (like a revision number), while others may allow the use
1308 of timestamps to mean ``the state of the tree at time X'' as opposed
1309 to a tree-state that has been explicitly marked.
1311 The Buildbot is designed to help developers, so it usually works in
1312 terms of @emph{the latest} sources as opposed to specific tagged
1313 revisions. However, it would really prefer to build from reproducible
1314 source trees, so implicit revisions are used whenever possible.
1316 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1317 @subsection Source Tree Specifications
1319 So for the Buildbot's purposes we treat each VC system as a server
1320 which can take a list of specifications as input and produce a source
1321 tree as output. Some of these specifications are static: they are
1322 attributes of the builder and do not change over time. Others are more
1323 variable: each build will have a different value. The repository is
1324 changed over time by a sequence of Changes, each of which represents a
1325 single developer making changes to some set of files. These Changes
1326 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1327 violates this assumption of cumulative Changes, but in most situations
1328 the changes don't occur frequently enough for this to be a significant
1329 problem}.
1331 For normal builds, the Buildbot wants to get well-defined source trees
1332 that contain specific Changes, and exclude other Changes that may have
1333 occurred after the desired ones. We assume that the Changes arrive at
1334 the buildbot (through one of the mechanisms described in @pxref{Change
1335 Sources}) in the same order in which they are committed to the
1336 repository. The Buildbot waits for the tree to become ``stable''
1337 before initiating a build, for two reasons. The first is that
1338 developers frequently make multiple related commits in quick
1339 succession, even when the VC system provides ways to make atomic
1340 transactions involving multiple files at the same time. Running a
1341 build in the middle of these sets of changes would use an inconsistent
1342 set of source files, and is likely to fail (and is certain to be less
1343 useful than a build which uses the full set of changes). The
1344 tree-stable-timer is intended to avoid these useless builds that
1345 include some of the developer's changes but not all. The second reason
1346 is that some VC systems (i.e. CVS) do not provide repository-wide
1347 transaction numbers, so that timestamps are the only way to refer to
1348 a specific repository state. These timestamps may be somewhat
1349 ambiguous, due to processing and notification delays. By waiting until
1350 the tree has been stable for, say, 10 minutes, we can choose a
1351 timestamp from the middle of that period to use for our source
1352 checkout, and then be reasonably sure that any clock-skew errors will
1353 not cause the build to be performed on an inconsistent set of source
1354 files.
1356 The Schedulers always use the tree-stable-timer, with a timeout that
1357 is configured to reflect a reasonable tradeoff between build latency
1358 and change frequency. When the VC system provides coherent
1359 repository-wide revision markers (such as Subversion's revision
1360 numbers, or in fact anything other than CVS's timestamps), the
1361 resulting Build is simply performed against a source tree defined by
1362 that revision marker. When the VC system does not provide this, a
1363 timestamp from the middle of the tree-stable period is used to
1364 generate the source tree@footnote{this @code{checkoutDelay} defaults
1365 to half the tree-stable timer, but it can be overridden with an
1366 argument to the Source Step}.
1368 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1369 @subsection How Different VC Systems Specify Sources
1371 For CVS, the static specifications are @code{repository} and
1372 @code{module}. In addition to those, each build uses a timestamp (or
1373 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1374 (which defaults to HEAD). These parameters collectively specify a set
1375 of sources from which a build may be performed.
1377 @uref{http://subversion.tigris.org, Subversion} combines the
1378 repository, module, and branch into a single @code{Subversion URL}
1379 parameter. Within that scope, source checkouts can be specified by a
1380 numeric @code{revision number} (a repository-wide
1381 monotonically-increasing marker, such that each transaction that
1382 changes the repository is indexed by a different revision number), or
1383 a revision timestamp. When branches are used, the repository and
1384 module form a static @code{baseURL}, while each build has a
1385 @code{revision number} and a @code{branch} (which defaults to a
1386 statically-specified @code{defaultBranch}). The @code{baseURL} and
1387 @code{branch} are simply concatenated together to derive the
1388 @code{svnurl} to use for the checkout.
1390 @uref{http://www.perforce.com/, Perforce} is similar. The server
1391 is specified through a @code{P4PORT} parameter. Module and branch
1392 are specified in a single depot path, and revisions are
1393 depot-wide. When branches are used, the @code{p4base} and
1394 @code{defaultBranch} are concatenated together to produce the depot
1395 path.
1397 @uref{http://wiki.gnuarch.org/, Arch} and
1398 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1399 URL, as well as a @code{version} which is kind of like a branch name.
1400 Arch uses the word @code{archive} to represent the repository. Arch
1401 lets you push changes from one archive to another, removing the strict
1402 centralization required by CVS and SVN. It retains the distinction
1403 between repository and working directory that most other VC systems
1404 use. For complex multi-module directory structures, Arch has a
1405 built-in @code{build config} layer with which the checkout process has
1406 two steps. First, an initial bootstrap checkout is performed to
1407 retrieve a set of build-config files. Second, one of these files is
1408 used to figure out which archives/modules should be used to populate
1409 subdirectories of the initial checkout.
1411 Builders which use Arch and Bazaar therefore have a static archive
1412 @code{url}, and a default ``branch'' (which is a string that specifies
1413 a complete category--branch--version triple). Each build can have its
1414 own branch (the category--branch--version string) to override the
1415 default, as well as a revision number (which is turned into a
1416 --patch-NN suffix when performing the checkout).
1419 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1420 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1421 sort of repository-vs-workspace model as Arch, but the repository data
1422 can either be stored inside the working directory or kept elsewhere
1423 (either on the same machine or on an entirely different machine). For
1424 the purposes of Buildbot (which never commits changes), the repository
1425 is specified with a URL and a revision number.
1427 The most common way to obtain read-only access to a bzr tree is via
1428 HTTP, simply by making the repository visible through a web server
1429 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1430 process has sufficient privileges to access them. Higher performance
1431 can be obtained by running a special Bazaar-specific server. None of
1432 these matter to the buildbot: the repository URL just has to match the
1433 kind of server being used. The @code{repoURL} argument provides the
1434 location of the repository.
1436 Branches are expressed as subdirectories of the main central
1437 repository, which means that if branches are being used, the BZR step
1438 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1439 the @code{repoURL} argument.
1442 @uref{http://darcs.net/, Darcs} doesn't really have the
1443 notion of a single master repository. Nor does it really have
1444 branches. In Darcs, each working directory is also a repository, and
1445 there are operations to push and pull patches from one of these
1446 @code{repositories} to another. For the Buildbot's purposes, all you
1447 need to do is specify the URL of a repository that you want to build
1448 from. The build slave will then pull the latest patches from that
1449 repository and build them. Multiple branches are implemented by using
1450 multiple repositories (possibly living on the same server).
1452 Builders which use Darcs therefore have a static @code{repourl} which
1453 specifies the location of the repository. If branches are being used,
1454 the source Step is instead configured with a @code{baseURL} and a
1455 @code{defaultBranch}, and the two strings are simply concatenated
1456 together to obtain the repository's URL. Each build then has a
1457 specific branch which replaces @code{defaultBranch}, or just uses the
1458 default one. Instead of a revision number, each build can have a
1459 ``context'', which is a string that records all the patches that are
1460 present in a given tree (this is the output of @command{darcs changes
1461 --context}, and is considerably less concise than, e.g. Subversion's
1462 revision number, but the patch-reordering flexibility of Darcs makes
1463 it impossible to provide a shorter useful specification).
1465 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1466 each branch is stored in a separate repository. The @code{repourl},
1467 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1468 same way as with Darcs. The ``revision'', however, is the hash
1469 identifier returned by @command{hg identify}.
1472 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1473 @subsection Attributes of Changes
1475 @heading Who
1477 Each Change has a @code{who} attribute, which specifies which
1478 developer is responsible for the change. This is a string which comes
1479 from a namespace controlled by the VC repository. Frequently this
1480 means it is a username on the host which runs the repository, but not
1481 all VC systems require this (Arch, for example, uses a fully-qualified
1482 @code{Arch ID}, which looks like an email address, as does Darcs).
1483 Each StatusNotifier will map the @code{who} attribute into something
1484 appropriate for their particular means of communication: an email
1485 address, an IRC handle, etc.
1487 @heading Files
1489 It also has a list of @code{files}, which are just the tree-relative
1490 filenames of any files that were added, deleted, or modified for this
1491 Change. These filenames are used by the @code{isFileImportant}
1492 function (in the Scheduler) to decide whether it is worth triggering a
1493 new build or not, e.g. the function could use
1494 @code{filename.endswith(".c")} to only run a build if a C file were
1495 checked in. Certain BuildSteps can also use the list of changed files
1496 to run a more targeted series of tests, e.g. the
1497 @code{python_twisted.Trial} step can run just the unit tests that
1498 provide coverage for the modified .py files instead of running the
1499 full test suite.
1501 @heading Comments
1503 The Change also has a @code{comments} attribute, which is a string
1504 containing any checkin comments.
1506 @heading Revision
1508 Each Change can have a @code{revision} attribute, which describes how
1509 to get a tree with a specific state: a tree which includes this Change
1510 (and all that came before it) but none that come after it. If this
1511 information is unavailable, the @code{.revision} attribute will be
1512 @code{None}. These revisions are provided by the ChangeSource, and
1513 consumed by the @code{computeSourceRevision} method in the appropriate
1514 @code{step.Source} class.
1516 @table @samp
1517 @item CVS
1518 @code{revision} is an int, seconds since the epoch
1519 @item SVN
1520 @code{revision} is an int, a transation number (r%d)
1521 @item Darcs
1522 @code{revision} is a large string, the output of @code{darcs changes --context}
1523 @item Mercurial
1524 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1525 @item Arch/Bazaar
1526 @code{revision} is the full revision ID (ending in --patch-%d)
1527 @item P4
1528 @code{revision} is an int, the transaction number
1529 @end table
1531 @heading Branches
1533 The Change might also have a @code{branch} attribute. This indicates
1534 that all of the Change's files are in the same named branch. The
1535 Schedulers get to decide whether the branch should be built or not.
1537 For VC systems like CVS, Arch, and Monotone, the @code{branch} name is
1538 unrelated to the filename. (that is, the branch name and the filename
1539 inhabit unrelated namespaces). For SVN, branches are expressed as
1540 subdirectories of the repository, so the file's ``svnurl'' is a
1541 combination of some base URL, the branch name, and the filename within
1542 the branch. (In a sense, the branch name and the filename inhabit the
1543 same namespace). Darcs branches are subdirectories of a base URL just
1544 like SVN. Mercurial branches are the same as Darcs.
1546 @table @samp
1547 @item CVS
1548 branch='warner-newfeature', files=['src/foo.c']
1549 @item SVN
1550 branch='branches/warner-newfeature', files=['src/foo.c']
1551 @item Darcs
1552 branch='warner-newfeature', files=['src/foo.c']
1553 @item Mercurial
1554 branch='warner-newfeature', files=['src/foo.c']
1555 @item Arch/Bazaar
1556 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1557 @end table
1559 @heading Links
1561 @c TODO: who is using 'links'? how is it being used?
1563 Finally, the Change might have a @code{links} list, which is intended
1564 to provide a list of URLs to a @emph{viewcvs}-style web page that
1565 provides more detail for this Change, perhaps including the full file
1566 diffs.
1569 @node Schedulers, BuildSet, Version Control Systems, Concepts
1570 @section Schedulers
1572 @cindex Scheduler
1574 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1575 gets a copy of every incoming Change. The Schedulers are responsible
1576 for deciding when Builds should be run. Some Buildbot installations
1577 might have a single Scheduler, while others may have several, each for
1578 a different purpose.
1580 For example, a ``quick'' scheduler might exist to give immediate
1581 feedback to developers, hoping to catch obvious problems in the code
1582 that can be detected quickly. These typically do not run the full test
1583 suite, nor do they run on a wide variety of platforms. They also
1584 usually do a VC update rather than performing a brand-new checkout
1585 each time. You could have a ``quick'' scheduler which used a 30 second
1586 timeout, and feeds a single ``quick'' Builder that uses a VC
1587 @code{mode='update'} setting.
1589 A separate ``full'' scheduler would run more comprehensive tests a
1590 little while later, to catch more subtle problems. This scheduler
1591 would have a longer tree-stable-timer, maybe 30 minutes, and would
1592 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1593 @code{'clobber'}, or @code{'export'}).
1595 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1596 made by the Scheduler. Dependencies are also implemented here.
1597 Periodic builds (those which are run every N seconds rather than after
1598 new Changes arrive) are triggered by a special @code{Periodic}
1599 Scheduler subclass. The default Scheduler class can also be told to
1600 watch for specific branches, ignoring Changes on other branches. This
1601 may be useful if you have a trunk and a few release branches which
1602 should be tracked, but when you don't want to have the Buildbot pay
1603 attention to several dozen private user branches.
1605 Some Schedulers may trigger builds for other reasons, other than
1606 recent Changes. For example, a Scheduler subclass could connect to a
1607 remote buildmaster and watch for builds of a library to succeed before
1608 triggering a local build that uses that library.
1610 Each Scheduler creates and submits @code{BuildSet} objects to the
1611 @code{BuildMaster}, which is then responsible for making sure the
1612 individual @code{BuildRequests} are delivered to the target
1613 @code{Builders}.
1615 @code{Scheduler} instances are activated by placing them in the
1616 @code{c['schedulers']} list in the buildmaster config file. Each
1617 Scheduler has a unique name.
1620 @node BuildSet, BuildRequest, Schedulers, Concepts
1621 @section BuildSet
1623 @cindex BuildSet
1625 A @code{BuildSet} is the name given to a set of Builds that all
1626 compile/test the same version of the tree on multiple Builders. In
1627 general, all these component Builds will perform the same sequence of
1628 Steps, using the same source code, but on different platforms or
1629 against a different set of libraries.
1631 The @code{BuildSet} is tracked as a single unit, which fails if any of
1632 the component Builds have failed, and therefore can succeed only if
1633 @emph{all} of the component Builds have succeeded. There are two kinds
1634 of status notification messages that can be emitted for a BuildSet:
1635 the @code{firstFailure} type (which fires as soon as we know the
1636 BuildSet will fail), and the @code{Finished} type (which fires once
1637 the BuildSet has completely finished, regardless of whether the
1638 overall set passed or failed).
1640 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1641 (branch, revision, changes, patch), some of which may be None, and a
1642 list of Builders on which it is to be run. They are then given to the
1643 BuildMaster, which is responsible for creating a separate
1644 @code{BuildRequest} for each Builder.
1646 There are a couple of different likely values for the
1647 @code{SourceStamp}:
1649 @table @code
1650 @item (revision=None, changes=[CHANGES], patch=None)
1651 This is a @code{SourceStamp} used when a series of Changes have
1652 triggered a build. The VC step will attempt to check out a tree that
1653 contains CHANGES (and any changes that occurred before CHANGES, but
1654 not any that occurred after them).
1656 @item (revision=None, changes=None, patch=None)
1657 This builds the most recent code on the default branch. This is the
1658 sort of @code{SourceStamp} that would be used on a Build that was
1659 triggered by a user request, or a Periodic scheduler. It is also
1660 possible to configure the VC Source Step to always check out the
1661 latest sources rather than paying attention to the Changes in the
1662 SourceStamp, which will result in same behavior as this.
1664 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1665 This builds the most recent code on the given BRANCH. Again, this is
1666 generally triggered by a user request or Periodic build.
1668 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1669 This checks out the tree at the given revision REV, then applies a
1670 patch (using @code{diff -pLEVEL <DIFF}). The @ref{try} feature uses
1671 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1672 step is bypassed.
1674 @end table
1676 The buildmaster is responsible for turning the @code{BuildSet} into a
1677 set of @code{BuildRequest} objects and queueing them on the
1678 appropriate Builders.
1681 @node BuildRequest, Builder, BuildSet, Concepts
1682 @section BuildRequest
1684 @cindex BuildRequest
1686 A @code{BuildRequest} is a request to build a specific set of sources
1687 on a single specific Builder. Each Builder runs the
1688 @code{BuildRequest} as soon as it can (i.e. when an associated
1689 buildslave becomes free).
1691 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1692 The actual process of running the build (the series of Steps that will
1693 be executed) is implemented by the @code{Build} object. In this future
1694 this might be changed, to have the @code{Build} define @emph{what}
1695 gets built, and a separate @code{BuildProcess} (provided by the
1696 Builder) to define @emph{how} it gets built.
1698 The @code{BuildRequest} may be mergeable with other compatible
1699 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1700 will generally be mergeable. Builds that are triggered by user
1701 requests are generally not, unless they are multiple requests to build
1702 the @emph{latest sources} of the same branch.
1704 @node Builder, Users, BuildRequest, Concepts
1705 @section Builder
1707 @cindex Builder
1709 The @code{Builder} is a long-lived object which controls all Builds of
1710 a given type. Each one is created when the config file is first
1711 parsed, and lives forever (or rather until it is removed from the
1712 config file). It mediates the connections to the buildslaves that do
1713 all the work, and is responsible for creating the @code{Build} objects
1714 that decide @emph{how} a build is performed (i.e., which steps are
1715 executed in what order).
1717 Each @code{Builder} gets a unique name, and the path name of a
1718 directory where it gets to do all its work (there is a
1719 buildmaster-side directory for keeping status information, as well as
1720 a buildslave-side directory where the actual checkout/compile/test
1721 commands are executed). It also gets a @code{BuildFactory}, which is
1722 responsible for creating new @code{Build} instances: because the
1723 @code{Build} instance is what actually performs each build, choosing
1724 the @code{BuildFactory} is the way to specify what happens each time a
1725 build is done.
1727 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1728 A @code{Builder} which is used to perform OS-X builds (as opposed to
1729 Linux or Solaris builds) should naturally be associated with an
1730 OS-X-based buildslave.
1733 @node Users,  , Builder, Concepts
1734 @section Users
1736 @cindex Users
1738 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1739 the world consists of a set of developers, each of whom can be
1740 described by a couple of simple attributes. These developers make
1741 changes to the source code, causing builds which may succeed or fail.
1743 Each developer is primarily known through the source control system. Each
1744 Change object that arrives is tagged with a @code{who} field that
1745 typically gives the account name (on the repository machine) of the user
1746 responsible for that change. This string is the primary key by which the
1747 User is known, and is displayed on the HTML status pages and in each Build's
1748 ``blamelist''.
1750 To do more with the User than just refer to them, this username needs to
1751 be mapped into an address of some sort. The responsibility for this mapping
1752 is left up to the status module which needs the address. The core code knows
1753 nothing about email addresses or IRC nicknames, just user names.
1755 @menu
1756 * Doing Things With Users::     
1757 * Email Addresses::             
1758 * IRC Nicknames::               
1759 * Live Status Clients::         
1760 @end menu
1762 @node Doing Things With Users, Email Addresses, Users, Users
1763 @subsection Doing Things With Users
1765 Each Change has a single User who is responsible for that Change. Most
1766 Builds have a set of Changes: the Build represents the first time these
1767 Changes have been built and tested by the Buildbot. The build has a
1768 ``blamelist'' that consists of a simple union of the Users responsible
1769 for all the Build's Changes.
1771 The Build provides (through the IBuildStatus interface) a list of Users
1772 who are ``involved'' in the build. For now this is equal to the
1773 blamelist, but in the future it will be expanded to include a ``build
1774 sheriff'' (a person who is ``on duty'' at that time and responsible for
1775 watching over all builds that occur during their shift), as well as
1776 per-module owners who simply want to keep watch over their domain (chosen by
1777 subdirectory or a regexp matched against the filenames pulled out of the
1778 Changes). The Involved Users are those who probably have an interest in the
1779 results of any given build.
1781 In the future, Buildbot will acquire the concept of ``Problems'',
1782 which last longer than builds and have beginnings and ends. For example, a
1783 test case which passed in one build and then failed in the next is a
1784 Problem. The Problem lasts until the test case starts passing again, at
1785 which point the Problem is said to be ``resolved''.
1787 If there appears to be a code change that went into the tree at the
1788 same time as the test started failing, that Change is marked as being
1789 resposible for the Problem, and the user who made the change is added
1790 to the Problem's ``Guilty'' list. In addition to this user, there may
1791 be others who share responsibility for the Problem (module owners,
1792 sponsoring developers). In addition to the Responsible Users, there
1793 may be a set of Interested Users, who take an interest in the fate of
1794 the Problem.
1796 Problems therefore have sets of Users who may want to be kept aware of
1797 the condition of the problem as it changes over time. If configured, the
1798 Buildbot can pester everyone on the Responsible list with increasing
1799 harshness until the problem is resolved, with the most harshness reserved
1800 for the Guilty parties themselves. The Interested Users may merely be told
1801 when the problem starts and stops, as they are not actually responsible for
1802 fixing anything.
1804 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1805 @subsection Email Addresses
1807 The @code{buildbot.status.mail.MailNotifier} class
1808 (@pxref{MailNotifier}) provides a status target which can send email
1809 about the results of each build. It accepts a static list of email
1810 addresses to which each message should be delivered, but it can also
1811 be configured to send mail to the Build's Interested Users. To do
1812 this, it needs a way to convert User names into email addresses.
1814 For many VC systems, the User Name is actually an account name on the
1815 system which hosts the repository. As such, turning the name into an
1816 email address is a simple matter of appending
1817 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1818 (for example the preferred email address may be at ``project.org''
1819 despite the repository host being named ``cvs.project.org''), and some
1820 VC systems have full separation between the concept of a user and that
1821 of an account on the repository host (like Perforce). Some systems
1822 (like Arch) put a full contact email address in every change.
1824 To convert these names to addresses, the MailNotifier uses an EmailLookup
1825 object. This provides a .getAddress method which accepts a name and
1826 (eventually) returns an address. The default @code{MailNotifier}
1827 module provides an EmailLookup which simply appends a static string,
1828 configurable when the notifier is created. To create more complex behaviors
1829 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1830 determine a preferred address for the developer), provide a different object
1831 as the @code{lookup} argument.
1833 In the future, when the Problem mechanism has been set up, the Buildbot
1834 will need to send mail to arbitrary Users. It will do this by locating a
1835 MailNotifier-like object among all the buildmaster's status targets, and
1836 asking it to send messages to various Users. This means the User-to-address
1837 mapping only has to be set up once, in your MailNotifier, and every email
1838 message the buildbot emits will take advantage of it.
1840 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1841 @subsection IRC Nicknames
1843 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1844 provides a status target which can announce the results of each build. It
1845 also provides an interactive interface by responding to online queries
1846 posted in the channel or sent as private messages.
1848 In the future, the buildbot can be configured map User names to IRC
1849 nicknames, to watch for the recent presence of these nicknames, and to
1850 deliver build status messages to the interested parties. Like
1851 @code{MailNotifier} does for email addresses, the @code{IRC} object
1852 will have an @code{IRCLookup} which is responsible for nicknames. The
1853 mapping can be set up statically, or it can be updated by online users
1854 themselves (by claiming a username with some kind of ``buildbot: i am
1855 user warner'' commands).
1857 Once the mapping is established, the rest of the buildbot can ask the
1858 @code{IRC} object to send messages to various users. It can report on
1859 the likelihood that the user saw the given message (based upon how long the
1860 user has been inactive on the channel), which might prompt the Problem
1861 Hassler logic to send them an email message instead.
1863 @node Live Status Clients,  , IRC Nicknames, Users
1864 @subsection Live Status Clients
1866 The Buildbot also offers a PB-based status client interface which can
1867 display real-time build status in a GUI panel on the developer's desktop.
1868 This interface is normally anonymous, but it could be configured to let the
1869 buildmaster know @emph{which} developer is using the status client. The
1870 status client could then be used as a message-delivery service, providing an
1871 alternative way to deliver low-latency high-interruption messages to the
1872 developer (like ``hey, you broke the build'').
1875 @node Configuration, Getting Source Code Changes, Concepts, Top
1876 @chapter Configuration
1878 @cindex Configuration
1880 The buildbot's behavior is defined by the ``config file'', which
1881 normally lives in the @file{master.cfg} file in the buildmaster's base
1882 directory (but this can be changed with an option to the
1883 @code{buildbot create-master} command). This file completely specifies
1884 which Builders are to be run, which slaves they should use, how
1885 Changes should be tracked, and where the status information is to be
1886 sent. The buildmaster's @file{buildbot.tac} file names the base
1887 directory; everything else comes from the config file.
1889 A sample config file was installed for you when you created the
1890 buildmaster, but you will need to edit it before your buildbot will do
1891 anything useful.
1893 This chapter gives an overview of the format of this file and the
1894 various sections in it. You will need to read the later chapters to
1895 understand how to fill in each section properly.
1897 @menu
1898 * Config File Format::          
1899 * Loading the Config File::     
1900 * Defining the Project::        
1901 * Listing Change Sources and Schedulers::  
1902 * Setting the slaveport::       
1903 * Buildslave Specifiers::       
1904 * Defining Builders::           
1905 * Defining Status Targets::     
1906 * Debug options::               
1907 @end menu
1909 @node Config File Format, Loading the Config File, Configuration, Configuration
1910 @section Config File Format
1912 The config file is, fundamentally, just a piece of Python code which
1913 defines a dictionary named @code{BuildmasterConfig}, with a number of
1914 keys that are treated specially. You don't need to know Python to do
1915 basic configuration, though, you can just copy the syntax of the
1916 sample file. If you @emph{are} comfortable writing Python code,
1917 however, you can use all the power of a full programming language to
1918 achieve more complicated configurations.
1920 The @code{BuildmasterConfig} name is the only one which matters: all
1921 other names defined during the execution of the file are discarded.
1922 When parsing the config file, the Buildmaster generally compares the
1923 old configuration with the new one and performs the minimum set of
1924 actions necessary to bring the buildbot up to date: Builders which are
1925 not changed are left untouched, and Builders which are modified get to
1926 keep their old event history.
1928 Basic Python syntax: comments start with a hash character (``#''),
1929 tuples are defined with @code{(parenthesis, pairs)}, arrays are
1930 defined with @code{[square, brackets]}, tuples and arrays are mostly
1931 interchangeable. Dictionaries (data structures which map ``keys'' to
1932 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
1933 'key2': 'value2'@} }. Function calls (and object instantiation) can use
1934 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
1936 The config file starts with a series of @code{import} statements,
1937 which make various kinds of Steps and Status targets available for
1938 later use. The main @code{BuildmasterConfig} dictionary is created,
1939 then it is populated with a variety of keys. These keys are broken
1940 roughly into the following sections, each of which is documented in
1941 the rest of this chapter:
1943 @itemize @bullet
1944 @item
1945 Project Definitions
1946 @item
1947 Change Sources / Schedulers
1948 @item
1949 Slaveport
1950 @item
1951 Buildslave Configuration
1952 @item
1953 Builders / Interlocks
1954 @item
1955 Status Targets
1956 @item
1957 Debug options
1958 @end itemize
1960 The config file can use a few names which are placed into its namespace:
1962 @table @code
1963 @item basedir
1964 the base directory for the buildmaster. This string has not been
1965 expanded, so it may start with a tilde. It needs to be expanded before
1966 use. The config file is located in
1967 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
1969 @end table
1972 @node Loading the Config File, Defining the Project, Config File Format, Configuration
1973 @section Loading the Config File
1975 The config file is only read at specific points in time. It is first
1976 read when the buildmaster is launched. Once it is running, there are
1977 various ways to ask it to reload the config file. If you are on the
1978 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
1979 it: the @command{buildbot} tool has a shortcut for this:
1981 @example
1982 buildbot reconfig @var{BASEDIR}
1983 @end example
1985 This command will show you all of the lines from @file{twistd.log}
1986 that relate to the reconfiguration. If there are any problems during
1987 the config-file reload, they will be displayed in these lines.
1989 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
1990 ``Reload .cfg'' button which will also trigger a reload. In the
1991 future, there will be other ways to accomplish this step (probably a
1992 password-protected button on the web page, as well as a privileged IRC
1993 command).
1995 When reloading the config file, the buildmaster will endeavor to
1996 change as little as possible about the running system. For example,
1997 although old status targets may be shut down and new ones started up,
1998 any status targets that were not changed since the last time the
1999 config file was read will be left running and untouched. Likewise any
2000 Builders which have not been changed will be left running. If a
2001 Builder is modified (say, the build process is changed) while a Build
2002 is currently running, that Build will keep running with the old
2003 process until it completes. Any previously queued Builds (or Builds
2004 which get queued after the reconfig) will use the new process.
2006 @node Defining the Project, Listing Change Sources and Schedulers, Loading the Config File, Configuration
2007 @section Defining the Project
2009 There are a couple of basic settings that you use to tell the buildbot
2010 what project it is working on. This information is used by status
2011 reporters to let users find out more about the codebase being
2012 exercised by this particular Buildbot installation.
2014 @example
2015 c['projectName'] = "Buildbot"
2016 c['projectURL'] = "http://buildbot.sourceforge.net/"
2017 c['buildbotURL'] = "http://localhost:8010/"
2018 @end example
2020 @bcindex c['projectName']
2021 @code{projectName} is a short string will be used to describe the
2022 project that this buildbot is working on. For example, it is used as
2023 the title of the waterfall HTML page. 
2025 @bcindex c['projectURL']
2026 @code{projectURL} is a string that gives a URL for the project as a
2027 whole. HTML status displays will show @code{projectName} as a link to
2028 @code{projectURL}, to provide a link from buildbot HTML pages to your
2029 project's home page.
2031 @bcindex c['buildbotURL']
2032 The @code{buildbotURL} string should point to the location where the
2033 buildbot's internal web server (usually the @code{html.Waterfall}
2034 page) is visible. This typically uses the port number set when you
2035 create the @code{Waterfall} object: the buildbot needs your help to
2036 figure out a suitable externally-visible host name.
2038 When status notices are sent to users (either by email or over IRC),
2039 @code{buildbotURL} will be used to create a URL to the specific build
2040 or problem that they are being notified about. It will also be made
2041 available to queriers (over IRC) who want to find out where to get
2042 more information about this buildbot.
2045 @node Listing Change Sources and Schedulers, Setting the slaveport, Defining the Project, Configuration
2046 @section Listing Change Sources and Schedulers
2048 @bcindex c['sources']
2049 @bcindex c['change_source']
2051 The @code{c['change_source']} key is the ChangeSource
2052 instance@footnote{To be precise, it is an object or a list of objects
2053 which all implement the @code{buildbot.interfaces.IChangeSource}
2054 Interface. It is unusual to have multiple ChangeSources, so this key
2055 accepts either a single ChangeSource or a sequence of them.} that
2056 defines how the buildmaster learns about source code changes. More
2057 information about what goes here is available in @xref{Getting Source
2058 Code Changes}.
2060 @example
2061 from buildbot.changes.pb import PBChangeSource
2062 c['change_source'] = PBChangeSource()
2063 @end example
2065 (note: in buildbot-0.7.5 and earlier, this key was named
2066 @code{c['sources']}, and required a list. @code{c['sources']} is
2067 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2068 future release).
2070 @bcindex c['schedulers']
2071 @code{c['schedulers']} is a list of Scheduler instances, each of which
2072 causes builds to be started on a particular set of Builders. The two
2073 basic Scheduler classes you are likely to start with are
2074 @code{Scheduler} and @code{Periodic}, but you can write a customized
2075 subclass to implement more complicated build scheduling.
2077 The docstring for @code{buildbot.scheduler.Scheduler} is the best
2078 place to see all the options that can be used. Type @code{pydoc
2079 buildbot.scheduler.Scheduler} to see it, or look in
2080 @file{buildbot/scheduler.py} directly.
2082 The basic Scheduler takes four arguments:
2084 @table @code
2085 @item name
2086 Each Scheduler must have a unique name. This is only used in status
2087 displays.
2089 @item branch
2090 This Scheduler will pay attention to a single branch, ignoring Changes
2091 that occur on other branches. Setting @code{branch} equal to the
2092 special value of @code{None} means it should only pay attention to the
2093 default branch. Note that @code{None} is a keyword, not a string, so
2094 you want to use @code{None} and not @code{"None"}.
2096 @item treeStableTimer
2097 The Scheduler will wait for this many seconds before starting the
2098 build. If new changes are made during this interval, the timer will be
2099 restarted, so really the build will be started after a change and then
2100 after this many seconds of inactivity.
2102 @item builderNames
2103 When the tree-stable-timer finally expires, builds will be started on
2104 these Builders. Each Builder gets a unique name: these strings must
2105 match.
2107 @end table
2109 @example
2110 from buildbot import scheduler
2111 quick = scheduler.Scheduler("quick", None, 60,
2112                             ["quick-linux", "quick-netbsd"])
2113 full = scheduler.Scheduler("full", None, 5*60,
2114                            ["full-linux", "full-netbsd", "full-OSX"])
2115 nightly = scheduler.Periodic("nightly", ["full-solaris"], 24*60*60)
2116 c['schedulers'] = [quick, full, nightly]
2117 @end example
2119 In this example, the two ``quick'' builds are triggered 60 seconds
2120 after the tree has been changed. The ``full'' builds do not run quite
2121 so quickly (they wait 5 minutes), so hopefully if the quick builds
2122 fail due to a missing file or really simple typo, the developer can
2123 discover and fix the problem before the full builds are started. Both
2124 Schedulers only pay attention to the default branch: any changes on
2125 other branches are ignored by these Schedulers. Each Scheduler
2126 triggers a different set of Builders, referenced by name.
2128 The third Scheduler in this example just runs the full solaris build
2129 once per day. (note that this Scheduler only lets you control the time
2130 between builds, not the absolute time-of-day of each Build, so this
2131 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2132 depending upon when it was first activated).
2134 @menu
2135 * Scheduler Types::             
2136 * Build Dependencies::          
2137 @end menu
2139 @node Scheduler Types, Build Dependencies, Listing Change Sources and Schedulers, Listing Change Sources and Schedulers
2140 @subsection Scheduler Types
2142 @slindex buildbot.scheduler.Scheduler
2143 @slindex buildbot.scheduler.AnyBranchScheduler
2144 @slindex buildbot.scheduler.Periodic
2145 @slindex buildbot.scheduler.Nightly
2147 Here is a brief catalog of the available Scheduler types. All these
2148 Schedulers are classes in @code{buildbot.scheduler}, and the
2149 docstrings there are the best source of documentation on the arguments
2150 taken by each one.
2152 @table @code
2153 @item Scheduler
2154 This is the default Scheduler class. It follows exactly one branch,
2155 and starts a configurable tree-stable-timer after each change on that
2156 branch. When the timer expires, it starts a build on some set of
2157 Builders. The Scheduler accepts a @code{fileIsImportant} function
2158 which can be used to ignore some Changes if they do not affect any
2159 ``important'' files.
2161 @item AnyBranchScheduler
2162 This scheduler uses a tree-stable-timer like the default one, but
2163 follows multiple branches at once. Each branch gets a separate timer.
2165 @item Dependent
2166 This scheduler watches an ``upstream'' Scheduler. When all the
2167 Builders launched by that Scheduler successfully finish, the Dependent
2168 scheduler is triggered. The next section (@pxref{Build Dependencies})
2169 describes this scheduler in more detail.
2171 @item Periodic
2172 This simple scheduler just triggers a build every N seconds.
2174 @item Nightly
2175 This is highly configurable periodic build scheduler, which triggers a
2176 build at particular times of day, week, month, or year. The
2177 configuration syntax is very similar to the well-known @code{crontab}
2178 format, in which you provide values for minute, hour, day, and month
2179 (some of which can be wildcards), and a build is triggered whenever
2180 the current time matches the given constraints. This can run a build
2181 every night, every morning, every weekend, alternate Thursdays, on
2182 your boss's birthday, etc.
2184 @item Try_Jobdir / Try_Userpass
2185 This scheduler allows developers to use the @code{buildbot try}
2186 command to trigger builds of code they have not yet committed. See
2187 @ref{try} for complete details.
2189 @end table
2191 @node Build Dependencies,  , Scheduler Types, Listing Change Sources and Schedulers
2192 @subsection Build Dependencies
2194 @cindex Dependent
2195 @cindex Dependencies
2196 @slindex buildbot.scheduler.Dependent
2198 It is common to wind up with one kind of build which should only be
2199 performed if the same source code was successfully handled by some
2200 other kind of build first. An example might be a packaging step: you
2201 might only want to produce .deb or RPM packages from a tree that was
2202 known to compile successfully and pass all unit tests. You could put
2203 the packaging step in the same Build as the compile and testing steps,
2204 but there might be other reasons to not do this (in particular you
2205 might have several Builders worth of compiles/tests, but only wish to
2206 do the packaging once). Another example is if you want to skip the
2207 ``full'' builds after a failing ``quick'' build of the same source
2208 code. Or, if one Build creates a product (like a compiled library)
2209 that is used by some other Builder, you'd want to make sure the
2210 consuming Build is run @emph{after} the producing one.
2212 You can use @code{Dependencies} to express this relationship to the
2213 Buildbot. There is a special kind of Scheduler named
2214 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2215 for builds to complete successfully (on all of its Builders). Each
2216 time that happens, the same source code (i.e. the same
2217 @code{SourceStamp}) will be used to start a new set of builds, on a
2218 different set of Builders. This ``downstream'' scheduler doesn't pay
2219 attention to Changes at all, it only pays attention to the upstream
2220 scheduler.
2222 If the SourceStamp fails on any of the Builders in the upstream set,
2223 the downstream builds will not fire.
2225 @example
2226 from buildbot import scheduler
2227 tests = scheduler.Scheduler("tests", None, 5*60,
2228                             ["full-linux", "full-netbsd", "full-OSX"])
2229 package = scheduler.Dependent("package",
2230                               tests, # upstream scheduler
2231                               ["make-tarball", "make-deb", "make-rpm"])
2232 c['schedulers'] = [tests, package]
2233 @end example
2235 Note that @code{Dependent}'s upstream scheduler argument is given as a
2236 @code{Scheduler} @emph{instance}, not a name. This makes it impossible
2237 to create circular dependencies in the config file.
2240 @node Setting the slaveport, Buildslave Specifiers, Listing Change Sources and Schedulers, Configuration
2241 @section Setting the slaveport
2243 @bcindex c['slavePortnum']
2245 The buildmaster will listen on a TCP port of your choosing for
2246 connections from buildslaves. It can also use this port for
2247 connections from remote Change Sources, status clients, and debug
2248 tools. This port should be visible to the outside world, and you'll
2249 need to tell your buildslave admins about your choice.
2251 It does not matter which port you pick, as long it is externally
2252 visible, however you should probably use something larger than 1024,
2253 since most operating systems don't allow non-root processes to bind to
2254 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2255 box of some sort, you may have to configure your firewall to permit
2256 inbound connections to this port.
2258 @example
2259 c['slavePortnum'] = 10000
2260 @end example
2262 @code{c['slavePortnum']} is a @emph{strports} specification string,
2263 defined in the @code{twisted.application.strports} module (try
2264 @command{pydoc twisted.application.strports} to get documentation on
2265 the format). This means that you can have the buildmaster listen on a
2266 localhost-only port by doing:
2268 @example
2269 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2270 @end example
2272 This might be useful if you only run buildslaves on the same machine,
2273 and they are all configured to contact the buildmaster at
2274 @code{localhost:10000}.
2277 @node Buildslave Specifiers, Defining Builders, Setting the slaveport, Configuration
2278 @section Buildslave Specifiers
2280 @bcindex c['slaves']
2282 The @code{c['slaves']} key is a list of known buildslaves. Each
2283 buildslave is defined by an instance of the BuildSlave class, created
2284 with two values: (slavename, slavepassword). These are the same two
2285 values that need to be provided to the buildslave administrator when
2286 they create the buildslave.
2288 @example
2289 from buildbot.buildslave import BuildSlave
2290 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd'),
2291                BuildSlave('bot-bsd', 'bsdpasswd'),
2292               ]
2293 @end example
2295 The slavenames must be unique, of course. The password exists to
2296 prevent evildoers from interfering with the buildbot by inserting
2297 their own (broken) buildslaves into the system and thus displacing the
2298 real ones.
2300 Buildslaves with an unrecognized slavename or a non-matching password
2301 will be rejected when they attempt to connect, and a message
2302 describing the problem will be put in the log file (see @ref{Logfiles}).
2304 The @code{BuildSlave} constructor can take an optional
2305 @code{max_builds} parameter to limit the number of builds that it will
2306 execute simultaneously:
2308 @example
2309 from buildbot.buildslave import BuildSlave
2310 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2311 @end example
2313 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2314 key was used instead, and it took a list of (name, password) tuples.
2315 This key is accepted for backwards compatibility, but is deprecated as
2316 of 0.7.6 and will go away in some future release.
2318 @menu
2319 * When Buildslaves Go Missing::  
2320 @end menu
2322 @node When Buildslaves Go Missing,  , Buildslave Specifiers, Buildslave Specifiers
2323 @subsection When Buildslaves Go Missing
2325 Sometimes, the buildslaves go away. One very common reason for this is
2326 when the buildslave process is started once (manually) and left
2327 running, but then later the machine reboots and the process is not
2328 automatically restarted.
2330 If you'd like to have the administrator of the buildslave (or other
2331 people) be notified by email when the buildslave has been missing for
2332 too long, just add the @code{notify_on_missing=} argument to the
2333 @code{BuildSlave} definition:
2335 @example
2336 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2337                           notify_on_missing="bob@@example.com"),
2338               ]
2339 @end example
2341 By default, this will send email when the buildslave has been
2342 disconnected for more than one hour. Only one email per
2343 connection-loss event will be sent. To change the timeout, use
2344 @code{missing_timeout=} and give it a number of seconds (the default
2345 is 3600).
2347 You can have the buildmaster send email to multiple recipients: just
2348 provide a list of addresses instead of a single one:
2350 @example
2351 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2352                           notify_on_missing=["bob@@example.com",
2353                                              "alice@@example.org"],
2354                           missing_timeout=300, # notify after 10 minutes
2355                           ),
2356               ]
2357 @end example
2359 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2360 status target, if one is configured. This provides a way for you to
2361 control the ``from'' address of the email, as well as the relayhost
2362 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2363 configured on this buildmaster, the buildslave-missing emails will be
2364 sent using a default configuration.
2366 Note that if you want to have a MailNotifier for buildslave-missing
2367 emails but not for regular build emails, just create one with
2368 builders=[], as follows:
2370 @example
2371 from buildbot.status import mail
2372 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2373                       relayhost="smtp.example.org")
2374 c['status'].append(m)
2375 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2376                           notify_on_missing="bob@@example.com"),
2377               ]
2378 @end example
2381 @node Defining Builders, Defining Status Targets, Buildslave Specifiers, Configuration
2382 @section Defining Builders
2384 @bcindex c['builders']
2386 The @code{c['builders']} key is a list of dictionaries which specify
2387 the Builders. The Buildmaster runs a collection of Builders, each of
2388 which handles a single type of build (e.g. full versus quick), on a
2389 single build slave. A Buildbot which makes sure that the latest code
2390 (``HEAD'') compiles correctly across four separate architecture will
2391 have four Builders, each performing the same build but on different
2392 slaves (one per platform).
2394 Each Builder gets a separate column in the waterfall display. In
2395 general, each Builder runs independently (although various kinds of
2396 interlocks can cause one Builder to have an effect on another).
2398 Each Builder specification dictionary has several required keys:
2400 @table @code
2401 @item name
2402 This specifies the Builder's name, which is used in status
2403 reports.
2405 @item slavename
2406 This specifies which buildslave will be used by this Builder.
2407 @code{slavename} must appear in the @code{c['slaves']} list. Each
2408 buildslave can accomodate multiple Builders.
2410 @item slavenames
2411 If you provide @code{slavenames} instead of @code{slavename}, you can
2412 give a list of buildslaves which are capable of running this Builder.
2413 If multiple buildslaves are available for any given Builder, you will
2414 have some measure of redundancy: in case one slave goes offline, the
2415 others can still keep the Builder working. In addition, multiple
2416 buildslaves will allow multiple simultaneous builds for the same
2417 Builder, which might be useful if you have a lot of forced or ``try''
2418 builds taking place.
2420 If you use this feature, it is important to make sure that the
2421 buildslaves are all, in fact, capable of running the given build. The
2422 slave hosts should be configured similarly, otherwise you will spend a
2423 lot of time trying (unsuccessfully) to reproduce a failure that only
2424 occurs on some of the buildslaves and not the others. Different
2425 platforms, operating systems, versions of major programs or libraries,
2426 all these things mean you should use separate Builders.
2428 @item builddir
2429 This specifies the name of a subdirectory (under the base directory)
2430 in which everything related to this builder will be placed. On the
2431 buildmaster, this holds build status information. On the buildslave,
2432 this is where checkouts, compiles, and tests are run.
2434 @item factory
2435 This is a @code{buildbot.process.factory.BuildFactory} instance which
2436 controls how the build is performed. Full details appear in their own
2437 chapter, @xref{Build Process}. Parameters like the location of the CVS
2438 repository and the compile-time options used for the build are
2439 generally provided as arguments to the factory's constructor.
2441 @end table
2443 Other optional keys may be set on each Builder:
2445 @table @code
2447 @item category
2448 If provided, this is a string that identifies a category for the
2449 builder to be a part of. Status clients can limit themselves to a
2450 subset of the available categories. A common use for this is to add
2451 new builders to your setup (for a new module, or for a new buildslave)
2452 that do not work correctly yet and allow you to integrate them with
2453 the active builders. You can put these new builders in a test
2454 category, make your main status clients ignore them, and have only
2455 private status clients pick them up. As soon as they work, you can
2456 move them over to the active category.
2458 @end table
2461 @node Defining Status Targets, Debug options, Defining Builders, Configuration
2462 @section Defining Status Targets
2464 The Buildmaster has a variety of ways to present build status to
2465 various users. Each such delivery method is a ``Status Target'' object
2466 in the configuration's @code{status} list. To add status targets, you
2467 just append more objects to this list:
2469 @bcindex c['status']
2471 @example
2472 c['status'] = []
2474 from buildbot.status import html
2475 c['status'].append(html.Waterfall(http_port=8010))
2477 from buildbot.status import mail
2478 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
2479                       extraRecipients=["builds@@lists.example.com"],
2480                       sendToInterestedUsers=False)
2481 c['status'].append(m)
2483 from buildbot.status import words
2484 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
2485                              channels=["#example"]))
2486 @end example
2488 Status delivery has its own chapter, @xref{Status Delivery}, in which
2489 all the built-in status targets are documented.
2492 @node Debug options,  , Defining Status Targets, Configuration
2493 @section Debug options
2496 @bcindex c['debugPassword']
2497 If you set @code{c['debugPassword']}, then you can connect to the
2498 buildmaster with the diagnostic tool launched by @code{buildbot
2499 debugclient MASTER:PORT}. From this tool, you can reload the config
2500 file, manually force builds, and inject changes, which may be useful
2501 for testing your buildmaster without actually commiting changes to
2502 your repository (or before you have the Change Sources set up). The
2503 debug tool uses the same port number as the slaves do:
2504 @code{c['slavePortnum']}, and is authenticated with this password.
2506 @example
2507 c['debugPassword'] = "debugpassword"
2508 @end example
2510 @bcindex c['manhole']
2511 If you set @code{c['manhole']} to an instance of one of the classes in
2512 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
2513 and get an interactive Python shell, which may be useful for debugging
2514 buildbot internals. It is probably only useful for buildbot
2515 developers. It exposes full access to the buildmaster's account
2516 (including the ability to modify and delete files), so it should not
2517 be enabled with a weak or easily guessable password.
2519 There are three separate @code{Manhole} classes. Two of them use SSH,
2520 one uses unencrypted telnet. Two of them use a username+password
2521 combination to grant access, one of them uses an SSH-style
2522 @file{authorized_keys} file which contains a list of ssh public keys.
2524 @table @code
2525 @item manhole.AuthorizedKeysManhole
2526 You construct this with the name of a file that contains one SSH
2527 public key per line, just like @file{~/.ssh/authorized_keys}. If you
2528 provide a non-absolute filename, it will be interpreted relative to
2529 the buildmaster's base directory.
2531 @item manhole.PasswordManhole
2532 This one accepts SSH connections but asks for a username and password
2533 when authenticating. It accepts only one such pair.
2536 @item manhole.TelnetManhole
2537 This accepts regular unencrypted telnet connections, and asks for a
2538 username/password pair before providing access. Because this
2539 username/password is transmitted in the clear, and because Manhole
2540 access to the buildmaster is equivalent to granting full shell
2541 privileges to both the buildmaster and all the buildslaves (and to all
2542 accounts which then run code produced by the buildslaves), it is
2543 highly recommended that you use one of the SSH manholes instead.
2545 @end table
2547 @example
2548 # some examples:
2549 from buildbot import manhole
2550 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
2551 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
2552 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
2553 @end example
2555 The @code{Manhole} instance can be configured to listen on a specific
2556 port. You may wish to have this listening port bind to the loopback
2557 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
2558 restrict access to clients which are running on the same host.
2560 @example
2561 from buildbot.manhole import PasswordManhole
2562 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
2563 @end example
2565 To have the @code{Manhole} listen on all interfaces, use
2566 @code{"tcp:9999"} or simply 9999. This port specification uses
2567 @code{twisted.application.strports}, so you can make it listen on SSL
2568 or even UNIX-domain sockets if you want.
2570 Note that using any Manhole requires that the TwistedConch package be
2571 installed, and that you be using Twisted version 2.0 or later.
2573 The buildmaster's SSH server will use a different host key than the
2574 normal sshd running on a typical unix host. This will cause the ssh
2575 client to complain about a ``host key mismatch'', because it does not
2576 realize there are two separate servers running on the same host. To
2577 avoid this, use a clause like the following in your @file{.ssh/config}
2578 file:
2580 @example
2581 Host remotehost-buildbot
2582  HostName remotehost
2583  HostKeyAlias remotehost-buildbot
2584  Port 9999
2585  # use 'user' if you use PasswordManhole and your name is not 'admin'.
2586  # if you use AuthorizedKeysManhole, this probably doesn't matter.
2587  User admin
2588 @end example
2591 @node Getting Source Code Changes, Build Process, Configuration, Top
2592 @chapter Getting Source Code Changes
2594 The most common way to use the Buildbot is centered around the idea of
2595 @code{Source Trees}: a directory tree filled with source code of some form
2596 which can be compiled and/or tested. Some projects use languages that don't
2597 involve any compilation step: nevertheless there may be a @code{build} phase
2598 where files are copied or rearranged into a form that is suitable for
2599 installation. Some projects do not have unit tests, and the Buildbot is
2600 merely helping to make sure that the sources can compile correctly. But in
2601 all of these cases, the thing-being-tested is a single source tree.
2603 A Version Control System mantains a source tree, and tells the
2604 buildmaster when it changes. The first step of each Build is typically
2605 to acquire a copy of some version of this tree.
2607 This chapter describes how the Buildbot learns about what Changes have
2608 occurred. For more information on VC systems and Changes, see
2609 @ref{Version Control Systems}.
2612 @menu
2613 * Change Sources::              
2614 * Choosing ChangeSources::      
2615 * CVSToys - PBService::         
2616 * Mail-parsing ChangeSources::  
2617 * PBChangeSource::              
2618 * P4Source::                    
2619 * BonsaiPoller::                
2620 * SVNPoller::                   
2621 * MercurialHook::               
2622 @end menu
2626 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
2627 @section Change Sources
2629 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
2630 @c so narrow-minded anymore
2632 Each Buildmaster watches a single source tree. Changes can be provided
2633 by a variety of ChangeSource types, however any given project will
2634 typically have only a single ChangeSource active. This section
2635 provides a description of all available ChangeSource types and
2636 explains how to set up each of them.
2638 There are a variety of ChangeSources available, some of which are
2639 meant to be used in conjunction with other tools to deliver Change
2640 events from the VC repository to the buildmaster.
2642 @itemize @bullet
2644 @item CVSToys
2645 This ChangeSource opens a TCP connection from the buildmaster to a
2646 waiting FreshCVS daemon that lives on the repository machine, and
2647 subscribes to hear about Changes.
2649 @item MaildirSource
2650 This one watches a local maildir-format inbox for email sent out by
2651 the repository when a change is made. When a message arrives, it is
2652 parsed to create the Change object. A variety of parsing functions are
2653 available to accomodate different email-sending tools.
2655 @item PBChangeSource
2656 This ChangeSource listens on a local TCP socket for inbound
2657 connections from a separate tool. Usually, this tool would be run on
2658 the VC repository machine in a commit hook. It is expected to connect
2659 to the TCP socket and send a Change message over the network
2660 connection. The @command{buildbot sendchange} command is one example
2661 of a tool that knows how to send these messages, so you can write a
2662 commit script for your VC system that calls it to deliver the Change.
2663 There are other tools in the contrib/ directory that use the same
2664 protocol.
2666 @end itemize
2668 As a quick guide, here is a list of VC systems and the ChangeSources
2669 that might be useful with them. All of these ChangeSources are in the
2670 @code{buildbot.changes} module.
2672 @table @code
2673 @item CVS
2675 @itemize @bullet
2676 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
2677 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
2678 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
2679 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
2680 @item pb.PBChangeSource (listening for connections from @code{buildbot
2681 sendchange} run in a loginfo script)
2682 @item pb.PBChangeSource (listening for connections from a long-running
2683 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
2684 database directly
2685 @end itemize
2687 @item SVN
2688 @itemize @bullet
2689 @item pb.PBChangeSource (listening for connections from
2690 @code{contrib/svn_buildbot.py} run in a postcommit script)
2691 @item pb.PBChangeSource (listening for connections from a long-running
2692 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
2693 process
2694 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
2695 @item svnpoller.SVNPoller (polling the SVN repository)
2696 @end itemize
2698 @item Darcs
2699 @itemize @bullet
2700 @item pb.PBChangeSource (listening for connections from
2701 @code{contrib/darcs_buildbot.py} in a commit script
2702 @end itemize
2704 @item Mercurial
2705 @itemize @bullet
2706 @item pb.PBChangeSource (listening for connections from
2707 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
2708 @item pb.PBChangeSource (listening for connections from
2709 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
2710 hook)
2711 @end itemize
2713 @item Arch/Bazaar
2714 @itemize @bullet
2715 @item pb.PBChangeSource (listening for connections from
2716 @code{contrib/arch_buildbot.py} run in a commit hook)
2717 @end itemize
2719 @end table
2721 All VC systems can be driven by a PBChangeSource and the
2722 @code{buildbot sendchange} tool run from some form of commit script.
2723 If you write an email parsing function, they can also all be driven by
2724 a suitable @code{MaildirSource}.
2727 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
2728 @section Choosing ChangeSources
2730 The @code{master.cfg} configuration file has a dictionary key named
2731 @code{BuildmasterConfig['change_source']}, which holds the active
2732 @code{IChangeSource} object. The config file will typically create an
2733 object from one of the classes described below and stuff it into this
2734 key.
2736 Each buildmaster typically has just a single ChangeSource, since it is
2737 only watching a single source tree. But if, for some reason, you need
2738 multiple sources, just set @code{c['change_source']} to a list of
2739 ChangeSources.. it will accept that too.
2741 @example
2742 s = FreshCVSSourceNewcred(host="host", port=4519,
2743                           user="alice", passwd="secret",
2744                           prefix="Twisted")
2745 BuildmasterConfig['change_source'] = [s]
2746 @end example
2748 Each source tree has a nominal @code{top}. Each Change has a list of
2749 filenames, which are all relative to this top location. The
2750 ChangeSource is responsible for doing whatever is necessary to
2751 accomplish this. Most sources have a @code{prefix} argument: a partial
2752 pathname which is stripped from the front of all filenames provided to
2753 that @code{ChangeSource}. Files which are outside this sub-tree are
2754 ignored by the changesource: it does not generate Changes for those
2755 files.
2758 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
2759 @section CVSToys - PBService
2761 @csindex buildbot.changes.freshcvs.FreshCVSSource
2763 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
2764 server which runs on the machine that hosts the CVS repository it
2765 watches. It has a variety of ways to distribute commit notifications,
2766 and offers a flexible regexp-based way to filter out uninteresting
2767 changes. One of the notification options is named @code{PBService} and
2768 works by listening on a TCP port for clients. These clients subscribe
2769 to hear about commit notifications.
2771 The buildmaster has a CVSToys-compatible @code{PBService} client built
2772 in. There are two versions of it, one for old versions of CVSToys
2773 (1.0.9 and earlier) which used the @code{oldcred} authentication
2774 framework, and one for newer versions (1.0.10 and later) which use
2775 @code{newcred}. Both are classes in the
2776 @code{buildbot.changes.freshcvs} package.
2778 @code{FreshCVSSourceNewcred} objects are created with the following
2779 parameters:
2781 @table @samp
2783 @item @code{host} and @code{port}
2784 these specify where the CVSToys server can be reached
2786 @item @code{user} and @code{passwd}
2787 these specify the login information for the CVSToys server
2788 (@code{freshcvs}). These must match the server's values, which are
2789 defined in the @code{freshCfg} configuration file (which lives in the
2790 CVSROOT directory of the repository).
2792 @item @code{prefix}
2793 this is the prefix to be found and stripped from filenames delivered
2794 by the CVSToys server. Most projects live in sub-directories of the
2795 main repository, as siblings of the CVSROOT sub-directory, so
2796 typically this prefix is set to that top sub-directory name.
2798 @end table
2800 @heading Example
2802 To set up the freshCVS server, add a statement like the following to
2803 your @file{freshCfg} file:
2805 @example
2806 pb = ConfigurationSet([
2807     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
2808     ])
2809 @end example
2811 This will announce all changes to a client which connects to port 4519
2812 using a username of 'foo' and a password of 'bar'.
2814 Then add a clause like this to your buildmaster's @file{master.cfg}:
2816 @example
2817 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
2818                                                     "foo", "bar",
2819                                                     prefix="glib/")
2820 @end example
2822 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
2823 "glib" is the top-level directory (relative to the repository's root) where
2824 all your source code lives. Most projects keep one or more projects in the
2825 same repository (along with CVSROOT/ to hold admin files like loginfo and
2826 freshCfg); the prefix= argument tells the buildmaster to ignore everything
2827 outside that directory, and to strip that common prefix from all pathnames
2828 it handles.
2831 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
2832 @section Mail-parsing ChangeSources
2834 Many projects publish information about changes to their source tree
2835 by sending an email message out to a mailing list, frequently named
2836 PROJECT-commits or PROJECT-changes. Each message usually contains a
2837 description of the change (who made the change, which files were
2838 affected) and sometimes a copy of the diff. Humans can subscribe to
2839 this list to stay informed about what's happening to the source tree.
2841 The Buildbot can also be subscribed to a -commits mailing list, and
2842 can trigger builds in response to Changes that it hears about. The
2843 buildmaster admin needs to arrange for these email messages to arrive
2844 in a place where the buildmaster can find them, and configure the
2845 buildmaster to parse the messages correctly. Once that is in place,
2846 the email parser will create Change objects and deliver them to the
2847 Schedulers (see @pxref{Scheduler Types}) just like any other
2848 ChangeSource.
2850 There are two components to setting up an email-based ChangeSource.
2851 The first is to route the email messages to the buildmaster, which is
2852 done by dropping them into a ``maildir''. The second is to actually
2853 parse the messages, which is highly dependent upon the tool that was
2854 used to create them. Each VC system has a collection of favorite
2855 change-emailing tools, and each has a slightly different format, so
2856 each has a different parsing function. There is a separate
2857 ChangeSource variant for each parsing function.
2859 Once you've chosen a maildir location and a parsing function, create
2860 the change source and put it in @code{c['change_source']}:
2862 @example
2863 from buildbot.changes.mail import SyncmailMaildirSource
2864 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
2865                                            prefix="/trunk/")
2866 @end example
2868 @menu
2869 * Subscribing the Buildmaster::  
2870 * Using Maildirs::              
2871 * Parsing Email Change Messages::  
2872 @end menu
2874 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
2875 @subsection Subscribing the Buildmaster
2877 The recommended way to install the buildbot is to create a dedicated
2878 account for the buildmaster. If you do this, the account will probably
2879 have a distinct email address (perhaps
2880 @email{buildmaster@@example.org}). Then just arrange for this
2881 account's email to be delivered to a suitable maildir (described in
2882 the next section).
2884 If the buildbot does not have its own account, ``extension addresses''
2885 can be used to distinguish between email intended for the buildmaster
2886 and email intended for the rest of the account. In most modern MTAs,
2887 the e.g. @code{foo@@example.org} account has control over every email
2888 address at example.org which begins with "foo", such that email
2889 addressed to @email{account-foo@@example.org} can be delivered to a
2890 different destination than @email{account-bar@@example.org}. qmail
2891 does this by using separate .qmail files for the two destinations
2892 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
2893 controlling the base address and @file{.qmail-default} controlling all
2894 other extensions). Other MTAs have similar mechanisms.
2896 Thus you can assign an extension address like
2897 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
2898 @email{foo@@example.org} for your own use.
2901 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
2902 @subsection Using Maildirs
2904 A ``maildir'' is a simple directory structure originally developed for
2905 qmail that allows safe atomic update without locking. Create a base
2906 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
2907 When messages arrive, they are put into a uniquely-named file (using
2908 pids, timestamps, and random numbers) in ``tmp''. When the file is
2909 complete, it is atomically renamed into ``new''. Eventually the
2910 buildmaster notices the file in ``new'', reads and parses the
2911 contents, then moves it into ``cur''. A cronjob can be used to delete
2912 files in ``cur'' at leisure.
2914 Maildirs are frequently created with the @command{maildirmake} tool,
2915 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
2916 equivalent.
2918 Many modern MTAs can deliver directly to maildirs. The usual .forward
2919 or .procmailrc syntax is to name the base directory with a trailing
2920 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
2921 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
2922 Delivery Agent).
2924 For MTAs which cannot put files into maildirs directly, the
2925 ``safecat'' tool can be executed from a .forward file to accomplish
2926 the same thing.
2928 The Buildmaster uses the linux DNotify facility to receive immediate
2929 notification when the maildir's ``new'' directory has changed. When
2930 this facility is not available, it polls the directory for new
2931 messages, every 10 seconds by default.
2933 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
2934 @subsection Parsing Email Change Messages
2936 The second component to setting up an email-based ChangeSource is to
2937 parse the actual notices. This is highly dependent upon the VC system
2938 and commit script in use.
2940 A couple of common tools used to create these change emails are:
2942 @table @samp
2944 @item CVS
2945 @table @samp
2946 @item CVSToys MailNotifier
2947 @ref{FCMaildirSource}
2948 @item Bonsai notification
2949 @ref{BonsaiMaildirSource}
2950 @item syncmail
2951 @ref{SyncmailMaildirSource}
2952 @end table
2954 @item SVN
2955 @table @samp
2956 @item svnmailer
2957 http://opensource.perlig.de/en/svnmailer/
2958 @item commit-email.pl
2959 @ref{SVNCommitEmailMaildirSource}
2960 @end table
2962 @item Mercurial
2963 @table @samp
2964 @item NotifyExtension
2965 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
2966 @end table
2968 @end table
2971 The following sections describe the parsers available for each of
2972 these tools.
2974 Most of these parsers accept a @code{prefix=} argument, which is used
2975 to limit the set of files that the buildmaster pays attention to. This
2976 is most useful for systems like CVS and SVN which put multiple
2977 projects in a single repository (or use repository names to indicate
2978 branches). Each filename that appears in the email is tested against
2979 the prefix: if the filename does not start with the prefix, the file
2980 is ignored. If the filename @emph{does} start with the prefix, that
2981 prefix is stripped from the filename before any further processing is
2982 done. Thus the prefix usually ends with a slash.
2984 @menu
2985 * FCMaildirSource::             
2986 * SyncmailMaildirSource::       
2987 * BonsaiMaildirSource::         
2988 * SVNCommitEmailMaildirSource::  
2989 @end menu
2991 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
2992 @subsubsection FCMaildirSource
2995 @csindex buildbot.changes.mail.FCMaildirSource
2997 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
2999 This parser works with the CVSToys @code{MailNotification} action,
3000 which will send email to a list of recipients for each commit. This
3001 tends to work better than using @code{/bin/mail} from within the
3002 CVSROOT/loginfo file directly, as CVSToys will batch together all
3003 files changed during the same CVS invocation, and can provide more
3004 information (like creating a ViewCVS URL for each file changed).
3006 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3007 messages and turn them into Change objects. It can be given two
3008 parameters: the directory name of the maildir root, and the prefix to
3009 strip.
3011 @example
3012 from buildbot.changes.mail import FCMaildirSource
3013 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3014 @end example
3016 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3017 @subsubsection SyncmailMaildirSource
3019 @csindex buildbot.changes.mail.SyncmailMaildirSource
3021 http://sourceforge.net/projects/cvs-syncmail
3023 @code{SyncmailMaildirSource} knows how to parse the message format used by
3024 the CVS ``syncmail'' script.
3026 @example
3027 from buildbot.changes.mail import SyncmailMaildirSource
3028 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3029 @end example
3031 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3032 @subsubsection BonsaiMaildirSource
3034 @csindex buildbot.changes.mail.BonsaiMaildirSource
3036 http://www.mozilla.org/bonsai.html
3038 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3039 tree-management system built by Mozilla.
3041 @example
3042 from buildbot.changes.mail import BonsaiMaildirSource
3043 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3044 @end example
3046 @node SVNCommitEmailMaildirSource,  , BonsaiMaildirSource, Parsing Email Change Messages
3047 @subsubsection SVNCommitEmailMaildirSource
3049 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3051 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3052 @code{commit-email.pl} script, which is included in the Subversion
3053 distribution.
3055 It does not currently handle branches: all of the Change objects that
3056 it creates will be associated with the default (i.e. trunk) branch.
3058 @example
3059 from buildbot.changes.mail import SVNCommitEmailMaildirSource
3060 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
3061 @end example
3064 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
3065 @section PBChangeSource
3067 @csindex buildbot.changes.pb.PBChangeSource
3069 The last kind of ChangeSource actually listens on a TCP port for
3070 clients to connect and push change notices @emph{into} the
3071 Buildmaster. This is used by the built-in @code{buildbot sendchange}
3072 notification tool, as well as the VC-specific
3073 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
3074 @file{contrib/hg_buildbot.py} tools, and the
3075 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
3076 repository (in a commit hook script), and connect to the buildmaster
3077 directly each time a file is comitted. This is also useful for
3078 creating new kinds of change sources that work on a @code{push} model
3079 instead of some kind of subscription scheme, for example a script
3080 which is run out of an email .forward file.
3082 This ChangeSource can be configured to listen on its own TCP port, or
3083 it can share the port that the buildmaster is already using for the
3084 buildslaves to connect. (This is possible because the
3085 @code{PBChangeSource} uses the same protocol as the buildslaves, and
3086 they can be distinguished by the @code{username} attribute used when
3087 the initial connection is established). It might be useful to have it
3088 listen on a different port if, for example, you wanted to establish
3089 different firewall rules for that port. You could allow only the SVN
3090 repository machine access to the @code{PBChangeSource} port, while
3091 allowing only the buildslave machines access to the slave port. Or you
3092 could just expose one port and run everything over it. @emph{Note:
3093 this feature is not yet implemented, the PBChangeSource will always
3094 share the slave port and will always have a @code{user} name of
3095 @code{change}, and a passwd of @code{changepw}. These limitations will
3096 be removed in the future.}.
3099 The @code{PBChangeSource} is created with the following arguments. All
3100 are optional.
3102 @table @samp
3103 @item @code{port}
3104 which port to listen on. If @code{None} (which is the default), it
3105 shares the port used for buildslave connections. @emph{Not
3106 Implemented, always set to @code{None}}.
3108 @item @code{user} and @code{passwd}
3109 The user/passwd account information that the client program must use
3110 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
3111 Implemented, @code{user} is currently always set to @code{change},
3112 @code{passwd} is always set to @code{changepw}}.
3114 @item @code{prefix}
3115 The prefix to be found and stripped from filenames delivered over the
3116 connection. Any filenames which do not start with this prefix will be
3117 removed. If all the filenames in a given Change are removed, the that
3118 whole Change will be dropped. This string should probably end with a
3119 directory separator.
3121 This is useful for changes coming from version control systems that
3122 represent branches as parent directories within the repository (like
3123 SVN and Perforce). Use a prefix of 'trunk/' or
3124 'project/branches/foobranch/' to only follow one branch and to get
3125 correct tree-relative filenames. Without a prefix, the PBChangeSource
3126 will probably deliver Changes with filenames like @file{trunk/foo.c}
3127 instead of just @file{foo.c}. Of course this also depends upon the
3128 tool sending the Changes in (like @command{buildbot sendchange}) and
3129 what filenames it is delivering: that tool may be filtering and
3130 stripping prefixes at the sending end.
3132 @end table
3134 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
3135 @section P4Source
3137 @csindex buildbot.changes.p4poller.P4Source
3139 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
3140 Perforce} depot for changes. It accepts the following arguments:
3142 @table @samp
3143 @item @code{p4base}
3144 The base depot path to watch, without the trailing '/...'.
3146 @item @code{p4port}
3147 The Perforce server to connect to (as host:port).
3149 @item @code{p4user}
3150 The Perforce user.
3152 @item @code{p4passwd}
3153 The Perforce password.
3155 @item @code{split_file}
3156 A function that maps a pathname, without the leading @code{p4base}, to a
3157 (branch, filename) tuple. The default just returns (None, branchfile),
3158 which effectively disables branch support. You should supply a function
3159 which understands your repository structure.
3161 @item @code{pollinterval}
3162 How often to poll, in seconds. Defaults to 600 (10 minutes).
3164 @item @code{histmax}
3165 The maximum number of changes to inspect at a time. If more than this
3166 number occur since the last poll, older changes will be silently
3167 ignored.
3168 @end table
3170 @heading Example
3172 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
3173 specified in the buildmaster's environment. It watches a project in which the
3174 branch name is simply the next path component, and the file is all path
3175 components after.
3177 @example
3178 import buildbot.changes.p4poller
3179 s = p4poller.P4Source(p4base='//depot/project/',
3180                       split_file=lambda branchfile: branchfile.split('/',1),
3181                      )
3182 c['change_source'] = s
3183 @end example
3185 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
3186 @section BonsaiPoller
3188 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
3190 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
3191 CGI script accessed through a web server that provides information
3192 about a CVS tree, for example the Mozilla bonsai server at
3193 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
3194 humans and machines. In this case, the buildbot's change source forms
3195 a query which asks about any files in the specified branch which have
3196 changed since the last query.
3198 Please take a look at the BonsaiPoller docstring for details about the
3199 arguments it accepts.
3202 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
3203 @section SVNPoller
3205 @csindex buildbot.changes.svnpoller.SVNPoller
3207 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
3208 which periodically polls a @uref{http://subversion.tigris.org/,
3209 Subversion} repository for new revisions, by running the @code{svn
3210 log} command in a subshell. It can watch a single branch or multiple
3211 branches.
3213 @code{SVNPoller} accepts the following arguments:
3215 @table @code
3216 @item svnurl
3217 The base URL path to watch, like
3218 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
3219 @code{http://divmod.org/svn/Divmod/}, or even
3220 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
3221 include the access scheme, the location of the repository (both the
3222 hostname for remote ones, and any additional directory names necessary
3223 to get to the repository), and the sub-path within the repository's
3224 virtual filesystem for the project and branch of interest.
3226 The @code{SVNPoller} will only pay attention to files inside the
3227 subdirectory specified by the complete svnurl.
3229 @item split_file
3230 A function to convert pathnames into (branch, relative_pathname)
3231 tuples. Use this to explain your repository's branch-naming policy to
3232 @code{SVNPoller}. This function must accept a single string and return
3233 a two-entry tuple. There are a few utility functions in
3234 @code{buildbot.changes.svnpoller} that can be used as a
3235 @code{split_file} function, see below for details.
3237 The default value always returns (None, path), which indicates that
3238 all files are on the trunk.
3240 Subclasses of @code{SVNPoller} can override the @code{split_file}
3241 method instead of using the @code{split_file=} argument.
3243 @item svnuser
3244 An optional string parameter. If set, the @code{--user} argument will
3245 be added to all @code{svn} commands. Use this if you have to
3246 authenticate to the svn server before you can do @code{svn info} or
3247 @code{svn log} commands.
3249 @item svnpasswd
3250 Like @code{svnuser}, this will cause a @code{--password} argument to
3251 be passed to all svn commands.
3253 @item pollinterval
3254 How often to poll, in seconds. Defaults to 600 (checking once every 10
3255 minutes). Lower this if you want the buildbot to notice changes
3256 faster, raise it if you want to reduce the network and CPU load on
3257 your svn server. Please be considerate of public SVN repositories by
3258 using a large interval when polling them.
3260 @item histmax
3261 The maximum number of changes to inspect at a time. Every POLLINTERVAL
3262 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
3263 looks through them for any ones it does not already know about. If
3264 more than HISTMAX revisions have been committed since the last poll,
3265 older changes will be silently ignored. Larger values of histmax will
3266 cause more time and memory to be consumed on each poll attempt.
3267 @code{histmax} defaults to 100.
3269 @item svnbin
3270 This controls the @code{svn} executable to use. If subversion is
3271 installed in a weird place on your system (outside of the
3272 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
3273 to find it. The default value of ``svn'' will almost always be
3274 sufficient.
3276 @end table
3278 @heading Branches
3280 Each source file that is tracked by a Subversion repository has a
3281 fully-qualified SVN URL in the following form:
3282 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
3283 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
3284 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
3285 string. The @code{SVNPoller} is responsible for producing Changes that
3286 contain a branch name and a FILEPATH (which is relative to the top of
3287 a checked-out tree). The details of how these strings are split up
3288 depend upon how your repository names its branches.
3290 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
3292 One common layout is to have all the various projects that share a
3293 repository get a single top-level directory each. Then under a given
3294 project's directory, you get two subdirectories, one named ``trunk''
3295 and another named ``branches''. Under ``branches'' you have a bunch of
3296 other directories, one per branch, with names like ``1.5.x'' and
3297 ``testing''. It is also common to see directories like ``tags'' and
3298 ``releases'' next to ``branches'' and ``trunk''.
3300 For example, the Twisted project has a subversion server on
3301 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
3302 repository is available through a SCHEME of ``svn:''. The primary
3303 sub-project is Twisted, of course, with a repository root of
3304 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
3305 Informant, with a root of
3306 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
3307 checked-out Twisted tree, there is a file named bin/trial (which is
3308 used to run unit test suites).
3310 The trunk for Twisted is in
3311 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
3312 fully-qualified SVN URL for the trunk version of @code{trial} would be
3313 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
3314 SVNURL for that file on a branch named ``1.5.x'' would be
3315 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
3317 To set up a @code{SVNPoller} that watches the Twisted trunk (and
3318 nothing else), we would use the following:
3320 @example
3321 from buildbot.changes.svnpoller import SVNPoller
3322 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
3323 @end example
3325 In this case, every Change that our @code{SVNPoller} produces will
3326 have @code{.branch=None}, to indicate that the Change is on the trunk.
3327 No other sub-projects or branches will be tracked.
3329 If we want our ChangeSource to follow multiple branches, we have to do
3330 two things. First we have to change our @code{svnurl=} argument to
3331 watch more than just ``.../Twisted/trunk''. We will set it to
3332 ``.../Twisted'' so that we'll see both the trunk and all the branches.
3333 Second, we have to tell @code{SVNPoller} how to split the
3334 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
3335 out into (BRANCH) and (FILEPATH) pairs.
3337 We do the latter by providing a ``split_file'' function. This function
3338 is responsible for splitting something like
3339 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
3340 @code{filepath}=''bin/trial''. This function is always given a string
3341 that names a file relative to the subdirectory pointed to by the
3342 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
3343 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
3344 branch indicated), or None to indicate that the file is outside any
3345 project of interest.
3347 (note that we want to see ``branches/1.5.x'' rather than just
3348 ``1.5.x'' because when we perform the SVN checkout, we will probably
3349 append the branch name to the baseURL, which requires that we keep the
3350 ``branches'' component in there. Other VC schemes use a different
3351 approach towards branches and may not require this artifact.)
3353 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
3354 scheme, the following function will work:
3356 @example
3357 def split_file_branches(path):
3358     pieces = path.split('/')
3359     if pieces[0] == 'trunk':
3360         return (None, '/'.join(pieces[1:]))
3361     elif pieces[0] == 'branches':
3362         return ('/'.join(pieces[0:2]),
3363                 '/'.join(pieces[2:]))
3364     else:
3365         return None
3366 @end example
3368 This function is provided as
3369 @code{buildbot.changes.svnpoller.split_file_branches} for your
3370 convenience. So to have our Twisted-watching @code{SVNPoller} follow
3371 multiple branches, we would use this:
3373 @example
3374 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
3375 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
3376                                split_file=split_file_branches)
3377 @end example
3379 Changes for all sorts of branches (with names like ``branches/1.5.x'',
3380 and None to indicate the trunk) will be delivered to the Schedulers.
3381 Each Scheduler is then free to use or ignore each branch as it sees
3382 fit.
3384 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
3386 Another common way to organize a Subversion repository is to put the
3387 branch name at the top, and the projects underneath. This is
3388 especially frequent when there are a number of related sub-projects
3389 that all get released in a group.
3391 For example, Divmod.org hosts a project named ``Nevow'' as well as one
3392 named ``Quotient''. In a checked-out Nevow tree there is a directory
3393 named ``formless'' that contains a python source file named
3394 ``webform.py''. This repository is accessible via webdav (and thus
3395 uses an ``http:'' scheme) through the divmod.org hostname. There are
3396 many branches in this repository, and they use a
3397 (BRANCHNAME)/(PROJECT) naming policy.
3399 The fully-qualified SVN URL for the trunk version of webform.py is
3400 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
3401 You can do an @code{svn co} with that URL and get a copy of the latest
3402 version. The 1.5.x branch version of this file would have a URL of
3403 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
3404 The whole Nevow trunk would be checked out with
3405 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
3406 trunk would be checked out using
3407 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
3409 Now suppose we want to have an @code{SVNPoller} that only cares about
3410 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
3411 described earlier:
3413 @example
3414 from buildbot.changes.svnpoller import SVNPoller
3415 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
3416 @end example
3418 But what happens when we want to track multiple Nevow branches? We
3419 have to point our @code{svnurl=} high enough to see all those
3420 branches, but we also don't want to include Quotient changes (since
3421 we're only building Nevow). To accomplish this, we must rely upon the
3422 @code{split_file} function to help us tell the difference between
3423 files that belong to Nevow and those that belong to Quotient, as well
3424 as figuring out which branch each one is on.
3426 @example
3427 from buildbot.changes.svnpoller import SVNPoller
3428 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
3429                                split_file=my_file_splitter)
3430 @end example
3432 The @code{my_file_splitter} function will be called with
3433 repository-relative pathnames like:
3435 @table @code
3436 @item trunk/Nevow/formless/webform.py
3437 This is a Nevow file, on the trunk. We want the Change that includes this
3438 to see a filename of @code{formless/webform.py"}, and a branch of None
3440 @item branches/1.5.x/Nevow/formless/webform.py
3441 This is a Nevow file, on a branch. We want to get
3442 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
3444 @item trunk/Quotient/setup.py
3445 This is a Quotient file, so we want to ignore it by having
3446 @code{my_file_splitter} return None.
3448 @item branches/1.5.x/Quotient/setup.py
3449 This is also a Quotient file, which should be ignored.
3450 @end table
3452 The following definition for @code{my_file_splitter} will do the job:
3454 @example
3455 def my_file_splitter(path):
3456     pieces = path.split('/')
3457     if pieces[0] == 'trunk':
3458         branch = None
3459         pieces.pop(0) # remove 'trunk'
3460     elif pieces[0] == 'branches':
3461         pieces.pop(0) # remove 'branches'
3462         # grab branch name
3463         branch = 'branches/' + pieces.pop(0)
3464     else:
3465         return None # something weird
3466     projectname = pieces.pop(0)
3467     if projectname != 'Nevow':
3468         return None # wrong project
3469     return (branch, '/'.join(pieces))
3470 @end example
3472 @node MercurialHook,  , SVNPoller, Getting Source Code Changes
3473 @section MercurialHook
3475 Since Mercurial is written in python, the hook script can invoke
3476 Buildbot's @code{sendchange} function directly, rather than having to
3477 spawn an external process. This function delivers the same sort of
3478 changes as @code{buildbot sendchange} and the various hook scripts in
3479 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
3480 buildmaster to receive these changes.
3482 To set this up, first choose a Mercurial repository that represents
3483 your central ``official'' source tree. This will be the same
3484 repository that your buildslaves will eventually pull from. Install
3485 Buildbot on the machine that hosts this repository, using the same
3486 version of python as Mercurial is using (so that the Mercurial hook
3487 can import code from buildbot). Then add the following to the
3488 @code{.hg/hgrc} file in that repository, replacing the buildmaster
3489 hostname/portnumber as appropriate for your buildbot:
3491 @example
3492 [hooks]
3493 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
3495 [hgbuildbot]
3496 master = buildmaster.example.org:9987
3497 @end example
3499 (Note that Mercurial lets you define multiple @code{changegroup} hooks
3500 by giving them distinct names, like @code{changegroup.foo} and
3501 @code{changegroup.bar}, which is why we use
3502 @code{changegroup.buildbot} in this example. There is nothing magical
3503 about the ``buildbot'' suffix in the hook name. The
3504 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
3505 only section that the buildbot hook pays attention to.)
3507 Also note that this runs as a @code{changegroup} hook, rather than as
3508 an @code{incoming} hook. The @code{changegroup} hook is run with
3509 multiple revisions at a time (say, if multiple revisions are being
3510 pushed to this repository in a single @command{hg push} command),
3511 whereas the @code{incoming} hook is run with just one revision at a
3512 time. The @code{hgbuildbot.hook} function will only work with the
3513 @code{changegroup} hook.
3515 The @code{[hgbuildbot]} section has two other parameters that you
3516 might specify, both of which control the name of the branch that is
3517 attached to the changes coming from this hook.
3519 One common branch naming policy for Mercurial repositories is to use
3520 it just like Darcs: each branch goes into a separate repository, and
3521 all the branches for a single project share a common parent directory.
3522 For example, you might have @file{/var/repos/PROJECT/trunk/} and
3523 @file{/var/repos/PROJECT/release}. To use this style, use the
3524 @code{branchtype = dirname} setting, which simply uses the last
3525 component of the repository's enclosing directory as the branch name:
3527 @example
3528 [hgbuildbot]
3529 master = buildmaster.example.org:9987
3530 branchtype = dirname
3531 @end example
3533 Another approach is to use Mercurial's built-in branches (the kind
3534 created with @command{hg branch} and listed with @command{hg
3535 branches}). This feature associates persistent names with particular
3536 lines of descent within a single repository. (note that the buildbot
3537 @code{source.Mercurial} checkout step does not yet support this kind
3538 of branch). To have the commit hook deliver this sort of branch name
3539 with the Change object, use @code{branchtype = inrepo}:
3541 @example
3542 [hgbuildbot]
3543 master = buildmaster.example.org:9987
3544 branchtype = inrepo
3545 @end example
3547 Finally, if you want to simply specify the branchname directly, for
3548 all changes, use @code{branch = BRANCHNAME}. This overrides
3549 @code{branchtype}:
3551 @example
3552 [hgbuildbot]
3553 master = buildmaster.example.org:9987
3554 branch = trunk
3555 @end example
3557 If you use @code{branch=} like this, you'll need to put a separate
3558 .hgrc in each repository. If you use @code{branchtype=}, you may be
3559 able to use the same .hgrc for all your repositories, stored in
3560 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
3563 @node Build Process, Status Delivery, Getting Source Code Changes, Top
3564 @chapter Build Process
3566 A @code{Build} object is responsible for actually performing a build.
3567 It gets access to a remote @code{SlaveBuilder} where it may run
3568 commands, and a @code{BuildStatus} object where it must emit status
3569 events. The @code{Build} is created by the Builder's
3570 @code{BuildFactory}.
3572 The default @code{Build} class is made up of a fixed sequence of
3573 @code{BuildSteps}, executed one after another until all are complete
3574 (or one of them indicates that the build should be halted early). The
3575 default @code{BuildFactory} creates instances of this @code{Build}
3576 class with a list of @code{BuildSteps}, so the basic way to configure
3577 the build is to provide a list of @code{BuildSteps} to your
3578 @code{BuildFactory}.
3580 More complicated @code{Build} subclasses can make other decisions:
3581 execute some steps only if certain files were changed, or if certain
3582 previous steps passed or failed. The base class has been written to
3583 allow users to express basic control flow without writing code, but
3584 you can always subclass and customize to achieve more specialized
3585 behavior.
3587 @menu
3588 * Build Steps::                 
3589 * Interlocks::                  
3590 * Build Factories::             
3591 @end menu
3593 @node Build Steps, Interlocks, Build Process, Build Process
3594 @section Build Steps
3596 @code{BuildStep}s are usually specified in the buildmaster's
3597 configuration file, in a list that goes into the @code{BuildFactory}.
3598 The @code{BuildStep} instances in this list are used as templates to
3599 construct new independent copies for each build (so that state can be
3600 kept on the @code{BuildStep} in one build without affecting a later
3601 build). Each @code{BuildFactory} can be created with a list of steps,
3602 or the factory can be created empty and then steps added to it using
3603 the @code{addStep} method:
3605 @example
3606 from buildbot.steps import source, shell
3607 from buildbot.process import factory
3609 f = factory.BuildFactory()
3610 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
3611 f.addStep(shell.ShellCommand(command=["make", "all"]))
3612 f.addStep(shell.ShellCommand(command=["make", "test"]))
3613 @end example
3615 In earlier versions (0.7.5 and older), these steps were specified with
3616 a tuple of (step_class, keyword_arguments). Steps can still be
3617 specified this way, but the preferred form is to pass actual
3618 @code{BuildStep} instances to @code{addStep}, because that gives the
3619 @code{BuildStep} class a chance to do some validation on the
3620 arguments.
3622 The rest of this section lists all the standard BuildStep objects
3623 available for use in a Build, and the parameters which can be used to
3624 control each.
3626 @menu
3627 * Common Parameters::           
3628 * Source Checkout::             
3629 * ShellCommand::                
3630 * Simple ShellCommand Subclasses::  
3631 * Python BuildSteps::           
3632 * Transferring Files::          
3633 * Writing New BuildSteps::      
3634 @end menu
3636 @node Common Parameters, Source Checkout, Build Steps, Build Steps
3637 @subsection Common Parameters
3639 The standard @code{Build} runs a series of @code{BuildStep}s in order,
3640 only stopping when it runs out of steps or if one of them requests
3641 that the build be halted. It collects status information from each one
3642 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
3644 All BuildSteps accept some common parameters. Some of these control
3645 how their individual status affects the overall build. Others are used
3646 to specify which @code{Locks} (see @pxref{Interlocks}) should be
3647 acquired before allowing the step to run.
3649 Arguments common to all @code{BuildStep} subclasses:
3652 @table @code
3653 @item name
3654 the name used to describe the step on the status display. It is also
3655 used to give a name to any LogFiles created by this step.
3657 @item haltOnFailure
3658 if True, a FAILURE of this build step will cause the build to halt
3659 immediately with an overall result of FAILURE.
3661 @item flunkOnWarnings
3662 when True, a WARNINGS or FAILURE of this build step will mark the
3663 overall build as FAILURE. The remaining steps will still be executed.
3665 @item flunkOnFailure
3666 when True, a FAILURE of this build step will mark the overall build as
3667 a FAILURE. The remaining steps will still be executed.
3669 @item warnOnWarnings
3670 when True, a WARNINGS or FAILURE of this build step will mark the
3671 overall build as having WARNINGS. The remaining steps will still be
3672 executed.
3674 @item warnOnFailure
3675 when True, a FAILURE of this build step will mark the overall build as
3676 having WARNINGS. The remaining steps will still be executed.
3678 @item locks
3679 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
3680 @code{buildbot.locks.MasterLock}) that should be acquired before
3681 starting this Step. The Locks will be released when the step is
3682 complete. Note that this is a list of actual Lock instances, not
3683 names. Also note that all Locks must have unique names.
3685 @end table
3688 @node Source Checkout, ShellCommand, Common Parameters, Build Steps
3689 @subsection Source Checkout
3691 The first step of any build is typically to acquire the source code
3692 from which the build will be performed. There are several classes to
3693 handle this, one for each of the different source control system that
3694 Buildbot knows about. For a description of how Buildbot treats source
3695 control in general, see @ref{Version Control Systems}.
3697 All source checkout steps accept some common parameters to control how
3698 they get the sources and where they should be placed. The remaining
3699 per-VC-system parameters are mostly to specify where exactly the
3700 sources are coming from.
3702 @table @code
3703 @item mode
3705 a string describing the kind of VC operation that is desired. Defaults
3706 to @code{update}.
3708 @table @code
3709 @item update
3710 specifies that the CVS checkout/update should be performed directly
3711 into the workdir. Each build is performed in the same directory,
3712 allowing for incremental builds. This minimizes disk space, bandwidth,
3713 and CPU time. However, it may encounter problems if the build process
3714 does not handle dependencies properly (sometimes you must do a ``clean
3715 build'' to make sure everything gets compiled), or if source files are
3716 deleted but generated files can influence test behavior (e.g. python's
3717 .pyc files), or when source directories are deleted but generated
3718 files prevent CVS from removing them. Builds ought to be correct
3719 regardless of whether they are done ``from scratch'' or incrementally,
3720 but it is useful to test both kinds: this mode exercises the
3721 incremental-build style.
3723 @item copy
3724 specifies that the CVS workspace should be maintained in a separate
3725 directory (called the 'copydir'), using checkout or update as
3726 necessary. For each build, a new workdir is created with a copy of the
3727 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
3728 disk space required, but keeps the bandwidth low (update instead of a
3729 full checkout). A full 'clean' build is performed each time. This
3730 avoids any generated-file build problems, but is still occasionally
3731 vulnerable to CVS problems such as a repository being manually
3732 rearranged, causing CVS errors on update which are not an issue with a
3733 full checkout.
3735 @c TODO: something is screwy about this, revisit. Is it the source
3736 @c directory or the working directory that is deleted each time?
3738 @item clobber
3739 specifes that the working directory should be deleted each time,
3740 necessitating a full checkout for each build. This insures a clean
3741 build off a complete checkout, avoiding any of the problems described
3742 above. This mode exercises the ``from-scratch'' build style.
3744 @item export
3745 this is like @code{clobber}, except that the 'cvs export' command is
3746 used to create the working directory. This command removes all CVS
3747 metadata files (the CVS/ directories) from the tree, which is
3748 sometimes useful for creating source tarballs (to avoid including the
3749 metadata in the tar file).
3750 @end table
3752 @item workdir
3753 like all Steps, this indicates the directory where the build will take
3754 place. Source Steps are special in that they perform some operations
3755 outside of the workdir (like creating the workdir itself).
3757 @item alwaysUseLatest
3758 if True, bypass the usual ``update to the last Change'' behavior, and
3759 always update to the latest changes instead.
3761 @item retry
3762 If set, this specifies a tuple of @code{(delay, repeats)} which means
3763 that when a full VC checkout fails, it should be retried up to
3764 @var{repeats} times, waiting @var{delay} seconds between attempts. If
3765 you don't provide this, it defaults to @code{None}, which means VC
3766 operations should not be retried. This is provided to make life easier
3767 for buildslaves which are stuck behind poor network connections.
3769 @end table
3772 My habit as a developer is to do a @code{cvs update} and @code{make} each
3773 morning. Problems can occur, either because of bad code being checked in, or
3774 by incomplete dependencies causing a partial rebuild to fail where a
3775 complete from-scratch build might succeed. A quick Builder which emulates
3776 this incremental-build behavior would use the @code{mode='update'}
3777 setting.
3779 On the other hand, other kinds of dependency problems can cause a clean
3780 build to fail where a partial build might succeed. This frequently results
3781 from a link step that depends upon an object file that was removed from a
3782 later version of the tree: in the partial tree, the object file is still
3783 around (even though the Makefiles no longer know how to create it).
3785 ``official'' builds (traceable builds performed from a known set of
3786 source revisions) are always done as clean builds, to make sure it is
3787 not influenced by any uncontrolled factors (like leftover files from a
3788 previous build). A ``full'' Builder which behaves this way would want
3789 to use the @code{mode='clobber'} setting.
3791 Each VC system has a corresponding source checkout class: their
3792 arguments are described on the following pages.
3795 @menu
3796 * CVS::                         
3797 * SVN::                         
3798 * Darcs::                       
3799 * Mercurial::                   
3800 * Arch::                        
3801 * Bazaar::                      
3802 * Bzr::                         
3803 * P4::                          
3804 @end menu
3806 @node CVS, SVN, Source Checkout, Source Checkout
3807 @subsubsection CVS
3808 @cindex CVS Checkout
3809 @bsindex buildbot.steps.source.CVS
3812 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
3813 CVS} checkout or update. It takes the following arguments:
3815 @table @code
3816 @item cvsroot
3817 (required): specify the CVSROOT value, which points to a CVS
3818 repository, probably on a remote machine. For example, the cvsroot
3819 value you would use to get a copy of the Buildbot source code is
3820 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
3822 @item cvsmodule
3823 (required): specify the cvs @code{module}, which is generally a
3824 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
3825 code is @code{buildbot}.
3827 @item branch
3828 a string which will be used in a @code{-r} argument. This is most
3829 useful for specifying a branch to work on. Defaults to @code{HEAD}.
3831 @item global_options
3832 a list of flags to be put before the verb in the CVS command.
3834 @item checkoutDelay
3835 if set, the number of seconds to put between the timestamp of the last
3836 known Change and the value used for the @code{-D} option. Defaults to
3837 half of the parent Build's treeStableTimer.
3839 @end table
3842 @node SVN, Darcs, CVS, Source Checkout
3843 @subsubsection SVN
3845 @cindex SVN Checkout
3846 @bsindex buildbot.steps.source.SVN
3849 The @code{SVN} build step performs a
3850 @uref{http://subversion.tigris.org, Subversion} checkout or update.
3851 There are two basic ways of setting up the checkout step, depending
3852 upon whether you are using multiple branches or not.
3854 If all of your builds use the same branch, then you should create the
3855 @code{SVN} step with the @code{svnurl} argument:
3857 @table @code
3858 @item svnurl
3859 (required): this specifies the @code{URL} argument that will be given
3860 to the @code{svn checkout} command. It dictates both where the
3861 repository is located and which sub-tree should be extracted. In this
3862 respect, it is like a combination of the CVS @code{cvsroot} and
3863 @code{cvsmodule} arguments. For example, if you are using a remote
3864 Subversion repository which is accessible through HTTP at a URL of
3865 @code{http://svn.example.com/repos}, and you wanted to check out the
3866 @code{trunk/calc} sub-tree, you would use
3867 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
3868 to your @code{SVN} step.
3869 @end table
3871 If, on the other hand, you are building from multiple branches, then
3872 you should create the @code{SVN} step with the @code{baseURL} and
3873 @code{defaultBranch} arguments instead:
3875 @table @code
3876 @item baseURL
3877 (required): this specifies the base repository URL, to which a branch
3878 name will be appended. It should probably end in a slash.
3880 @item defaultBranch
3881 this specifies the name of the branch to use when a Build does not
3882 provide one of its own. This will be appended to @code{baseURL} to
3883 create the string that will be passed to the @code{svn checkout}
3884 command.
3885 @end table
3887 If you are using branches, you must also make sure your
3888 @code{ChangeSource} will report the correct branch names.
3890 @heading branch example
3892 Let's suppose that the ``MyProject'' repository uses branches for the
3893 trunk, for various users' individual development efforts, and for
3894 several new features that will require some amount of work (involving
3895 multiple developers) before they are ready to merge onto the trunk.
3896 Such a repository might be organized as follows:
3898 @example
3899 svn://svn.example.org/MyProject/trunk
3900 svn://svn.example.org/MyProject/branches/User1/foo
3901 svn://svn.example.org/MyProject/branches/User1/bar
3902 svn://svn.example.org/MyProject/branches/User2/baz
3903 svn://svn.example.org/MyProject/features/newthing
3904 svn://svn.example.org/MyProject/features/otherthing
3905 @end example
3907 Further assume that we want the Buildbot to run tests against the
3908 trunk and against all the feature branches (i.e., do a
3909 checkout/compile/build of branch X when a file has been changed on
3910 branch X, when X is in the set [trunk, features/newthing,
3911 features/otherthing]). We do not want the Buildbot to automatically
3912 build any of the user branches, but it should be willing to build a
3913 user branch when explicitly requested (most likely by the user who
3914 owns that branch).
3916 There are three things that need to be set up to accomodate this
3917 system. The first is a ChangeSource that is capable of identifying the
3918 branch which owns any given file. This depends upon a user-supplied
3919 function, in an external program that runs in the SVN commit hook and
3920 connects to the buildmaster's @code{PBChangeSource} over a TCP
3921 connection. (you can use the ``@code{buildbot sendchange}'' utility
3922 for this purpose, but you will still need an external program to
3923 decide what value should be passed to the @code{--branch=} argument).
3924 For example, a change to a file with the SVN url of
3925 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
3926 be broken down into a Change instance with
3927 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
3929 The second piece is an @code{AnyBranchScheduler} which will pay
3930 attention to the desired branches. It will not pay attention to the
3931 user branches, so it will not automatically start builds in response
3932 to changes there. The AnyBranchScheduler class requires you to
3933 explicitly list all the branches you want it to use, but it would not
3934 be difficult to write a subclass which used
3935 @code{branch.startswith('features/'} to remove the need for this
3936 explicit list. Or, if you want to build user branches too, you can use
3937 AnyBranchScheduler with @code{branches=None} to indicate that you want
3938 it to pay attention to all branches.
3940 The third piece is an @code{SVN} checkout step that is configured to
3941 handle the branches correctly, with a @code{baseURL} value that
3942 matches the way the ChangeSource splits each file's URL into base,
3943 branch, and file.
3945 @example
3946 from buildbot.changes.pb import PBChangeSource
3947 from buildbot.scheduler import AnyBranchScheduler
3948 from buildbot.process import source, factory
3949 from buildbot.steps import source, shell
3951 c['change_source'] = PBChangeSource()
3952 s1 = AnyBranchScheduler('main',
3953                         ['trunk', 'features/newthing', 'features/otherthing'],
3954                         10*60, ['test-i386', 'test-ppc'])
3955 c['schedulers'] = [s1]
3957 f = factory.BuildFactory()
3958 f.addStep(source.SVN(mode='update',
3959                      baseURL='svn://svn.example.org/MyProject/',
3960                      defaultBranch='trunk'))
3961 f.addStep(shell.Compile(command="make all"))
3962 f.addStep(shell.Test(command="make test"))
3964 c['builders'] = [
3965   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
3966                        'factory':f @},
3967   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
3968                       'factory':f @},
3970 @end example
3972 In this example, when a change arrives with a @code{branch} attribute
3973 of ``trunk'', the resulting build will have an SVN step that
3974 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
3975 ``trunk'' (the branch name) to get the correct svn command. If the
3976 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
3977 will concatenate ``svn://svn.example.org/MyProject/'' with
3978 ``features/newthing'' to get the svnurl for checkout.
3980 @node Darcs, Mercurial, SVN, Source Checkout
3981 @subsubsection Darcs
3983 @cindex Darcs Checkout
3984 @bsindex buildbot.steps.source.Darcs
3987 The @code{Darcs} build step performs a
3988 @uref{http://darcs.net/, Darcs} checkout or update.
3990 Like @xref{SVN}, this step can either be configured to always check
3991 out a specific tree, or set up to pull from a particular branch that
3992 gets specified separately for each build. Also like SVN, the
3993 repository URL given to Darcs is created by concatenating a
3994 @code{baseURL} with the branch name, and if no particular branch is
3995 requested, it uses a @code{defaultBranch}. The only difference in
3996 usage is that each potential Darcs repository URL must point to a
3997 fully-fledged repository, whereas SVN URLs usually point to sub-trees
3998 of the main Subversion repository. In other words, doing an SVN
3999 checkout of @code{baseURL} is legal, but silly, since you'd probably
4000 wind up with a copy of every single branch in the whole repository.
4001 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
4002 the parent directory of a collection of Darcs repositories is not
4003 itself a valid repository.
4005 The Darcs step takes the following arguments:
4007 @table @code
4008 @item repourl
4009 (required unless @code{baseURL} is provided): the URL at which the
4010 Darcs source repository is available.
4012 @item baseURL
4013 (required unless @code{repourl} is provided): the base repository URL,
4014 to which a branch name will be appended. It should probably end in a
4015 slash.
4017 @item defaultBranch
4018 (allowed if and only if @code{baseURL} is provided): this specifies
4019 the name of the branch to use when a Build does not provide one of its
4020 own. This will be appended to @code{baseURL} to create the string that
4021 will be passed to the @code{darcs get} command.
4022 @end table
4024 @node Mercurial, Arch, Darcs, Source Checkout
4025 @subsubsection Mercurial
4027 @cindex Mercurial Checkout
4028 @bsindex buildbot.steps.source.Mercurial
4031 The @code{Mercurial} build step performs a
4032 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
4033 or update.
4035 Branches are handled just like @xref{Darcs}.
4037 The Mercurial step takes the following arguments:
4039 @table @code
4040 @item repourl
4041 (required unless @code{baseURL} is provided): the URL at which the
4042 Mercurial source repository is available.
4044 @item baseURL
4045 (required unless @code{repourl} is provided): the base repository URL,
4046 to which a branch name will be appended. It should probably end in a
4047 slash.
4049 @item defaultBranch
4050 (allowed if and only if @code{baseURL} is provided): this specifies
4051 the name of the branch to use when a Build does not provide one of its
4052 own. This will be appended to @code{baseURL} to create the string that
4053 will be passed to the @code{hg clone} command.
4054 @end table
4057 @node Arch, Bazaar, Mercurial, Source Checkout
4058 @subsubsection Arch
4060 @cindex Arch Checkout
4061 @bsindex buildbot.steps.source.Arch
4064 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
4065 Arch} checkout or update using the @code{tla} client. It takes the
4066 following arguments:
4068 @table @code
4069 @item url
4070 (required): this specifies the URL at which the Arch source archive is
4071 available.
4073 @item version
4074 (required): this specifies which ``development line'' (like a branch)
4075 should be used. This provides the default branch name, but individual
4076 builds may specify a different one.
4078 @item archive
4079 (optional): Each repository knows its own archive name. If this
4080 parameter is provided, it must match the repository's archive name.
4081 The parameter is accepted for compatibility with the @code{Bazaar}
4082 step, below.
4084 @end table
4086 @node Bazaar, Bzr, Arch, Source Checkout
4087 @subsubsection Bazaar
4089 @cindex Bazaar Checkout
4090 @bsindex buildbot.steps.source.Bazaar
4093 @code{Bazaar} is an alternate implementation of the Arch VC system,
4094 which uses a client named @code{baz}. The checkout semantics are just
4095 different enough from @code{tla} that there is a separate BuildStep for
4098 It takes exactly the same arguments as @code{Arch}, except that the
4099 @code{archive=} parameter is required. (baz does not emit the archive
4100 name when you do @code{baz register-archive}, so we must provide it
4101 ourselves).
4104 @node Bzr, P4, Bazaar, Source Checkout
4105 @subsubsection Bzr
4107 @cindex Bzr Checkout
4108 @bsindex buildbot.steps.source.Bzr
4110 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
4111 as simply ``Bazaar''. The repository-vs-workspace model is similar to
4112 Darcs, but it uses a strictly linear sequence of revisions (one
4113 history per branch) like Arch. Branches are put in subdirectories.
4114 This makes it look very much like Mercurial, so it takes the same
4115 arguments:
4117 @table @code
4119 @item repourl
4120 (required unless @code{baseURL} is provided): the URL at which the
4121 Bzr source repository is available.
4123 @item baseURL
4124 (required unless @code{repourl} is provided): the base repository URL,
4125 to which a branch name will be appended. It should probably end in a
4126 slash.
4128 @item defaultBranch
4129 (allowed if and only if @code{baseURL} is provided): this specifies
4130 the name of the branch to use when a Build does not provide one of its
4131 own. This will be appended to @code{baseURL} to create the string that
4132 will be passed to the @code{bzr checkout} command.
4133 @end table
4137 @node P4,  , Bzr, Source Checkout
4138 @subsubsection P4
4140 @cindex Perforce Update
4141 @bsindex buildbot.steps.source.P4
4142 @c TODO @bsindex buildbot.steps.source.P4Sync
4145 The @code{P4} build step creates a @uref{http://www.perforce.com/,
4146 Perforce} client specification and performs an update.
4148 @table @code
4149 @item p4base
4150 A view into the Perforce depot without branch name or trailing "...".
4151 Typically "//depot/proj/".
4152 @item defaultBranch
4153 A branch name to append on build requests if none is specified.
4154 Typically "trunk".
4155 @item p4port
4156 (optional): the host:port string describing how to get to the P4 Depot
4157 (repository), used as the -p argument for all p4 commands.
4158 @item p4user
4159 (optional): the Perforce user, used as the -u argument to all p4
4160 commands.
4161 @item p4passwd
4162 (optional): the Perforce password, used as the -p argument to all p4
4163 commands.
4164 @item p4extra_views
4165 (optional): a list of (depotpath, clientpath) tuples containing extra
4166 views to be mapped into the client specification. Both will have
4167 "/..." appended automatically. The client name and source directory
4168 will be prepended to the client path.
4169 @item p4client
4170 (optional): The name of the client to use. In mode='copy' and
4171 mode='update', it's particularly important that a unique name is used
4172 for each checkout directory to avoid incorrect synchronization. For
4173 this reason, Python percent substitution will be performed on this value
4174 to replace %(slave)s with the slave name and %(builder)s with the
4175 builder name. The default is "buildbot_%(slave)s_%(build)s".
4176 @end table
4178 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
4179 @subsection ShellCommand
4181 @bsindex buildbot.steps.shell.ShellCommand
4182 @c TODO @bsindex buildbot.steps.shell.TreeSize
4184 This is a useful base class for just about everything you might want
4185 to do during a build (except for the initial source checkout). It runs
4186 a single command in a child shell on the buildslave. All stdout/stderr
4187 is recorded into a LogFile. The step finishes with a status of FAILURE
4188 if the command's exit code is non-zero, otherwise it has a status of
4189 SUCCESS.
4191 The preferred way to specify the command is with a list of argv strings,
4192 since this allows for spaces in filenames and avoids doing any fragile
4193 shell-escaping. You can also specify the command with a single string, in
4194 which case the string is given to '/bin/sh -c COMMAND' for parsing.
4196 All ShellCommands are run by default in the ``workdir'', which
4197 defaults to the ``@file{build}'' subdirectory of the slave builder's
4198 base directory. The absolute path of the workdir will thus be the
4199 slave's basedir (set as an option to @code{buildbot create-slave},
4200 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
4201 builder's @code{c['builddir']} key in master.cfg) plus the workdir
4202 itself (a class-level attribute of the BuildFactory, defaults to
4203 ``@file{build}'').
4205 @code{ShellCommand} arguments:
4207 @table @code
4208 @item command
4209 a list of strings (preferred) or single string (discouraged) which
4210 specifies the command to be run. A list of strings is preferred
4211 because it can be used directly as an argv array. Using a single
4212 string (with embedded spaces) requires the buildslave to pass the
4213 string to /bin/sh for interpretation, which raises all sorts of
4214 difficult questions about how to escape or interpret shell
4215 metacharacters.
4217 @item env
4218 a dictionary of environment strings which will be added to the child
4219 command's environment. For example, to run tests with a different i18n
4220 language setting, you might use
4222 @example
4223 f.addStep(ShellCommand, command=["make", "test"],
4224           env=@{'LANG': 'fr_FR'@})
4225 @end example
4227 These variable settings will override any existing ones in the
4228 buildslave's environment. The exception is PYTHONPATH, which is merged
4229 with (actually prepended to) any existing $PYTHONPATH setting. The
4230 value is treated as a list of directories to prepend, and a single
4231 string is treated like a one-item list. For example, to prepend both
4232 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
4233 to any existing $PYTHONPATH setting, you would do something like the
4234 following:
4236 @example
4237 f.addStep(ShellCommand, command=["make", "test"],
4238           env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
4239                               "/home/buildbot/lib/python"] @})
4240 @end example
4242 @item want_stdout
4243 if False, stdout from the child process is discarded rather than being
4244 sent to the buildmaster for inclusion in the step's LogFile.
4246 @item want_stderr
4247 like @code{want_stdout} but for stderr. Note that commands run through
4248 a PTY do not have separate stdout/stderr streams: both are merged into
4249 stdout.
4251 @item logfiles
4252 Sometimes commands will log interesting data to a local file, rather
4253 than emitting everything to stdout or stderr. For example, Twisted's
4254 ``trial'' command (which runs unit tests) only presents summary
4255 information to stdout, and puts the rest into a file named
4256 @file{_trial_temp/test.log}. It is often useful to watch these files
4257 as the command runs, rather than using @command{/bin/cat} to dump
4258 their contents afterwards.
4260 The @code{logfiles=} argument allows you to collect data from these
4261 secondary logfiles in near-real-time, as the step is running. It
4262 accepts a dictionary which maps from a local Log name (which is how
4263 the log data is presented in the build results) to a remote filename
4264 (interpreted relative to the build's working directory). Each named
4265 file will be polled on a regular basis (every couple of seconds) as
4266 the build runs, and any new text will be sent over to the buildmaster.
4268 @example
4269 f.addStep(ShellCommand, command=["make", "test"],
4270           logfiles=@{"triallog": "_trial_temp/test.log"@})
4271 @end example
4274 @item timeout
4275 if the command fails to produce any output for this many seconds, it
4276 is assumed to be locked up and will be killed.
4278 @item description
4279 This will be used to describe the command (on the Waterfall display)
4280 while the command is still running. It should be a single
4281 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
4282 form is a list of short strings, which allows the HTML Waterfall
4283 display to create narrower columns by emitting a <br> tag between each
4284 word. You may also provide a single string.
4286 @item descriptionDone
4287 This will be used to describe the command once it has finished. A
4288 simple noun like ``compile'' or ``tests'' should be used. Like
4289 @code{description}, this may either be a list of short strings or a
4290 single string.
4292 If neither @code{description} nor @code{descriptionDone} are set, the
4293 actual command arguments will be used to construct the description.
4294 This may be a bit too wide to fit comfortably on the Waterfall
4295 display.
4297 @example
4298 f.addStep(ShellCommand, command=["make", "test"],
4299           description=["testing"],
4300           descriptionDone=["tests"])
4301 @end example
4303 @end table
4305 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
4306 @subsection Simple ShellCommand Subclasses
4308 Several subclasses of ShellCommand are provided as starting points for
4309 common build steps. These are all very simple: they just override a few
4310 parameters so you don't have to specify them yourself, making the master.cfg
4311 file less verbose.
4313 @menu
4314 * Configure::                   
4315 * Compile::                     
4316 * Test::                        
4317 * Build Properties::            
4318 @end menu
4320 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
4321 @subsubsection Configure
4323 @bsindex buildbot.steps.shell.Configure
4325 This is intended to handle the @code{./configure} step from
4326 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
4327 MakeMaker.pm-style modules. The default command is @code{./configure}
4328 but you can change this by providing a @code{command=} parameter.
4330 @node Compile, Test, Configure, Simple ShellCommand Subclasses
4331 @subsubsection Compile
4333 @bsindex buildbot.steps.shell.Compile
4335 This is meant to handle compiling or building a project written in C. The
4336 default command is @code{make all}. When the compile is finished, the
4337 log file is scanned for GCC error/warning messages and a summary log is
4338 created with any problems that were seen (TODO: the summary is not yet
4339 created).
4341 @node Test, Build Properties, Compile, Simple ShellCommand Subclasses
4342 @subsubsection Test
4344 @bsindex buildbot.steps.shell.Test
4346 This is meant to handle unit tests. The default command is @code{make
4347 test}, and the @code{warnOnFailure} flag is set.
4351 @node Build Properties,  , Test, Simple ShellCommand Subclasses
4352 @subsubsection Build Properties
4354 @cindex build properties
4356 Each build has a set of ``Build Properties'', which can be used by its
4357 BuildStep to modify their actions. For example, the SVN revision
4358 number of the source code being built is available as a build
4359 property, and a ShellCommand step could incorporate this number into a
4360 command which create a numbered release tarball.
4362 Some build properties are set when the build starts, such as the
4363 SourceStamp information. Other properties can be set by BuildSteps as
4364 they run, for example the various Source steps will set the
4365 @code{got_revision} property to the source revision that was actually
4366 checked out (which can be useful when the SourceStamp in use merely
4367 requested the ``latest revision'': @code{got_revision} will tell you
4368 what was actually built).
4370 In custom BuildSteps, you can get and set the build properties with
4371 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4372 for the name of the property, and returns or accepts an
4373 arbitrary@footnote{Build properties are serialized along with the
4374 build results, so they must be serializable. For this reason, the
4375 value of any build property should be simple inert data: strings,
4376 numbers, lists, tuples, and dictionaries. They should not contain
4377 class instances.} object. For example:
4379 @example
4380 class MakeTarball(ShellCommand):
4381     def start(self):
4382         self.setCommand(["tar", "czf",
4383                          "build-%s.tar.gz" % self.getProperty("revision"),
4384                          "source"])
4385         ShellCommand.start(self)
4386 @end example
4388 @cindex WithProperties
4390 You can use build properties in ShellCommands by using the
4391 @code{WithProperties} wrapper when setting the arguments of the
4392 ShellCommand. This interpolates the named build properties into the
4393 generated shell command. You can also use a @code{WithProperties} as
4394 the @code{workdir=} argument: this allows the working directory for a
4395 command to be varied for each build, depending upon various build
4396 properties.
4398 @example
4399 from buildbot.steps.shell import ShellCommand, WithProperties
4401 f.addStep(ShellCommand,
4402           command=["tar", "czf",
4403                    WithProperties("build-%s.tar.gz", "revision"),
4404                    "source"])
4405 @end example
4407 If this BuildStep were used in a tree obtained from Subversion, it
4408 would create a tarball with a name like @file{build-1234.tar.gz}.
4410 The @code{WithProperties} function does @code{printf}-style string
4411 interpolation, using strings obtained by calling
4412 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4413 @code{%d}, etc), you must have exactly one additional argument to
4414 indicate which build property you want to insert.
4417 You can also use python dictionary-style string interpolation by using
4418 the @code{%(propname)s} syntax. In this form, the property name goes
4419 in the parentheses, and WithProperties takes @emph{no} additional
4420 arguments:
4422 @example
4423 f.addStep(ShellCommand,
4424           command=["tar", "czf",
4425                    WithProperties("build-%(revision)s.tar.gz"),
4426                    "source"])
4427 @end example
4429 Don't forget the extra ``s'' after the closing parenthesis! This is
4430 the cause of many confusing errors. Also note that you can only use
4431 WithProperties in the list form of the command= definition. You cannot
4432 currently use it in the (discouraged) @code{command="stuff"}
4433 single-string form. However, you can use something like
4434 @code{command=["/bin/sh", "-c", "stuff", WithProperties(stuff)]} to
4435 use both shell expansion and WithProperties interpolation.
4437 Note that, like python, you can either do positional-argument
4438 interpolation @emph{or} keyword-argument interpolation, not both. Thus
4439 you cannot use a string like
4440 @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4442 At the moment, the only way to set build properties is by writing a
4443 custom BuildStep.
4445 @heading Common Build Properties
4447 The following build properties are set when the build is started, and
4448 are available to all steps.
4450 @table @code
4451 @item branch
4453 This comes from the build's SourceStamp, and describes which branch is
4454 being checked out. This will be @code{None} (which interpolates into
4455 @code{WithProperties} as an empty string) if the build is on the
4456 default branch, which is generally the trunk. Otherwise it will be a
4457 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4458 system being used.
4460 @item revision
4462 This also comes from the SourceStamp, and is the revision of the
4463 source code tree that was requested from the VC system. When a build
4464 is requested of a specific revision (as is generally the case when the
4465 build is triggered by Changes), this will contain the revision
4466 specification. The syntax depends upon the VC system in use: for SVN
4467 it is an integer, for Mercurial it is a short string, for Darcs it is
4468 a rather large string, etc.
4470 If the ``force build'' button was pressed, the revision will be
4471 @code{None}, which means to use the most recent revision available.
4472 This is a ``trunk build''. This will be interpolated as an empty
4473 string.
4475 @item got_revision
4477 This is set when a Source step checks out the source tree, and
4478 provides the revision that was actually obtained from the VC system.
4479 In general this should be the same as @code{revision}, except for
4480 trunk builds, where @code{got_revision} indicates what revision was
4481 current when the checkout was performed. This can be used to rebuild
4482 the same source code later.
4484 Note that for some VC systems (Darcs in particular), the revision is a
4485 large string containing newlines, and is not suitable for
4486 interpolation into a filename.
4488 @item buildername
4490 This is a string that indicates which Builder the build was a part of.
4491 The combination of buildername and buildnumber uniquely identify a
4492 build.
4494 @item buildnumber
4496 Each build gets a number, scoped to the Builder (so the first build
4497 performed on any given Builder will have a build number of 0). This
4498 integer property contains the build's number.
4500 @item slavename
4502 This is a string which identifies which buildslave the build is
4503 running on.
4505 @end table
4507 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
4508 @subsection Python BuildSteps
4510 Here are some BuildSteps that are specifcally useful for projects
4511 implemented in Python.
4513 @menu
4514 * BuildEPYDoc::                 
4515 * PyFlakes::                    
4516 @end menu
4518 @node BuildEPYDoc, PyFlakes, Python BuildSteps, Python BuildSteps
4519 @subsubsection BuildEPYDoc
4521 @bsindex buildbot.steps.python.BuildEPYDoc
4523 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
4524 API documentation for Python modules from their docstrings. It reads
4525 all the .py files from your source tree, processes the docstrings
4526 therein, and creates a large tree of .html files (or a single .pdf
4527 file).
4529 The @code{buildbot.steps.python.BuildEPYDoc} step will run
4530 @command{epydoc} to produce this API documentation, and will count the
4531 errors and warnings from its output.
4533 You must supply the command line to be used. The default is
4534 @command{make epydocs}, which assumes that your project has a Makefile
4535 with an ``epydocs'' target. You might wish to use something like
4536 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
4537 to add @command{--pdf} to generate a PDF file instead of a large tree
4538 of HTML files.
4540 The API docs are generated in-place in the build tree (under the
4541 workdir, in the subdirectory controlled by the ``-o'' argument). To
4542 make them useful, you will probably have to copy them to somewhere
4543 they can be read. A command like @command{rsync -ad apiref/
4544 dev.example.com:~public_html/current-apiref/} might be useful. You
4545 might instead want to bundle them into a tarball and publish it in the
4546 same place where the generated install tarball is placed.
4548 @example
4549 from buildbot.steps.python import BuildEPYDoc
4552 f.addStep(BuildEPYDoc, command=["epydoc", "-o", "apiref", "source/mypkg"])
4553 @end example
4556 @node PyFlakes,  , BuildEPYDoc, Python BuildSteps
4557 @subsubsection PyFlakes
4559 @bsindex buildbot.steps.python.PyFlakes
4561 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
4562 to perform basic static analysis of Python code to look for simple
4563 errors, like missing imports and references of undefined names. It is
4564 like a fast and simple form of the C ``lint'' program. Other tools
4565 (like pychecker) provide more detailed results but take longer to run.
4567 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
4568 count the various kinds of errors and warnings it detects.
4570 You must supply the command line to be used. The default is
4571 @command{make pyflakes}, which assumes you have a top-level Makefile
4572 with a ``pyflakes'' target. You might want to use something like
4573 @command{pyflakes .} or @command{pyflakes src}.
4575 @example
4576 from buildbot.steps.python import PyFlakes
4579 f.addStep(PyFlakes, command=["pyflakes", "src"])
4580 @end example
4583 @node Transferring Files, Writing New BuildSteps, Python BuildSteps, Build Steps
4584 @subsection Transferring Files
4586 @cindex File Transfer
4587 @bsindex buildbot.steps.transfer.FileUpload
4588 @bsindex buildbot.steps.transfer.FileDownload
4590 Most of the work involved in a build will take place on the
4591 buildslave. But occasionally it is useful to do some work on the
4592 buildmaster side. The most basic way to involve the buildmaster is
4593 simply to move a file from the slave to the master, or vice versa.
4594 There are a pair of BuildSteps named @code{FileUpload} and
4595 @code{FileDownload} to provide this functionality. @code{FileUpload}
4596 moves a file @emph{up to} the master, while @code{FileDownload} moves
4597 a file @emph{down from} the master.
4599 As an example, let's assume that there is a step which produces an
4600 HTML file within the source tree that contains some sort of generated
4601 project documentation. We want to move this file to the buildmaster,
4602 into a @file{~/public_html} directory, so it can be visible to
4603 developers. This file will wind up in the slave-side working directory
4604 under the name @file{docs/reference.html}. We want to put it into the
4605 master-side @file{~/public_html/ref.html}.
4607 @example
4608 from buildbot.steps.shell import ShellCommand
4609 from buildbot.steps.transfer import FileUpload
4611 f.addStep(ShellCommand, command=["make", "docs"])
4612 f.addStep(FileUpload,
4613           slavesrc="docs/reference.html",
4614           masterdest="~/public_html/ref.html")
4615 @end example
4617 The @code{masterdest=} argument will be passed to os.path.expanduser,
4618 so things like ``~'' will be expanded properly. Non-absolute paths
4619 will be interpreted relative to the buildmaster's base directory.
4620 Likewise, the @code{slavesrc=} argument will be expanded and
4621 interpreted relative to the builder's working directory.
4624 To move a file from the master to the slave, use the
4625 @code{FileDownload} command. For example, let's assume that some step
4626 requires a configuration file that, for whatever reason, could not be
4627 recorded in the source code repository or generated on the buildslave
4628 side:
4630 @example
4631 from buildbot.steps.shell import ShellCommand
4632 from buildbot.steps.transfer import FileUpload
4634 f.addStep(FileDownload
4635           mastersrc="~/todays_build_config.txt",
4636           slavedest="build_config.txt")
4637 f.addStep(ShellCommand, command=["make", "config"])
4638 @end example
4640 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
4641 relative to the buildmaster's base directory, and the
4642 @code{slavedest=} argument is relative to the builder's working
4643 directory. If the buildslave is running in @file{~buildslave}, and the
4644 builder's ``builddir'' is something like @file{tests-i386}, then the
4645 workdir is going to be @file{~buildslave/tests-i386/build}, and a
4646 @code{slavedest=} of @file{foo/bar.html} will get put in
4647 @file{~buildslave/tests-i386/build/foo/bar.html}. Remember that
4648 neither of these commands will create missing directories for you.
4651 @subheading Other Parameters
4653 The @code{maxsize=} argument lets you set a maximum size for the file
4654 to be transferred. This may help to avoid surprises: transferring a
4655 100MB coredump when you were expecting to move a 10kB status file
4656 might take an awfully long time. The @code{blocksize=} argument
4657 controls how the file is sent over the network: larger blocksizes are
4658 slightly more efficient but also consume more memory on each end, and
4659 there is a hard-coded limit of about 640kB.
4661 The @code{mode=} argument allows you to control the access permissions
4662 of the target file, traditionally expressed as an octal integer. The
4663 most common value is probably 0755, which sets the ``x'' executable
4664 bit on the file (useful for shell scripts and the like). The default
4665 value for @code{mode=} is None, which means the permission bits will
4666 default to whatever the umask of the writing process is. The default
4667 umask tends to be fairly restrictive, but at least on the buildslave
4668 you can make it less restrictive with a --umask command-line option at
4669 creation time (@pxref{Buildslave Options}).
4672 @node Writing New BuildSteps,  , Transferring Files, Build Steps
4673 @subsection Writing New BuildSteps
4675 While it is a good idea to keep your build process self-contained in
4676 the source code tree, sometimes it is convenient to put more
4677 intelligence into your Buildbot configuration. One was to do this is
4678 to write a custom BuildStep. Once written, this Step can be used in
4679 the @file{master.cfg} file.
4681 The best reason for writing a custom BuildStep is to better parse the
4682 results of the command being run. For example, a BuildStep that knows
4683 about JUnit could look at the logfiles to determine which tests had
4684 been run, how many passed and how many failed, and then report more
4685 detailed information than a simple @code{rc==0} -based ``good/bad''
4686 decision.
4688 TODO: add more description of BuildSteps.
4690 @menu
4691 * BuildStep LogFiles::          
4692 * Reading Logfiles::            
4693 * Adding LogObservers::         
4694 * BuildStep URLs::              
4695 @end menu
4697 @node BuildStep LogFiles, Reading Logfiles, Writing New BuildSteps, Writing New BuildSteps
4698 @subsubsection BuildStep LogFiles
4700 Each BuildStep has a collection of ``logfiles''. Each one has a short
4701 name, like ``stdio'' or ``warnings''. Each LogFile contains an
4702 arbitrary amount of text, usually the contents of some output file
4703 generated during a build or test step, or a record of everything that
4704 was printed to stdout/stderr during the execution of some command.
4706 These LogFiles are stored to disk, so they can be retrieved later.
4708 Each can contain multiple ``channels'', generally limited to three
4709 basic ones: stdout, stderr, and ``headers''. For example, when a
4710 ShellCommand runs, it writes a few lines to the ``headers'' channel to
4711 indicate the exact argv strings being run, which directory the command
4712 is being executed in, and the contents of the current environment
4713 variables. Then, as the command runs, it adds a lot of ``stdout'' and
4714 ``stderr'' messages. When the command finishes, a final ``header''
4715 line is added with the exit code of the process.
4717 Status display plugins can format these different channels in
4718 different ways. For example, the web page shows LogFiles as text/html,
4719 with header lines in blue text, stdout in black, and stderr in red. A
4720 different URL is available which provides a text/plain format, in
4721 which stdout and stderr are collapsed together, and header lines are
4722 stripped completely. This latter option makes it easy to save the
4723 results to a file and run @command{grep} or whatever against the
4724 output.
4726 Each BuildStep contains a mapping (implemented in a python dictionary)
4727 from LogFile name to the actual LogFile objects. Status plugins can
4728 get a list of LogFiles to display, for example, a list of HREF links
4729 that, when clicked, provide the full contents of the LogFile.
4731 @heading Using LogFiles in custom BuildSteps
4733 The most common way for a custom BuildStep to use a LogFile is to
4734 summarize the results of a ShellCommand (after the command has
4735 finished running). For example, a compile step with thousands of lines
4736 of output might want to create a summary of just the warning messages.
4737 If you were doing this from a shell, you would use something like:
4739 @example
4740 grep "warning:" output.log >warnings.log
4741 @end example
4743 In a custom BuildStep, you could instead create a ``warnings'' LogFile
4744 that contained the same text. To do this, you would add code to your
4745 @code{createSummary} method that pulls lines from the main output log
4746 and creates a new LogFile with the results:
4748 @example
4749     def createSummary(self, log):
4750         warnings = []
4751         for line in log.readlines():
4752             if "warning:" in line:
4753                 warnings.append()
4754         self.addCompleteLog('warnings', "".join(warnings))
4755 @end example
4757 This example uses the @code{addCompleteLog} method, which creates a
4758 new LogFile, puts some text in it, and then ``closes'' it, meaning
4759 that no further contents will be added. This LogFile will appear in
4760 the HTML display under an HREF with the name ``warnings'', since that
4761 is the name of the LogFile.
4763 You can also use @code{addHTMLLog} to create a complete (closed)
4764 LogFile that contains HTML instead of plain text. The normal LogFile
4765 will be HTML-escaped if presented through a web page, but the HTML
4766 LogFile will not. At the moment this is only used to present a pretty
4767 HTML representation of an otherwise ugly exception traceback when
4768 something goes badly wrong during the BuildStep.
4770 In contrast, you might want to create a new LogFile at the beginning
4771 of the step, and add text to it as the command runs. You can create
4772 the LogFile and attach it to the build by calling @code{addLog}, which
4773 returns the LogFile object. You then add text to this LogFile by
4774 calling methods like @code{addStdout} and @code{addHeader}. When you
4775 are done, you must call the @code{finish} method so the LogFile can be
4776 closed. It may be useful to create and populate a LogFile like this
4777 from a LogObserver method @xref{Adding LogObservers}.
4779 The @code{logfiles=} argument to @code{ShellCommand} (see
4780 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
4781 by asking the buildslave to watch a actual file on disk. The
4782 buildslave will look for additions in the target file and report them
4783 back to the BuildStep. These additions will be added to the LogFile by
4784 calling @code{addStdout}. These secondary LogFiles can be used as the
4785 source of a LogObserver just like the normal ``stdio'' LogFile.
4787 @node Reading Logfiles, Adding LogObservers, BuildStep LogFiles, Writing New BuildSteps
4788 @subsubsection Reading Logfiles
4790 Once a LogFile has been added to a BuildStep with @code{addLog()},
4791 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
4792 your BuildStep can retrieve it by using @code{getLog()}:
4794 @example
4795 class MyBuildStep(ShellCommand):
4796     logfiles = @{ "nodelog": "_test/node.log" @}
4798     def evaluateCommand(self, cmd):
4799         nodelog = self.getLog("nodelog")
4800         if "STARTED" in nodelog.getText():
4801             return SUCCESS
4802         else:
4803             return FAILURE
4804 @end example
4806 For a complete list of the methods you can call on a LogFile, please
4807 see the docstrings on the @code{IStatusLog} class in
4808 @file{buildbot/interfaces.py}.
4811 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
4812 @subsubsection Adding LogObservers
4814 @cindex LogObserver
4815 @cindex LogLineObserver
4817 Most shell commands emit messages to stdout or stderr as they operate,
4818 especially if you ask them nicely with a @code{--verbose} flag of some
4819 sort. They may also write text to a log file while they run. Your
4820 BuildStep can watch this output as it arrives, to keep track of how
4821 much progress the command has made. You can get a better measure of
4822 progress by counting the number of source files compiled or test cases
4823 run than by merely tracking the number of bytes that have been written
4824 to stdout. This improves the accuracy and the smoothness of the ETA
4825 display.
4827 To accomplish this, you will need to attach a @code{LogObserver} to
4828 one of the log channels, most commonly to the ``stdio'' channel but
4829 perhaps to another one which tracks a log file. This observer is given
4830 all text as it is emitted from the command, and has the opportunity to
4831 parse that output incrementally. Once the observer has decided that
4832 some event has occurred (like a source file being compiled), it can
4833 use the @code{setProgress} method to tell the BuildStep about the
4834 progress that this event represents.
4836 There are a number of pre-built @code{LogObserver} classes that you
4837 can choose from (defined in @code{buildbot.process.buildstep}, and of
4838 course you can subclass them to add further customization. The
4839 @code{LogLineObserver} class handles the grunt work of buffering and
4840 scanning for end-of-line delimiters, allowing your parser to operate
4841 on complete stdout/stderr lines.
4843 For example, let's take a look at the @code{TrialTestCaseCounter},
4844 which is used by the Trial step to count test cases as they are run.
4845 As Trial executes, it emits lines like the following:
4847 @example
4848 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
4849 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
4850 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
4851 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
4852 @end example
4854 When the tests are finished, trial emits a long line of ``======'' and
4855 then some lines which summarize the tests that failed. We want to
4856 avoid parsing these trailing lines, because their format is less
4857 well-defined than the ``[OK]'' lines.
4859 The parser class looks like this:
4861 @example
4862 from buildbot.process.buildstep import LogLineObserver
4864 class TrialTestCaseCounter(LogLineObserver):
4865     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
4866     numTests = 0
4867     finished = False
4869     def outLineReceived(self, line):
4870         if self.finished:
4871             return
4872         if line.startswith("=" * 40):
4873             self.finished = True
4874             return
4876         m = self._line_re.search(line.strip())
4877         if m:
4878             testname, result = m.groups()
4879             self.numTests += 1
4880             self.step.setProgress('tests', self.numTests)
4881 @end example
4883 This parser only pays attention to stdout, since that's where trial
4884 writes the progress lines. It has a mode flag named @code{finished} to
4885 ignore everything after the ``===='' marker, and a scary-looking
4886 regular expression to match each line while hopefully ignoring other
4887 messages that might get displayed as the test runs.
4889 Each time it identifies a test has been completed, it increments its
4890 counter and delivers the new progress value to the step with
4891 @code{self.step.setProgress}. This class is specifically measuring
4892 progress along the ``tests'' metric, in units of test cases (as
4893 opposed to other kinds of progress like the ``output'' metric, which
4894 measures in units of bytes). The Progress-tracking code uses each
4895 progress metric separately to come up with an overall completion
4896 percentage and an ETA value.
4898 To connect this parser into the @code{Trial} BuildStep,
4899 @code{Trial.__init__} ends with the following clause:
4901 @example
4902         # this counter will feed Progress along the 'test cases' metric
4903         counter = TrialTestCaseCounter()
4904         self.addLogObserver('stdio', counter)
4905 @end example
4907 This creates a TrialTestCaseCounter and tells the step that the
4908 counter wants to watch the ``stdio'' log. The observer is
4909 automatically given a reference to the step in its @code{.step}
4910 attribute.
4912 @subheading A Somewhat Whimsical Example
4914 Let's say that we've got some snazzy new unit-test framework called
4915 Framboozle. It's the hottest thing since sliced bread. It slices, it
4916 dices, it runs unit tests like there's no tomorrow. Plus if your unit
4917 tests fail, you can use its name for a Web 2.1 startup company, make
4918 millions of dollars, and hire engineers to fix the bugs for you, while
4919 you spend your afternoons lazily hang-gliding along a scenic pacific
4920 beach, blissfully unconcerned about the state of your
4921 tests.@footnote{framboozle.com is still available. Remember, I get 10%
4922 :).}
4924 To run a Framboozle-enabled test suite, you just run the 'framboozler'
4925 command from the top of your source code tree. The 'framboozler'
4926 command emits a bunch of stuff to stdout, but the most interesting bit
4927 is that it emits the line "FNURRRGH!" every time it finishes running a
4928 test case@footnote{Framboozle gets very excited about running unit
4929 tests.}. You'd like to have a test-case counting LogObserver that
4930 watches for these lines and counts them, because counting them will
4931 help the buildbot more accurately calculate how long the build will
4932 take, and this will let you know exactly how long you can sneak out of
4933 the office for your hang-gliding lessons without anyone noticing that
4934 you're gone.
4936 This will involve writing a new BuildStep (probably named
4937 "Framboozle") which inherits from ShellCommand. The BuildStep class
4938 definition itself will look something like this:
4940 @example
4941 # START
4942 from buildbot.steps.shell import ShellCommand
4943 from buildbot.process.buildstep import LogLineObserver
4945 class FNURRRGHCounter(LogLineObserver):
4946     numTests = 0
4947     def outLineReceived(self, line):
4948         if "FNURRRGH!" in line:
4949             self.numTests += 1
4950             self.step.setProgress('tests', self.numTests)
4952 class Framboozle(ShellCommand):
4953     command = ["framboozler"]
4955     def __init__(self, **kwargs):
4956         ShellCommand.__init__(self, **kwargs)   # always upcall!
4957         counter = FNURRRGHCounter())
4958         self.addLogObserver(counter)
4959 # FINISH
4960 @end example
4962 So that's the code that we want to wind up using. How do we actually
4963 deploy it?
4965 You have a couple of different options.
4967 Option 1: The simplest technique is to simply put this text
4968 (everything from START to FINISH) in your master.cfg file, somewhere
4969 before the BuildFactory definition where you actually use it in a
4970 clause like:
4972 @example
4973 f = BuildFactory()
4974 f.addStep(SVN(svnurl="stuff"))
4975 f.addStep(Framboozle())
4976 @end example
4978 Remember that master.cfg is secretly just a python program with one
4979 job: populating the BuildmasterConfig dictionary. And python programs
4980 are allowed to define as many classes as they like. So you can define
4981 classes and use them in the same file, just as long as the class is
4982 defined before some other code tries to use it.
4984 This is easy, and it keeps the point of definition very close to the
4985 point of use, and whoever replaces you after that unfortunate
4986 hang-gliding accident will appreciate being able to easily figure out
4987 what the heck this stupid "Framboozle" step is doing anyways. The
4988 downside is that every time you reload the config file, the Framboozle
4989 class will get redefined, which means that the buildmaster will think
4990 that you've reconfigured all the Builders that use it, even though
4991 nothing changed. Bleh.
4993 Option 2: Instead, we can put this code in a separate file, and import
4994 it into the master.cfg file just like we would the normal buildsteps
4995 like ShellCommand and SVN.
4997 Create a directory named ~/lib/python, put everything from START to
4998 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
5000 @example
5001  PYTHONPATH=~/lib/python buildbot start MASTERDIR
5002 @end example
5004 or use the @file{Makefile.buildbot} to control the way
5005 @command{buildbot start} works. Or add something like this to
5006 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
5008 @example
5009  export PYTHONPATH=~/lib/python
5010 @end example
5012 Once we've done this, our master.cfg can look like:
5014 @example
5015 from framboozle import Framboozle
5016 f = BuildFactory()
5017 f.addStep(SVN(svnurl="stuff"))
5018 f.addStep(Framboozle())
5019 @end example
5023 @example
5024 import framboozle
5025 f = BuildFactory()
5026 f.addStep(SVN(svnurl="stuff"))
5027 f.addStep(framboozle.Framboozle())
5028 @end example
5030 (check out the python docs for details about how "import" and "from A
5031 import B" work).
5033 What we've done here is to tell python that every time it handles an
5034 "import" statement for some named module, it should look in our
5035 ~/lib/python/ for that module before it looks anywhere else. After our
5036 directories, it will try in a bunch of standard directories too
5037 (including the one where buildbot is installed). By setting the
5038 PYTHONPATH environment variable, you can add directories to the front
5039 of this search list.
5041 Python knows that once it "import"s a file, it doesn't need to
5042 re-import it again. This means that reconfiguring the buildmaster
5043 (with "buildbot reconfig", for example) won't make it think the
5044 Framboozle class has changed every time, so the Builders that use it
5045 will not be spuriously restarted. On the other hand, you either have
5046 to start your buildmaster in a slightly weird way, or you have to
5047 modify your environment to set the PYTHONPATH variable.
5050 Option 3: Install this code into a standard python library directory
5052 Find out what your python's standard include path is by asking it:
5054 @example
5055 80:warner@@luther% python
5056 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46) 
5057 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
5058 Type "help", "copyright", "credits" or "license" for more information.
5059 >>> import sys
5060 >>> print sys.path
5061 ['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/var/lib/python-support/python2.4', '/usr/lib/site-python']
5062 >>> 
5063 @end example
5065 In this case, putting the code into
5066 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
5067 fine. We can use the same master.cfg "import framboozle" statement as
5068 in Option 2. By putting it in a standard include directory (instead of
5069 the decidedly non-standard ~/lib/python), we don't even have to set
5070 PYTHONPATH to anything special. The downside is that you probably have
5071 to be root to write to one of those standard include directories.
5074 Option 4: Submit the code for inclusion in the Buildbot distribution
5076 Contribute the code in an Enhancement Request on SourceForge, via
5077 http://buildbot.sf.net . Lobby, convince, coerce, bribe, badger,
5078 harass, threaten, or otherwise encourage the author to accept the
5079 patch. This lets you do something like:
5081 @example
5082 from buildbot.steps import framboozle
5083 f = BuildFactory()
5084 f.addStep(SVN(svnurl="stuff"))
5085 f.addStep(framboozle.Framboozle())
5086 @end example
5088 And then you don't even have to install framboozle.py anywhere on your
5089 system, since it will ship with Buildbot. You don't have to be root,
5090 you don't have to set PYTHONPATH. But you do have to make a good case
5091 for Framboozle being worth going into the main distribution, you'll
5092 probably have to provide docs and some unit test cases, you'll need to
5093 figure out what kind of beer the author likes, and then you'll have to
5094 wait until the next release. But in some environments, all this is
5095 easier than getting root on your buildmaster box, so the tradeoffs may
5096 actually be worth it.
5100 Putting the code in master.cfg (1) makes it available to that
5101 buildmaster instance. Putting it in a file in a personal library
5102 directory (2) makes it available for any buildmasters you might be
5103 running. Putting it in a file in a system-wide shared library
5104 directory (3) makes it available for any buildmasters that anyone on
5105 that system might be running. Getting it into the buildbot's upstream
5106 repository (4) makes it available for any buildmasters that anyone in
5107 the world might be running. It's all a matter of how widely you want
5108 to deploy that new class.
5112 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
5113 @subsubsection BuildStep URLs
5115 @cindex links
5116 @cindex BuildStep URLs
5117 @cindex addURL
5119 Each BuildStep has a collection of ``links''. Like its collection of
5120 LogFiles, each link has a name and a target URL. The web status page
5121 creates HREFs for each link in the same box as it does for LogFiles,
5122 except that the target of the link is the external URL instead of an
5123 internal link to a page that shows the contents of the LogFile.
5125 These external links can be used to point at build information hosted
5126 on other servers. For example, the test process might produce an
5127 intricate description of which tests passed and failed, or some sort
5128 of code coverage data in HTML form, or a PNG or GIF image with a graph
5129 of memory usage over time. The external link can provide an easy way
5130 for users to navigate from the buildbot's status page to these
5131 external web sites or file servers. Note that the step itself is
5132 responsible for insuring that there will be a document available at
5133 the given URL (perhaps by using @command{scp} to copy the HTML output
5134 to a @file{~/public_html/} directory on a remote web server). Calling
5135 @code{addURL} does not magically populate a web server.
5137 To set one of these links, the BuildStep should call the @code{addURL}
5138 method with the name of the link and the target URL. Multiple URLs can
5139 be set.
5141 In this example, we assume that the @command{make test} command causes
5142 a collection of HTML files to be created and put somewhere on the
5143 coverage.example.org web server, in a filename that incorporates the
5144 build number.
5146 @example
5147 class TestWithCodeCoverage(BuildStep):
5148     command = ["make", "test",
5149                WithProperties("buildnum=%s" % "buildnumber")]
5151     def createSummary(self, log):
5152         buildnumber = self.getProperty("buildnumber")
5153         url = "http://coverage.example.org/builds/%s.html" % buildnumber
5154         self.addURL("coverage", url)
5155 @end example
5157 You might also want to extract the URL from some special message
5158 output by the build process itself:
5160 @example
5161 class TestWithCodeCoverage(BuildStep):
5162     command = ["make", "test",
5163                WithProperties("buildnum=%s" % "buildnumber")]
5165     def createSummary(self, log):
5166         output = StringIO(log.getText())
5167         for line in output.readlines():
5168             if line.startswith("coverage-url:"):
5169                 url = line[len("coverage-url:"):].strip()
5170                 self.addURL("coverage", url)
5171                 return
5172 @end example
5174 Note that a build process which emits both stdout and stderr might
5175 cause this line to be split or interleaved between other lines. It
5176 might be necessary to restrict the getText() call to only stdout with
5177 something like this:
5179 @example
5180         output = StringIO("".join([c[1]
5181                                    for c in log.getChunks()
5182                                    if c[0] == LOG_CHANNEL_STDOUT]))
5183 @end example
5185 Of course if the build is run under a PTY, then stdout and stderr will
5186 be merged before the buildbot ever sees them, so such interleaving
5187 will be unavoidable.
5190 @node Interlocks, Build Factories, Build Steps, Build Process
5191 @section Interlocks
5193 @cindex locks
5194 @slindex buildbot.locks.MasterLock
5195 @slindex buildbot.locks.SlaveLock
5197 For various reasons, you may want to prevent certain Steps (or perhaps
5198 entire Builds) from running simultaneously. Limited CPU speed or
5199 network bandwidth to the VC server, problems with simultaneous access
5200 to a database server used by unit tests, or multiple Builds which
5201 access shared state may all require some kind of interlock to prevent
5202 corruption, confusion, or resource overload. These resources might
5203 require completely exclusive access, or it might be sufficient to
5204 establish a limit of two or three simultaneous builds.
5206 @code{Locks} are the mechanism used to express these kinds of
5207 constraints on when Builds or Steps can be run. There are two kinds of
5208 @code{Locks}, each with their own scope: @code{MasterLock} instances
5209 are scoped to the buildbot as a whole, while @code{SlaveLock}s are
5210 scoped to a single buildslave. This means that each buildslave has a
5211 separate copy of each @code{SlaveLock}, which could enforce a
5212 one-Build-at-a-time limit for each machine, but still allow as many
5213 simultaneous builds as there are machines.
5215 Each @code{Lock} is created with a unique name. Each lock gets a count
5216 of how many owners it may have: how many processes can claim it at ths
5217 same time. This limit defaults to one, and is controllable through the
5218 @code{maxCount} argument. On @code{SlaveLock}s you can set the owner
5219 count on a per-slave basis by providing a dictionary (that maps from
5220 slavename to maximum owner count) to its @code{maxCountForSlave}
5221 argument. Any buildslaves that aren't mentioned in
5222 @code{maxCountForSlave} get their owner count from @code{maxCount}.
5224 To use a lock, simply include it in the @code{locks=} argument of the
5225 @code{BuildStep} object that should obtain the lock before it runs.
5226 This argument accepts a list of @code{Lock} objects: the Step will
5227 acquire all of them before it runs.
5229 To claim a lock for the whole Build, add a @code{'locks'} key to the
5230 builder specification dictionary with the same list of @code{Lock}
5231 objects. (This is the dictionary that has the @code{'name'},
5232 @code{'slavename'}, @code{'builddir'}, and @code{'factory'} keys). The
5233 @code{Build} object also accepts a @code{locks=} argument, but unless
5234 you are writing your own @code{BuildFactory} subclass then it will be
5235 easier to set the locks in the builder dictionary.
5237 Note that there are no partial-acquire or partial-release semantics:
5238 this prevents deadlocks caused by two Steps each waiting for a lock
5239 held by the other@footnote{Also note that a clever buildmaster admin
5240 could still create the opportunity for deadlock: Build A obtains Lock
5241 1, inside which Step A.two tries to acquire Lock 2 at the Step level.
5242 Meanwhile Build B obtains Lock 2, and has a Step B.two which wants to
5243 acquire Lock 1 at the Step level. Don't Do That.}. This also means
5244 that waiting to acquire a @code{Lock} can take an arbitrarily long
5245 time: if the buildmaster is very busy, a Step or Build which requires
5246 only one @code{Lock} may starve another that is waiting for that
5247 @code{Lock} plus some others.
5250 In the following example, we run the same build on three different
5251 platforms. The unit-test steps of these builds all use a common
5252 database server, and would interfere with each other if allowed to run
5253 simultaneously. The @code{Lock} prevents more than one of these builds
5254 from happening at the same time.
5256 @example
5257 from buildbot import locks
5258 from buildbot.steps import source, shell
5259 from buildbot.process import factory
5261 db_lock = locks.MasterLock("database")
5262 f = factory.BuildFactory()
5263 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
5264 f.addStep(shell.ShellCommand(command="make all"))
5265 f.addStep(shell.ShellCommand(command="make test", locks=[db_lock]))
5266 b1 = @{'name': 'full1', 'slavename': 'bot-1', builddir='f1', 'factory': f@}
5267 b2 = @{'name': 'full2', 'slavename': 'bot-2', builddir='f2', 'factory': f@}
5268 b3 = @{'name': 'full3', 'slavename': 'bot-3', builddir='f3', 'factory': f@}
5269 c['builders'] = [b1, b2, b3]
5270 @end example
5272 In the next example, we have one buildslave hosting three separate
5273 Builders (each running tests against a different version of Python).
5274 The machine which hosts this buildslave is not particularly fast, so
5275 we want to prevent all three builds from all happening at the same
5276 time. (Assume we've experimentally determined that one build leaves
5277 unused CPU capacity, three builds causes a lot of disk thrashing, but
5278 two builds at a time is Just Right). We use a @code{SlaveLock} because
5279 the builds happening on this one slow slave should not affect builds
5280 running on other slaves, and we use the lock on the build as a whole
5281 because the slave is so slow that even multiple simultaneous SVN
5282 checkouts would be too taxing. We set @code{maxCount=2} to achieve our
5283 goal of two simultaneous builds per slave.
5285 @example
5286 from buildbot import locks
5287 from buildbot.steps import source
5288 from buildbot.process import s, factory
5290 slow_lock = locks.SlaveLock("cpu", maxCount=2)
5291 source = s(source.SVN, svnurl="http://example.org/svn/Trunk")
5292 f22 = factory.Trial(source, trialpython=["python2.2"])
5293 f23 = factory.Trial(source, trialpython=["python2.3"])
5294 f24 = factory.Trial(source, trialpython=["python2.4"])
5295 b1 = @{'name': 'p22', 'slavename': 'bot-1', builddir='p22', 'factory': f22,
5296       'locks': [slow_lock] @}
5297 b2 = @{'name': 'p23', 'slavename': 'bot-1', builddir='p23', 'factory': f23,
5298       'locks': [slow_lock] @}
5299 b3 = @{'name': 'p24', 'slavename': 'bot-1', builddir='p24', 'factory': f24,
5300       'locks': [slow_lock] @}
5301 c['builders'] = [b1, b2, b3]
5302 @end example
5304 In the last example, we use two Locks at the same time. In this case,
5305 we're concerned about both of the previous constraints, but we'll say
5306 that only the tests are computationally intensive, and that they have
5307 been split into those which use the database and those which do not.
5308 In addition, two of the Builds run on a fast machine which does not
5309 need to worry about the cpu lock, but which still must be prevented
5310 from simultaneous database access. We use @code{maxCountForSlave} to
5311 limit the slow machine to one simultanous build, but allow practically
5312 unlimited concurrent builds on the fast machine.
5314 @example
5315 from buildbot import locks
5316 from buildbot.steps import source, shell
5317 from buildbot.process import factory
5319 db_lock = locks.MasterLock("database")
5320 slavecounts = @{"bot-slow": 1, "bot-fast": 100@}
5321 cpu_lock = locks.SlaveLock("cpu", maxCountForSlave=slavecounts)
5322 f = factory.BuildFactory()
5323 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
5324 f.addStep(shell.ShellCommand(command="make all", locks=[cpu_lock]))
5325 f.addStep(shell.ShellCommand(command="make test", locks=[cpu_lock]))
5326 f.addStep(shell.ShellCommand(command="make db-test", locks=[db_lock, cpu_lock]))
5328 b1 = @{'name': 'full1', 'slavename': 'bot-slow', builddir='full1',
5329       'factory': f@}
5330 b2 = @{'name': 'full2', 'slavename': 'bot-slow', builddir='full2',
5331       'factory': f@}
5332 b3 = @{'name': 'full3', 'slavename': 'bot-fast', builddir='full3',
5333       'factory': f@}
5334 b4 = @{'name': 'full4', 'slavename': 'bot-fast', builddir='full4',
5335       'factory': f@}
5336 c['builders'] = [b1, b2, b3, b4]
5337 @end example
5339 As a final note, remember that a unit test system which breaks when
5340 multiple people run it at the same time is fragile and should be
5341 fixed. Asking your human developers to serialize themselves when
5342 running unit tests will just discourage them from running the unit
5343 tests at all. Find a way to fix this: change the database tests to
5344 create a new (uniquely-named) user or table for each test run, don't
5345 use fixed listening TCP ports for network tests (instead listen on
5346 port 0 to let the kernel choose a port for you and then query the
5347 socket to find out what port was allocated). @code{MasterLock}s can be
5348 used to accomodate broken test systems like this, but are really
5349 intended for other purposes: build processes that store or retrieve
5350 products in shared directories, or which do things that human
5351 developers would not (or which might slow down or break in ways that
5352 require human attention to deal with).
5354 @code{SlaveLocks}s can be used to keep automated performance tests
5355 from interfering with each other, when there are multiple Builders all
5356 using the same buildslave. But they can't prevent other users from
5357 running CPU-intensive jobs on that host while the tests are running.
5359 @node Build Factories,  , Interlocks, Build Process
5360 @section Build Factories
5363 Each Builder is equipped with a ``build factory'', which is
5364 responsible for producing the actual @code{Build} objects that perform
5365 each build. This factory is created in the configuration file, and
5366 attached to a Builder through the @code{factory} element of its
5367 dictionary.
5369 The standard @code{BuildFactory} object creates @code{Build} objects
5370 by default. These Builds will each execute a collection of BuildSteps
5371 in a fixed sequence. Each step can affect the results of the build,
5372 but in general there is little intelligence to tie the different steps
5373 together. You can create subclasses of @code{Build} to implement more
5374 sophisticated build processes, and then use a subclass of
5375 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
5376 create instances of your new Build subclass.
5379 @menu
5380 * BuildStep Objects::           
5381 * BuildFactory::                
5382 * Process-Specific build factories::  
5383 @end menu
5385 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
5386 @subsection BuildStep Objects
5388 The steps used by these builds are all subclasses of @code{BuildStep}.
5389 The standard ones provided with Buildbot are documented later,
5390 @xref{Build Steps}. You can also write your own subclasses to use in
5391 builds.
5393 The basic behavior for a @code{BuildStep} is to:
5395 @itemize @bullet
5396 @item
5397 run for a while, then stop
5398 @item
5399 possibly invoke some RemoteCommands on the attached build slave
5400 @item
5401 possibly produce a set of log files
5402 @item
5403 finish with a status described by one of four values defined in
5404 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
5405 @item
5406 provide a list of short strings to describe the step
5407 @item
5408 define a color (generally green, orange, or red) with which the
5409 step should be displayed
5410 @end itemize
5413 More sophisticated steps may produce additional information and
5414 provide it to later build steps, or store it in the factory to provide
5415 to later builds.
5418 @menu
5419 * BuildFactory Attributes::     
5420 * Quick builds::                
5421 @end menu
5423 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
5424 @subsection BuildFactory
5426 @bfindex buildbot.process.factory.BuildFactory
5427 @bfindex buildbot.process.factory.BasicBuildFactory
5428 @c TODO: what is BasicSVN anyway?
5429 @bfindex buildbot.process.factory.BasicSVN
5431 The default @code{BuildFactory}, provided in the
5432 @code{buildbot.process.factory} module, contains an internal list of
5433 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
5434 tuples for each. These specification tuples are constructed when the
5435 config file is read, by asking the instances passed to @code{addStep}
5436 for their subclass and arguments.
5438 When asked to create a Build, the @code{BuildFactory} puts a copy of
5439 the list of step specifications into the new Build object. When the
5440 Build is actually started, these step specifications are used to
5441 create the actual set of BuildSteps, which are then executed one at a
5442 time. This serves to give each Build an independent copy of each step.
5443 For example, a build which consists of a CVS checkout followed by a
5444 @code{make build} would be constructed as follows:
5446 @example
5447 from buildbot.steps import source, shell
5448 from buildbot.process import factory
5450 f = factory.BuildFactory()
5451 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
5452 f.addStep(shell.Compile(command=["make", "build"]))
5453 @end example
5455 (To support config files from buildbot-0.7.5 and earlier,
5456 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
5457 command=["make","build"])} form, although its use is discouraged
5458 because then the @code{Compile} step doesn't get to validate or
5459 complain about its arguments until build time. The modern
5460 pass-by-instance approach allows this validation to occur while the
5461 config file is being loaded, where the admin has a better chance of
5462 noticing problems).
5464 It is also possible to pass a list of steps into the
5465 @code{BuildFactory} when it is created. Using @code{addStep} is
5466 usually simpler, but there are cases where is is more convenient to
5467 create the list of steps ahead of time.:
5469 @example
5470 from buildbot.steps import source, shell
5471 from buildbot.process import factory
5473 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
5474              shell.Compile(command=["make", "build"]),
5475             ]
5476 f = factory.BuildFactory(all_steps)
5477 @end example
5480 Each step can affect the build process in the following ways:
5482 @itemize @bullet
5483 @item
5484 If the step's @code{haltOnFailure} attribute is True, then a failure
5485 in the step (i.e. if it completes with a result of FAILURE) will cause
5486 the whole build to be terminated immediately: no further steps will be
5487 executed. This is useful for setup steps upon which the rest of the
5488 build depends: if the CVS checkout or @code{./configure} process
5489 fails, there is no point in trying to compile or test the resulting
5490 tree.
5492 @item
5493 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
5494 then a result of FAILURE or WARNINGS will mark the build as a whole as
5495 FAILED. However, the remaining steps will still be executed. This is
5496 appropriate for things like multiple testing steps: a failure in any
5497 one of them will indicate that the build has failed, however it is
5498 still useful to run them all to completion.
5500 @item
5501 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
5502 is set, then a result of FAILURE or WARNINGS will mark the build as
5503 having WARNINGS, and the remaining steps will still be executed. This
5504 may be appropriate for certain kinds of optional build or test steps.
5505 For example, a failure experienced while building documentation files
5506 should be made visible with a WARNINGS result but not be serious
5507 enough to warrant marking the whole build with a FAILURE.
5509 @end itemize
5511 In addition, each Step produces its own results, may create logfiles,
5512 etc. However only the flags described above have any effect on the
5513 build as a whole.
5515 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
5516 reasonably appropriate flags set on them already. For example, without
5517 a source tree there is no point in continuing the build, so the
5518 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
5519 in @file{buildbot/steps/*.py} to see how the other Steps are
5520 marked.
5522 Each Step is created with an additional @code{workdir} argument that
5523 indicates where its actions should take place. This is specified as a
5524 subdirectory of the slave builder's base directory, with a default
5525 value of @code{build}. This is only implemented as a step argument (as
5526 opposed to simply being a part of the base directory) because the
5527 CVS/SVN steps need to perform their checkouts from the parent
5528 directory.
5530 @menu
5531 * BuildFactory Attributes::     
5532 * Quick builds::                
5533 @end menu
5535 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
5536 @subsubsection BuildFactory Attributes
5538 Some attributes from the BuildFactory are copied into each Build.
5540 @cindex treeStableTimer
5542 @table @code
5543 @item useProgress
5544 (defaults to True): if True, the buildmaster keeps track of how long
5545 each step takes, so it can provide estimates of how long future builds
5546 will take. If builds are not expected to take a consistent amount of
5547 time (such as incremental builds in which a random set of files are
5548 recompiled or tested each time), this should be set to False to
5549 inhibit progress-tracking.
5551 @end table
5554 @node Quick builds,  , BuildFactory Attributes, BuildFactory
5555 @subsubsection Quick builds
5557 @bfindex buildbot.process.factory.QuickBuildFactory
5559 The difference between a ``full build'' and a ``quick build'' is that
5560 quick builds are generally done incrementally, starting with the tree
5561 where the previous build was performed. That simply means that the
5562 source-checkout step should be given a @code{mode='update'} flag, to
5563 do the source update in-place.
5565 In addition to that, the @code{useProgress} flag should be set to
5566 False. Incremental builds will (or at least the ought to) compile as
5567 few files as necessary, so they will take an unpredictable amount of
5568 time to run. Therefore it would be misleading to claim to predict how
5569 long the build will take.
5572 @node Process-Specific build factories,  , BuildFactory, Build Factories
5573 @subsection Process-Specific build factories
5575 Many projects use one of a few popular build frameworks to simplify
5576 the creation and maintenance of Makefiles or other compilation
5577 structures. Buildbot provides several pre-configured BuildFactory
5578 subclasses which let you build these projects with a minimum of fuss.
5580 @menu
5581 * GNUAutoconf::                 
5582 * CPAN::                        
5583 * Python distutils::            
5584 * Python/Twisted/trial projects::  
5585 @end menu
5587 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
5588 @subsubsection GNUAutoconf
5590 @bfindex buildbot.process.factory.GNUAutoconf
5592 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
5593 software portability tool, intended to make it possible to write
5594 programs in C (and other languages) which will run on a variety of
5595 UNIX-like systems. Most GNU software is built using autoconf. It is
5596 frequently used in combination with GNU automake. These tools both
5597 encourage a build process which usually looks like this:
5599 @example
5600 % CONFIG_ENV=foo ./configure --with-flags
5601 % make all
5602 % make check
5603 # make install
5604 @end example
5606 (except of course the Buildbot always skips the @code{make install}
5607 part).
5609 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
5610 designed to build projects which use GNU autoconf and/or automake. The
5611 configuration environment variables, the configure flags, and command
5612 lines used for the compile and test are all configurable, in general
5613 the default values will be suitable.
5615 Example:
5617 @example
5618 # use the s() convenience function defined earlier
5619 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
5620                         flags=["--disable-nls"])
5621 @end example
5623 Required Arguments:
5625 @table @code
5626 @item source
5627 This argument must be a step specification tuple that provides a
5628 BuildStep to generate the source tree.
5629 @end table
5631 Optional Arguments:
5633 @table @code
5634 @item configure
5635 The command used to configure the tree. Defaults to
5636 @code{./configure}. Accepts either a string or a list of shell argv
5637 elements.
5639 @item configureEnv
5640 The environment used for the initial configuration step. This accepts
5641 a dictionary which will be merged into the buildslave's normal
5642 environment. This is commonly used to provide things like
5643 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
5644 Defaults to an empty dictionary.
5646 @item configureFlags
5647 A list of flags to be appended to the argument list of the configure
5648 command. This is commonly used to enable or disable specific features
5649 of the autoconf-controlled package, like @code{["--without-x"]} to
5650 disable windowing support. Defaults to an empty list.
5652 @item compile
5653 this is a shell command or list of argv values which is used to
5654 actually compile the tree. It defaults to @code{make all}. If set to
5655 None, the compile step is skipped.
5657 @item test
5658 this is a shell command or list of argv values which is used to run
5659 the tree's self-tests. It defaults to @code{make check}. If set to
5660 None, the test step is skipped.
5662 @end table
5665 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
5666 @subsubsection CPAN
5668 @bfindex buildbot.process.factory.CPAN
5670 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
5671 archive use the @code{MakeMaker} module to provide configuration,
5672 build, and test services. The standard build routine for these modules
5673 looks like:
5675 @example
5676 % perl Makefile.PL
5677 % make
5678 % make test
5679 # make install
5680 @end example
5682 (except again Buildbot skips the install step)
5684 Buildbot provides a @code{CPAN} factory to compile and test these
5685 projects.
5688 Arguments:
5689 @table @code
5690 @item source
5691 (required): A step specification tuple, that that used by GNUAutoconf.
5693 @item perl
5694 A string which specifies the @code{perl} executable to use. Defaults
5695 to just @code{perl}.
5697 @end table
5700 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
5701 @subsubsection Python distutils
5703 @bfindex buildbot.process.factory.Distutils
5705 Most Python modules use the @code{distutils} package to provide
5706 configuration and build services. The standard build process looks
5707 like:
5709 @example
5710 % python ./setup.py build
5711 % python ./setup.py install
5712 @end example
5714 Unfortunately, although Python provides a standard unit-test framework
5715 named @code{unittest}, to the best of my knowledge @code{distutils}
5716 does not provide a standardized target to run such unit tests. (please
5717 let me know if I'm wrong, and I will update this factory).
5719 The @code{Distutils} factory provides support for running the build
5720 part of this process. It accepts the same @code{source=} parameter as
5721 the other build factories.
5724 Arguments:
5725 @table @code
5726 @item source
5727 (required): A step specification tuple, that that used by GNUAutoconf.
5728   
5729 @item python
5730 A string which specifies the @code{python} executable to use. Defaults
5731 to just @code{python}.
5733 @item test
5734 Provides a shell command which runs unit tests. This accepts either a
5735 string or a list. The default value is None, which disables the test
5736 step (since there is no common default command to run unit tests in
5737 distutils modules).
5739 @end table
5742 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
5743 @subsubsection Python/Twisted/trial projects
5745 @bfindex buildbot.process.factory.Trial
5746 @c TODO: document these steps better
5747 @bsindex buildbot.steps.python_twisted.HLint
5748 @bsindex buildbot.steps.python_twisted.Trial
5749 @bsindex buildbot.steps.python_twisted.ProcessDocs
5750 @bsindex buildbot.steps.python_twisted.BuildDebs
5751 @bsindex buildbot.steps.python_twisted.RemovePYCs
5753 Twisted provides a unit test tool named @code{trial} which provides a
5754 few improvements over Python's built-in @code{unittest} module. Many
5755 python projects which use Twisted for their networking or application
5756 services also use trial for their unit tests. These modules are
5757 usually built and tested with something like the following:
5759 @example
5760 % python ./setup.py build
5761 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
5762 % python ./setup.py install
5763 @end example
5765 Unfortunately, the @file{build/lib} directory into which the
5766 built/copied .py files are placed is actually architecture-dependent,
5767 and I do not yet know of a simple way to calculate its value. For many
5768 projects it is sufficient to import their libraries ``in place'' from
5769 the tree's base directory (@code{PYTHONPATH=.}).
5771 In addition, the @var{PROJECTNAME} value where the test files are
5772 located is project-dependent: it is usually just the project's
5773 top-level library directory, as common practice suggests the unit test
5774 files are put in the @code{test} sub-module. This value cannot be
5775 guessed, the @code{Trial} class must be told where to find the test
5776 files.
5778 The @code{Trial} class provides support for building and testing
5779 projects which use distutils and trial. If the test module name is
5780 specified, trial will be invoked. The library path used for testing
5781 can also be set.
5783 One advantage of trial is that the Buildbot happens to know how to
5784 parse trial output, letting it identify which tests passed and which
5785 ones failed. The Buildbot can then provide fine-grained reports about
5786 how many tests have failed, when individual tests fail when they had
5787 been passing previously, etc.
5789 Another feature of trial is that you can give it a series of source
5790 .py files, and it will search them for special @code{test-case-name}
5791 tags that indicate which test cases provide coverage for that file.
5792 Trial can then run just the appropriate tests. This is useful for
5793 quick builds, where you want to only run the test cases that cover the
5794 changed functionality.
5796 Arguments:
5797 @table @code
5798 @item source
5799 (required): A step specification tuple, like that used by GNUAutoconf.
5801 @item buildpython
5802 A list (argv array) of strings which specifies the @code{python}
5803 executable to use when building the package. Defaults to just
5804 @code{['python']}. It may be useful to add flags here, to supress
5805 warnings during compilation of extension modules. This list is
5806 extended with @code{['./setup.py', 'build']} and then executed in a
5807 ShellCommand.
5809 @item testpath
5810 Provides a directory to add to @code{PYTHONPATH} when running the unit
5811 tests, if tests are being run. Defaults to @code{.} to include the
5812 project files in-place. The generated build library is frequently
5813 architecture-dependent, but may simply be @file{build/lib} for
5814 pure-python modules.
5816 @item trialpython
5817 Another list of strings used to build the command that actually runs
5818 trial. This is prepended to the contents of the @code{trial} argument
5819 below. It may be useful to add @code{-W} flags here to supress
5820 warnings that occur while tests are being run. Defaults to an empty
5821 list, meaning @code{trial} will be run without an explicit
5822 interpreter, which is generally what you want if you're using
5823 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
5824 lives in the Twisted source tree.
5826 @item trial
5827 provides the name of the @code{trial} command. It is occasionally
5828 useful to use an alternate executable, such as @code{trial2.2} which
5829 might run the tests under an older version of Python. Defaults to
5830 @code{trial}.
5832 @item tests
5833 Provides a module name or names which contain the unit tests for this
5834 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
5835 list of strings. Defaults to None, indicating that no tests should be
5836 run. You must either set this or @code{useTestCaseNames} to do anyting
5837 useful with the Trial factory.
5839 @item useTestCaseNames
5840 Tells the Step to provide the names of all changed .py files to trial,
5841 so it can look for test-case-name tags and run just the matching test
5842 cases. Suitable for use in quick builds. Defaults to False.
5844 @item randomly
5845 If @code{True}, tells Trial (with the @code{--random=0} argument) to
5846 run the test cases in random order, which sometimes catches subtle
5847 inter-test dependency bugs. Defaults to @code{False}.
5849 @item recurse
5850 If @code{True}, tells Trial (with the @code{--recurse} argument) to
5851 look in all subdirectories for additional test cases. It isn't clear
5852 to me how this works, but it may be useful to deal with the
5853 unknown-PROJECTNAME problem described above, and is currently used in
5854 the Twisted buildbot to accomodate the fact that test cases are now
5855 distributed through multiple twisted.SUBPROJECT.test directories.
5857 @end table  
5859 Unless one of @code{trialModule} or @code{useTestCaseNames}
5860 are set, no tests will be run.
5862 Some quick examples follow. Most of these examples assume that the
5863 target python code (the ``code under test'') can be reached directly
5864 from the root of the target tree, rather than being in a @file{lib/}
5865 subdirectory.
5867 @example
5868 #  Trial(source, tests="toplevel.test") does:
5869 #   python ./setup.py build
5870 #   PYTHONPATH=. trial -to toplevel.test
5872 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
5873 #   python ./setup.py build
5874 #   PYTHONPATH=. trial -to toplevel.test other.test
5876 #  Trial(source, useTestCaseNames=True) does:
5877 #   python ./setup.py build
5878 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
5880 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
5881 #   python2.3 -Wall ./setup.py build
5882 #   PYTHONPATH=. trial -to foo.tests
5884 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
5885 #        tests="foo.tests") does:
5886 #   python2.3 -Wall ./setup.py build
5887 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
5889 # For running trial out of the tree being tested (only useful when the
5890 # tree being built is Twisted itself):
5891 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
5892 #        tests="foo.tests") does:
5893 #   python2.3 -Wall ./setup.py build
5894 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
5895 @end example
5897 If the output directory of @code{./setup.py build} is known, you can
5898 pull the python code from the built location instead of the source
5899 directories. This should be able to handle variations in where the
5900 source comes from, as well as accomodating binary extension modules:
5902 @example
5903 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
5904 # does:
5905 #  python ./setup.py build
5906 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
5907 @end example
5910 @node Status Delivery, Command-line tool, Build Process, Top
5911 @chapter Status Delivery
5913 More details are available in the docstrings for each class, use a
5914 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
5915 Most status delivery objects take a @code{categories=} argument, which
5916 can contain a list of ``category'' names: in this case, it will only
5917 show status for Builders that are in one of the named categories.
5919 (implementor's note: each of these objects should be a
5920 service.MultiService which will be attached to the BuildMaster object
5921 when the configuration is processed. They should use
5922 @code{self.parent.getStatus()} to get access to the top-level IStatus
5923 object, either inside @code{startService} or later. They may call
5924 @code{status.subscribe()} in @code{startService} to receive
5925 notifications of builder events, in which case they must define
5926 @code{builderAdded} and related methods. See the docstrings in
5927 @file{buildbot/interfaces.py} for full details.)
5929 @menu
5930 * WebStatus::                   
5931 * MailNotifier::                
5932 * IRC Bot::                     
5933 * PBListener::                  
5934 * Writing New Status Plugins::  
5935 @end menu
5937 @c @node Email Delivery,  , Status Delivery, Status Delivery
5938 @c @subsection Email Delivery
5940 @c DOCUMENT THIS
5943 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
5944 @section WebStatus
5946 @cindex WebStatus
5947 @stindex buildbot.status.web.baseweb.WebStatus
5949 The @code{buildbot.status.html.WebStatus} status target runs a small
5950 web server inside the buildmaster. You can point a browser at this web
5951 server and retrieve information about every build the buildbot knows
5952 about, as well as find out what the buildbot is currently working on.
5954 The first page you will see is the ``Welcome Page'', which contains
5955 links to all the other useful pages. This page is simply served from
5956 the @file{public_html/index.html} file in the buildmaster's base
5957 directory, where it is created by the @command{buildbot create-master}
5958 command along with the rest of the buildmaster.
5960 The most complex resource provided by @code{WebStatus} is the
5961 ``Waterfall Display'', which shows a time-based chart of events. This
5962 somewhat-busy display provides detailed information about all steps of
5963 all recent builds, and provides hyperlinks to look at individual build
5964 logs and source changes. By simply reloading this page on a regular
5965 basis, you will see a complete description of everything the buildbot
5966 is currently working on.
5968 There are also pages with more specialized information. For example,
5969 there is a page which shows the last 20 builds performed by the
5970 buildbot, one line each. Each line is a link to detailed information
5971 about that build. By adding query arguments to the URL used to reach
5972 this page, you can narrow the display to builds that involved certain
5973 branches, or which ran on certain Builders. These pages are described
5974 in great detail below.
5977 When the buildmaster is created, a subdirectory named
5978 @file{public_html/} is created in its base directory. @code{WebStatus}
5979 will serve files from this directory: for example, when a user points
5980 their browser at the buildbot's @code{WebStatus} URL, they will see
5981 the contents of the @file{public_html/index.html} file. Likewise,
5982 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
5983 @file{public_html/favicon.ico} are all useful things to have in there.
5984 The first time a buildmaster is created, the @file{public_html}
5985 directory is populated with some sample files, which you will probably
5986 want to customize for your own project. These files are all static:
5987 the buildbot does not modify them in any way as it serves them to HTTP
5988 clients.
5990 @example
5991 from buildbot.status.html import WebStatus
5992 c['status'].append(WebStatus(8080))
5993 @end example
5995 In addition, if you are familiar with twisted.web @emph{Resource
5996 Trees}, you can write code to add additional pages at places inside
5997 this web space. Just use @code{webstatus.putChild} to place these
5998 resources.
6000 The following section describes the special URLs and the status views
6001 they provide.
6004 @menu
6005 * WebStatus Configuration Parameters::  
6006 * Buildbot Web Resources::      
6007 * XMLRPC server::               
6008 * HTML Waterfall::              
6009 @end menu
6011 @node WebStatus Configuration Parameters, Buildbot Web Resources, WebStatus, WebStatus
6012 @subsection WebStatus Configuration Parameters
6014 The most common way to run a @code{WebStatus} is on a regular TCP
6015 port. To do this, just pass in the TCP port number when you create the
6016 @code{WebStatus} instance; this is called the @code{http_port} argument:
6018 @example
6019 from buildbot.status.html import WebStatus
6020 c['status'].append(WebStatus(8080))
6021 @end example
6023 The @code{http_port} argument is actually a ``strports specification''
6024 for the port that the web server should listen on. This can be a
6025 simple port number, or a string like
6026 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
6027 loopback interface, and therefore to clients running on the same
6028 host)@footnote{It may even be possible to provide SSL access by using
6029 a specification like
6030 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
6031 completely untested}.
6033 If instead (or in addition) you provide the @code{distrib_port}
6034 argument, a twisted.web distributed server will be started either on a
6035 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
6036 likely on a UNIX socket (if @code{distrib_port} is like
6037 @code{"unix:/path/to/socket"}).
6039 The @code{distrib_port} option means that, on a host with a
6040 suitably-configured twisted-web server, you do not need to consume a
6041 separate TCP port for the buildmaster's status web page. When the web
6042 server is constructed with @code{mktap web --user}, URLs that point to
6043 @code{http://host/~username/} are dispatched to a sub-server that is
6044 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
6045 such a system, it is convenient to create a dedicated @code{buildbot}
6046 user, then set @code{distrib_port} to
6047 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
6048 configuration will make the HTML status page available at
6049 @code{http://host/~buildbot/} . Suitable URL remapping can make it
6050 appear at @code{http://host/buildbot/}, and the right virtual host
6051 setup can even place it at @code{http://buildbot.host/} .
6053 The other @code{WebStatus} argument is @code{allowForce}. If set to
6054 True, then the web page will provide a ``Force Build'' button that
6055 allows visitors to manually trigger builds. This is useful for
6056 developers to re-run builds that have failed because of intermittent
6057 problems in the test suite, or because of libraries that were not
6058 installed at the time of the previous build. You may not wish to allow
6059 strangers to cause a build to run: in that case, set this to False to
6060 remove these buttons. The default value is False.
6064 @node Buildbot Web Resources, XMLRPC server, WebStatus Configuration Parameters, WebStatus
6065 @subsection Buildbot Web Resources
6067 Certain URLs are ``magic'', and the pages they serve are created by
6068 code in various classes in the @file{buildbot.status.web} package
6069 instead of being read from disk. The most common way to access these
6070 pages is for the buildmaster admin to write or modify the
6071 @file{index.html} page to contain links to them. Of course other
6072 project web pages can contain links to these buildbot pages as well.
6074 Many pages can be modified by adding query arguments to the URL. For
6075 example, a page which shows the results of the most recent build
6076 normally does this for all builders at once. But by appending
6077 ``?builder=i386'' to the end of the URL, the page will show only the
6078 results for the ``i386'' builder. When used in this way, you can add
6079 multiple ``builder='' arguments to see multiple builders. Remembering
6080 that URL query arguments are separated @emph{from each other} with
6081 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
6082 show builds for just those two Builders.
6084 The @code{branch=} query argument can be used on some pages. This
6085 filters the information displayed by that page down to only the builds
6086 or changes which involved the given branch. Use @code{branch=trunk} to
6087 reference the trunk: if you aren't intentionally using branches,
6088 you're probably using trunk. Multiple @code{branch=} arguments can be
6089 used to examine multiple branches at once (so appending
6090 @code{?branch=foo&branch=bar} to the URL will show builds involving
6091 either branch). No @code{branch=} arguments means to show builds and
6092 changes for all branches.
6094 Some pages may include the Builder name or the build number in the
6095 main part of the URL itself. For example, a page that describes Build
6096 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
6098 The table below lists all of the internal pages and the URLs that can
6099 be used to access them.
6101 NOTE: of the pages described here, @code{/slave_status_timeline} and
6102 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
6103 has only a few methods so far. Future releases will improve this.
6105 @table @code
6107 @item /waterfall
6109 This provides a chronologically-oriented display of the activity of
6110 all builders. It is the same display used by the Waterfall display.
6112 By adding one or more ``builder='' query arguments, the Waterfall is
6113 restricted to only showing information about the given Builders. By
6114 adding one or more ``branch='' query arguments, the display is
6115 restricted to showing information about the given branches.
6117 A 'show_events=true' query argument causes the display to include
6118 non-Build events, like slaves attaching and detaching, as well as
6119 reconfiguration events. 'show_events=false' hides these events. The
6120 default is to show them.
6122 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
6123 arguments will control what interval of time is displayed. The default
6124 is to show the latest events, but these can be used to look at earlier
6125 periods in history. The @code{num_events=} argument also provides a
6126 limit on the size of the displayed page.
6128 The Waterfall has references to resources many of the other portions
6129 of the URL space: @file{/builders} for access to individual builds,
6130 @file{/changes} for access to information about source code changes,
6131 etc.
6133 @item /builders/$BUILDERNAME
6135 This describes the given Builder, and provides buttons to force a build.
6137 @item /builders/$BUILDERNAME/builds/$BUILDNUM
6139 This describes a specific Build.
6141 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
6143 This describes a specific BuildStep.
6145 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
6147 This provides an HTML representation of a specific logfile.
6149 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
6151 This returns the logfile as plain text, without any HTML coloring
6152 markup. It also removes the ``headers'', which are the lines that
6153 describe what command was run and what the environment variable
6154 settings were like. This maybe be useful for saving to disk and
6155 feeding to tools like 'grep'.
6157 @item /changes
6159 This provides a brief description of the ChangeSource in use
6160 (@pxref{Change Sources}).
6162 @item /changes/NN
6164 This shows detailed information about the numbered Change: who was the
6165 author, what files were changed, what revision number was represented,
6166 etc.
6168 @item /buildslaves
6170 This summarizes each BuildSlave, including which Builders are
6171 configured to use it, whether the buildslave is currently connected or
6172 not, and host information retrieved from the buildslave itself.
6174 @item /one_line_per_build
6176 This page shows one line of text for each build, merging information
6177 from all Builders@footnote{Apparently this is the same way
6178 http://buildd.debian.org displays build status}. Each line specifies
6179 the name of the Builder, the number of the Build, what revision it
6180 used, and a summary of the results. Successful builds are in green,
6181 while failing builds are in red. The date and time of the build are
6182 added to the right-hand edge of the line. The lines are ordered by
6183 build finish timestamp.
6185 One or more @code{builder=} or @code{branch=} arguments can be used to
6186 restrict the list. In addition, a @code{numbuilds=} argument will
6187 control how many lines are displayed (20 by default).
6189 @item /one_box_per_builder
6191 This page shows a small table, with one box for each Builder,
6192 containing the results of the most recent Build. It does not show the
6193 individual steps, or the current status. This is a simple summary of
6194 buildbot status: if this page is green, then all tests are passing.
6196 As with @code{/one_line_per_build}, this page will also honor
6197 @code{builder=} and @code{branch=} arguments.
6199 @item /about
6201 This page gives a brief summary of the Buildbot itself: software
6202 version, versions of some libraries that the Buildbot depends upon,
6203 etc. It also contains a link to the buildbot.net home page.
6205 @item /slave_status_timeline
6207 (note: this page has not yet been implemented)
6209 This provides a chronological display of configuration and operational
6210 events: master startup/shutdown, slave connect/disconnect, and
6211 config-file changes. When a config-file reload is abandoned because of
6212 an error in the config file, the error is displayed on this page.
6214 This page does not show any builds.
6216 @item /last_build/$BUILDERNAME/status.png
6218 This returns a PNG image that describes the results of the most recent
6219 build, which can be referenced in an IMG tag by other pages, perhaps
6220 from a completely different site. Use it as you would a webcounter.
6222 @end table
6224 There are also a set of web-status resources that are intended for use
6225 by other programs, rather than humans.
6227 @table @code
6229 @item /xmlrpc
6231 This runs an XML-RPC server which can be used to query status
6232 information about various builds. See @ref{XMLRPC server} for more
6233 details.
6235 @end table
6237 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
6238 @subsection XMLRPC server
6240 When using WebStatus, the buildbot runs an XML-RPC server at
6241 @file{/xmlrpc} that can be used by other programs to query build
6242 status. The following table lists the methods that can be invoked
6243 using this interface.
6245 @table @code
6246 @item getAllBuildsInInterval(start, stop)
6248 Return a list of builds that have completed after the 'start'
6249 timestamp and before the 'stop' timestamp. This looks at all Builders.
6251 The timestamps are integers, interpreted as standard unix timestamps
6252 (seconds since epoch).
6254 Each Build is returned as a tuple in the form: @code{(buildername,
6255 buildnumber, build_end, branchname, revision, results, text)}
6257 The buildnumber is an integer. 'build_end' is an integer (seconds
6258 since epoch) specifying when the build finished.
6260 The branchname is a string, which may be an empty string to indicate
6261 None (i.e. the default branch). The revision is a string whose meaning
6262 is specific to the VC system in use, and comes from the 'got_revision'
6263 build property. The results are expressed as a string, one of
6264 ('success', 'warnings', 'failure', 'exception'). The text is a list of
6265 short strings that ought to be joined by spaces and include slightly
6266 more data about the results of the build.
6268 @item getBuild(builder_name, build_number)
6270 Return information about a specific build.
6272 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
6273 complete information about the build. It does not include the contents
6274 of the log files, but it has just about everything else.
6276 @end table
6278 @node HTML Waterfall,  , XMLRPC server, WebStatus
6279 @subsection HTML Waterfall
6281 @cindex Waterfall
6282 @stindex buildbot.status.html.Waterfall
6284 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
6285 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
6286 This section (and the @code{Waterfall} class itself) will be removed
6287 from a future release.
6289 @example
6290 from buildbot.status import html
6291 w = html.Waterfall(http_port=8080)
6292 c['status'].append(w)
6293 @end example
6297 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
6298 @section MailNotifier
6300 @cindex email
6301 @cindex mail
6302 @stindex buildbot.status.mail.MailNotifier
6304 The buildbot can also send email when builds finish. The most common
6305 use of this is to tell developers when their change has caused the
6306 build to fail. It is also quite common to send a message to a mailing
6307 list (usually named ``builds'' or similar) about every build.
6309 The @code{MailNotifier} status target is used to accomplish this. You
6310 configure it by specifying who mail should be sent to, under what
6311 circumstances mail should be sent, and how to deliver the mail. It can
6312 be configured to only send out mail for certain builders, and only
6313 send messages when the build fails, or when the builder transitions
6314 from success to failure. It can also be configured to include various
6315 build logs in each message.
6318 By default, the message will be sent to the Interested Users list
6319 (@pxref{Doing Things With Users}), which includes all developers who
6320 made changes in the build. You can add additional recipients with the
6321 extraRecipients argument.
6323 Each MailNotifier sends mail to a single set of recipients. To send
6324 different kinds of mail to different recipients, use multiple
6325 MailNotifiers.
6327 The following simple example will send an email upon the completion of
6328 each build, to just those developers whose Changes were included in
6329 the build. The email contains a description of the Build, its results,
6330 and URLs where more information can be obtained.
6332 @example
6333 from buildbot.status.mail import MailNotifier
6334 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
6335 c['status'].append(mn)
6336 @end example
6338 To get a simple one-message-per-build (say, for a mailing list), use
6339 the following form instead. This form does not send mail to individual
6340 developers (and thus does not need the @code{lookup=} argument,
6341 explained below), instead it only ever sends mail to the ``extra
6342 recipients'' named in the arguments:
6344 @example
6345 mn = MailNotifier(fromaddr="buildbot@@example.org",
6346                   sendToInterestedUsers=False,
6347                   extraRecipients=['listaddr@@example.org'])
6348 @end example
6350 @heading MailNotifier arguments
6352 @table @code
6353 @item fromaddr
6354 The email address to be used in the 'From' header.
6356 @item sendToInterestedUsers
6357 (boolean). If True (the default), send mail to all of the Interested
6358 Users. If False, only send mail to the extraRecipients list.
6360 @item extraRecipients
6361 (tuple of strings). A list of email addresses to which messages should
6362 be sent (in addition to the InterestedUsers list, which includes any
6363 developers who made Changes that went into this build). It is a good
6364 idea to create a small mailing list and deliver to that, then let
6365 subscribers come and go as they please.
6367 @item subject
6368 (string). A string to be used as the subject line of the message.
6369 @code{%(builder)s} will be replaced with the name of the builder which
6370 provoked the message.
6372 @item mode
6373 (string). Default to 'all'. One of:
6374 @table @code
6375 @item all
6376 Send mail about all builds, bothpassing and failing
6377 @item failing
6378 Only send mail about builds which fail
6379 @item problem
6380 Only send mail about a build which failed when the previous build has passed.
6381 If your builds usually pass, then this will only send mail when a problem
6382 occurs.
6383 @end table
6385 @item builders
6386 (list of strings). A list of builder names for which mail should be
6387 sent. Defaults to None (send mail for all builds). Use either builders
6388 or categories, but not both.
6390 @item categories
6391 (list of strings). A list of category names to serve status
6392 information for. Defaults to None (all categories). Use either
6393 builders or categories, but not both.
6395 @item addLogs
6396 (boolean). If True, include all build logs as attachments to the
6397 messages. These can be quite large. This can also be set to a list of
6398 log names, to send a subset of the logs. Defaults to False.
6400 @item relayhost
6401 (string). The host to which the outbound SMTP connection should be
6402 made. Defaults to 'localhost'
6404 @item lookup
6405 (implementor of @code{IEmailLookup}). Object which provides
6406 IEmailLookup, which is responsible for mapping User names (which come
6407 from the VC system) into valid email addresses. If not provided, the
6408 notifier will only be able to send mail to the addresses in the
6409 extraRecipients list. Most of the time you can use a simple Domain
6410 instance. As a shortcut, you can pass as string: this will be treated
6411 as if you had provided Domain(str). For example,
6412 lookup='twistedmatrix.com' will allow mail to be sent to all
6413 developers whose SVN usernames match their twistedmatrix.com account
6414 names. See buildbot/status/mail.py for more details.
6416 @end table
6419 @node IRC Bot, PBListener, MailNotifier, Status Delivery
6420 @section IRC Bot
6422 @cindex IRC
6423 @stindex buildbot.status.words.IRC
6426 The @code{buildbot.status.words.IRC} status target creates an IRC bot
6427 which will attach to certain channels and be available for status
6428 queries. It can also be asked to announce builds as they occur, or be
6429 told to shut up.
6431 @example
6432 from twisted.status import words
6433 irc = words.IRC("irc.example.org", "botnickname", 
6434                 channels=["channel1", "channel2"],
6435                 password="mysecretpassword")
6436 c['status'].append(irc)
6437 @end example
6439 Take a look at the docstring for @code{words.IRC} for more details on
6440 configuring this service. The @code{password} argument, if provided,
6441 will be sent to Nickserv to claim the nickname: some IRC servers will
6442 not allow clients to send private messages until they have logged in
6443 with a password.
6445 To use the service, you address messages at the buildbot, either
6446 normally (@code{botnickname: status}) or with private messages
6447 (@code{/msg botnickname status}). The buildbot will respond in kind.
6449 Some of the commands currently available:
6451 @table @code
6453 @item list builders
6454 Emit a list of all configured builders
6455 @item status BUILDER
6456 Announce the status of a specific Builder: what it is doing right now.
6457 @item status all
6458 Announce the status of all Builders
6459 @item watch BUILDER
6460 If the given Builder is currently running, wait until the Build is
6461 finished and then announce the results.
6462 @item last BUILDER
6463 Return the results of the last build to run on the given Builder.
6465 @item help COMMAND
6466 Describe a command. Use @code{help commands} to get a list of known
6467 commands.
6468 @item source
6469 Announce the URL of the Buildbot's home page.
6470 @item version
6471 Announce the version of this Buildbot.
6472 @end table
6474 If the @code{allowForce=True} option was used, some addtional commands
6475 will be available:
6477 @table @code
6478 @item force build BUILDER REASON
6479 Tell the given Builder to start a build of the latest code. The user
6480 requesting the build and REASON are recorded in the Build status. The
6481 buildbot will announce the build's status when it finishes.
6483 @item stop build BUILDER REASON
6484 Terminate any running build in the given Builder. REASON will be added
6485 to the build status to explain why it was stopped. You might use this
6486 if you committed a bug, corrected it right away, and don't want to
6487 wait for the first build (which is destined to fail) to complete
6488 before starting the second (hopefully fixed) build.
6489 @end table
6491 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
6492 @section PBListener
6494 @cindex PBListener
6495 @stindex buildbot.status.client.PBListener
6498 @example
6499 import buildbot.status.client
6500 pbl = buildbot.status.client.PBListener(port=int, user=str,
6501                                         passwd=str)
6502 c['status'].append(pbl)
6503 @end example
6505 This sets up a PB listener on the given TCP port, to which a PB-based
6506 status client can connect and retrieve status information.
6507 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
6508 status client. The @code{port} argument can also be a strports
6509 specification string.
6511 @node Writing New Status Plugins,  , PBListener, Status Delivery
6512 @section Writing New Status Plugins
6514 TODO: this needs a lot more examples
6516 Each status plugin is an object which provides the
6517 @code{twisted.application.service.IService} interface, which creates a
6518 tree of Services with the buildmaster at the top [not strictly true].
6519 The status plugins are all children of an object which implements
6520 @code{buildbot.interfaces.IStatus}, the main status object. From this
6521 object, the plugin can retrieve anything it wants about current and
6522 past builds. It can also subscribe to hear about new and upcoming
6523 builds.
6525 Status plugins which only react to human queries (like the Waterfall
6526 display) never need to subscribe to anything: they are idle until
6527 someone asks a question, then wake up and extract the information they
6528 need to answer it, then they go back to sleep. Plugins which need to
6529 act spontaneously when builds complete (like the MailNotifier plugin)
6530 need to subscribe to hear about new builds.
6532 If the status plugin needs to run network services (like the HTTP
6533 server used by the Waterfall plugin), they can be attached as Service
6534 children of the plugin itself, using the @code{IServiceCollection}
6535 interface.
6539 @node Command-line tool, Resources, Status Delivery, Top
6540 @chapter Command-line tool
6542 The @command{buildbot} command-line tool can be used to start or stop a
6543 buildmaster or buildbot, and to interact with a running buildmaster.
6544 Some of its subcommands are intended for buildmaster admins, while
6545 some are for developers who are editing the code that the buildbot is
6546 monitoring.
6548 @menu
6549 * Administrator Tools::         
6550 * Developer Tools::             
6551 * Other Tools::                 
6552 * .buildbot config directory::  
6553 @end menu
6555 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
6556 @section Administrator Tools
6558 The following @command{buildbot} sub-commands are intended for
6559 buildmaster administrators:
6561 @heading create-master
6563 This creates a new directory and populates it with files that allow it
6564 to be used as a buildmaster's base directory.
6566 @example
6567 buildbot create-master BASEDIR
6568 @end example
6570 @heading create-slave
6572 This creates a new directory and populates it with files that let it
6573 be used as a buildslave's base directory. You must provide several
6574 arguments, which are used to create the initial @file{buildbot.tac}
6575 file.
6577 @example
6578 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
6579 @end example
6581 @heading start
6583 This starts a buildmaster or buildslave which was already created in
6584 the given base directory. The daemon is launched in the background,
6585 with events logged to a file named @file{twistd.log}.
6587 @example
6588 buildbot start BASEDIR
6589 @end example
6591 @heading stop
6593 This terminates the daemon (either buildmaster or buildslave) running
6594 in the given directory.
6596 @example
6597 buildbot stop BASEDIR
6598 @end example
6600 @heading sighup
6602 This sends a SIGHUP to the buildmaster running in the given directory,
6603 which causes it to re-read its @file{master.cfg} file.
6605 @example
6606 buildbot sighup BASEDIR
6607 @end example
6609 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
6610 @section Developer Tools
6612 These tools are provided for use by the developers who are working on
6613 the code that the buildbot is monitoring.
6615 @menu
6616 * statuslog::                   
6617 * statusgui::                   
6618 * try::                         
6619 @end menu
6621 @node statuslog, statusgui, Developer Tools, Developer Tools
6622 @subsection statuslog
6624 @example
6625 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
6626 @end example
6628 This command starts a simple text-based status client, one which just
6629 prints out a new line each time an event occurs on the buildmaster.
6631 The @option{--master} option provides the location of the
6632 @code{buildbot.status.client.PBListener} status port, used to deliver
6633 build information to realtime status clients. The option is always in
6634 the form of a string, with hostname and port number separated by a
6635 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
6636 same as the slaveport (although a future version may allow the same
6637 port number to be used for both purposes). If you get an error message
6638 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
6639 this may indicate that you are connecting to the slaveport rather than
6640 a @code{PBListener} port.
6642 The @option{--master} option can also be provided by the
6643 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
6644 config directory}).
6646 @node statusgui, try, statuslog, Developer Tools
6647 @subsection statusgui
6649 @cindex statusgui
6651 If you have set up a PBListener (@pxref{PBListener}), you will be able
6652 to monitor your Buildbot using a simple Gtk+ application invoked with
6653 the @code{buildbot statusgui} command:
6655 @example
6656 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
6657 @end example
6659 This command starts a simple Gtk+-based status client, which contains
6660 a few boxes for each Builder that change color as events occur. It
6661 uses the same @option{--master} argument as the @command{buildbot
6662 statuslog} command (@pxref{statuslog}).
6664 @node try,  , statusgui, Developer Tools
6665 @subsection try
6667 This lets a developer to ask the question ``What would happen if I
6668 committed this patch right now?''. It runs the unit test suite (across
6669 multiple build platforms) on the developer's current code, allowing
6670 them to make sure they will not break the tree when they finally
6671 commit their changes.
6673 The @command{buildbot try} command is meant to be run from within a
6674 developer's local tree, and starts by figuring out the base revision
6675 of that tree (what revision was current the last time the tree was
6676 updated), and a patch that can be applied to that revision of the tree
6677 to make it match the developer's copy. This (revision, patch) pair is
6678 then sent to the buildmaster, which runs a build with that
6679 SourceStamp. If you want, the tool will emit status messages as the
6680 builds run, and will not terminate until the first failure has been
6681 detected (or the last success).
6683 There is an alternate form which accepts a pre-made patch file
6684 (typically the output of a command like 'svn diff'). This ``--diff''
6685 form does not require a local tree to run from. See @xref{try --diff}.
6687 For this command to work, several pieces must be in place:
6690 @heading TryScheduler
6692 @slindex buildbot.scheduler.Try_Jobdir
6693 @slindex buildbot.scheduler.Try_Userpass
6695 The buildmaster must have a @code{scheduler.Try} instance in
6696 the config file's @code{c['schedulers']} list. This lets the
6697 administrator control who may initiate these ``trial'' builds, which
6698 branches are eligible for trial builds, and which Builders should be
6699 used for them.
6701 The @code{TryScheduler} has various means to accept build requests:
6702 all of them enforce more security than the usual buildmaster ports do.
6703 Any source code being built can be used to compromise the buildslave
6704 accounts, but in general that code must be checked out from the VC
6705 repository first, so only people with commit privileges can get
6706 control of the buildslaves. The usual force-build control channels can
6707 waste buildslave time but do not allow arbitrary commands to be
6708 executed by people who don't have those commit privileges. However,
6709 the source code patch that is provided with the trial build does not
6710 have to go through the VC system first, so it is important to make
6711 sure these builds cannot be abused by a non-committer to acquire as
6712 much control over the buildslaves as a committer has. Ideally, only
6713 developers who have commit access to the VC repository would be able
6714 to start trial builds, but unfortunately the buildmaster does not, in
6715 general, have access to VC system's user list.
6717 As a result, the @code{TryScheduler} requires a bit more
6718 configuration. There are currently two ways to set this up:
6720 @table @strong
6721 @item jobdir (ssh)
6723 This approach creates a command queue directory, called the
6724 ``jobdir'', in the buildmaster's working directory. The buildmaster
6725 admin sets the ownership and permissions of this directory to only
6726 grant write access to the desired set of developers, all of whom must
6727 have accounts on the machine. The @code{buildbot try} command creates
6728 a special file containing the source stamp information and drops it in
6729 the jobdir, just like a standard maildir. When the buildmaster notices
6730 the new file, it unpacks the information inside and starts the builds.
6732 The config file entries used by 'buildbot try' either specify a local
6733 queuedir (for which write and mv are used) or a remote one (using scp
6734 and ssh).
6736 The advantage of this scheme is that it is quite secure, the
6737 disadvantage is that it requires fiddling outside the buildmaster
6738 config (to set the permissions on the jobdir correctly). If the
6739 buildmaster machine happens to also house the VC repository, then it
6740 can be fairly easy to keep the VC userlist in sync with the
6741 trial-build userlist. If they are on different machines, this will be
6742 much more of a hassle. It may also involve granting developer accounts
6743 on a machine that would not otherwise require them.
6745 To implement this, the buildslave invokes 'ssh -l username host
6746 buildbot tryserver ARGS', passing the patch contents over stdin. The
6747 arguments must include the inlet directory and the revision
6748 information.
6750 @item user+password (PB)
6752 In this approach, each developer gets a username/password pair, which
6753 are all listed in the buildmaster's configuration file. When the
6754 developer runs @code{buildbot try}, their machine connects to the
6755 buildmaster via PB and authenticates themselves using that username
6756 and password, then sends a PB command to start the trial build.
6758 The advantage of this scheme is that the entire configuration is
6759 performed inside the buildmaster's config file. The disadvantages are
6760 that it is less secure (while the ``cred'' authentication system does
6761 not expose the password in plaintext over the wire, it does not offer
6762 most of the other security properties that SSH does). In addition, the
6763 buildmaster admin is responsible for maintaining the username/password
6764 list, adding and deleting entries as developers come and go.
6766 @end table
6769 For example, to set up the ``jobdir'' style of trial build, using a
6770 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
6771 all your project developers were members of the @code{developers} unix
6772 group), you would first create that directory (with @command{mkdir
6773 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
6774 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
6775 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
6776 MASTERDIR/jobdir/*}), and then use the following scheduler in the
6777 buildmaster's config file:
6779 @example
6780 from buildbot.scheduler import Try_Jobdir
6781 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
6782                jobdir="jobdir")
6783 c['schedulers'] = [s]
6784 @end example
6786 Note that you must create the jobdir before telling the buildmaster to
6787 use this configuration, otherwise you will get an error. Also remember
6788 that the buildmaster must be able to read and write to the jobdir as
6789 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
6790 as you start using the jobdir, to make sure the buildmaster is happy
6791 with it.
6793 To use the username/password form of authentication, create a
6794 @code{Try_Userpass} instance instead. It takes the same
6795 @code{builderNames} argument as the @code{Try_Jobdir} form, but
6796 accepts an addtional @code{port} argument (to specify the TCP port to
6797 listen on) and a @code{userpass} list of username/password pairs to
6798 accept. Remember to use good passwords for this: the security of the
6799 buildslave accounts depends upon it:
6801 @example
6802 from buildbot.scheduler import Try_Userpass
6803 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
6804                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
6805 c['schedulers'] = [s]
6806 @end example
6808 Like most places in the buildbot, the @code{port} argument takes a
6809 strports specification. See @code{twisted.application.strports} for
6810 details.
6813 @heading locating the master
6815 The @command{try} command needs to be told how to connect to the
6816 @code{TryScheduler}, and must know which of the authentication
6817 approaches described above is in use by the buildmaster. You specify
6818 the approach by using @option{--connect=ssh} or @option{--connect=pb}
6819 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
6820 @file{.buildbot/options}).
6822 For the PB approach, the command must be given a @option{--master}
6823 argument (in the form HOST:PORT) that points to TCP port that you
6824 picked in the @code{Try_Userpass} scheduler. It also takes a
6825 @option{--username} and @option{--passwd} pair of arguments that match
6826 one of the entries in the buildmaster's @code{userpass} list. These
6827 arguments can also be provided as @code{try_master},
6828 @code{try_username}, and @code{try_password} entries in the
6829 @file{.buildbot/options} file.
6831 For the SSH approach, the command must be given @option{--tryhost},
6832 @option{--username}, and optionally @option{--password} (TODO:
6833 really?) to get to the buildmaster host. It must also be given
6834 @option{--trydir}, which points to the inlet directory configured
6835 above. The trydir can be relative to the user's home directory, but
6836 most of the time you will use an explicit path like
6837 @file{~buildbot/project/trydir}. These arguments can be provided in
6838 @file{.buildbot/options} as @code{try_host}, @code{try_username},
6839 @code{try_password}, and @code{try_dir}.
6841 In addition, the SSH approach needs to connect to a PBListener status
6842 port, so it can retrieve and report the results of the build (the PB
6843 approach uses the existing connection to retrieve status information,
6844 so this step is not necessary). This requires a @option{--master}
6845 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
6846 in the form of a HOSTNAME:PORT string.
6849 @heading choosing the Builders
6851 A trial build is performed on multiple Builders at the same time, and
6852 the developer gets to choose which Builders are used (limited to a set
6853 selected by the buildmaster admin with the TryScheduler's
6854 @code{builderNames=} argument). The set you choose will depend upon
6855 what your goals are: if you are concerned about cross-platform
6856 compatibility, you should use multiple Builders, one from each
6857 platform of interest. You might use just one builder if that platform
6858 has libraries or other facilities that allow better test coverage than
6859 what you can accomplish on your own machine, or faster test runs.
6861 The set of Builders to use can be specified with multiple
6862 @option{--builder} arguments on the command line. It can also be
6863 specified with a single @code{try_builders} option in
6864 @file{.buildbot/options} that uses a list of strings to specify all
6865 the Builder names:
6867 @example
6868 try_builders = ["full-OSX", "full-win32", "full-linux"]
6869 @end example
6871 @heading specifying the VC system
6873 The @command{try} command also needs to know how to take the
6874 developer's current tree and extract the (revision, patch)
6875 source-stamp pair. Each VC system uses a different process, so you
6876 start by telling the @command{try} command which VC system you are
6877 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
6878 This can also be provided as @code{try_vc} in
6879 @file{.buildbot/options}.
6881 The following names are recognized: @code{cvs} @code{svn} @code{baz}
6882 @code{tla} @code{hg} @code{darcs}
6885 @heading finding the top of the tree
6887 Some VC systems (notably CVS and SVN) track each directory
6888 more-or-less independently, which means the @command{try} command
6889 needs to move up to the top of the project tree before it will be able
6890 to construct a proper full-tree patch. To accomplish this, the
6891 @command{try} command will crawl up through the parent directories
6892 until it finds a marker file. The default name for this marker file is
6893 @file{.buildbot-top}, so when you are using CVS or SVN you should
6894 @code{touch .buildbot-top} from the top of your tree before running
6895 @command{buildbot try}. Alternatively, you can use a filename like
6896 @file{ChangeLog} or @file{README}, since many projects put one of
6897 these files in their top-most directory (and nowhere else). To set
6898 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
6899 options file with @code{try_topfile = 'ChangeLog'}.
6901 You can also manually set the top of the tree with
6902 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
6903 '~/trees/mytree'}. If you use @code{try_topdir}, in a
6904 @file{.buildbot/options} file, you will need a separate options file
6905 for each tree you use, so it may be more convenient to use the
6906 @code{try_topfile} approach instead.
6908 Other VC systems which work on full projects instead of individual
6909 directories (tla, baz, darcs, monotone, mercurial) do not require
6910 @command{try} to know the top directory, so the @option{--try-topfile}
6911 and @option{--try-topdir} arguments will be ignored.
6912 @c is this true? I think I currently require topdirs all the time.
6914 If the @command{try} command cannot find the top directory, it will
6915 abort with an error message.
6917 @heading determining the branch name
6919 Some VC systems record the branch information in a way that ``try''
6920 can locate it, in particular Arch (both @command{tla} and
6921 @command{baz}). For the others, if you are using something other than
6922 the default branch, you will have to tell the buildbot which branch
6923 your tree is using. You can do this with either the @option{--branch}
6924 argument, or a @option{try_branch} entry in the
6925 @file{.buildbot/options} file.
6927 @heading determining the revision and patch
6929 Each VC system has a separate approach for determining the tree's base
6930 revision and computing a patch.
6932 @table @code
6934 @item CVS
6936 @command{try} pretends that the tree is up to date. It converts the
6937 current time into a @code{-D} time specification, uses it as the base
6938 revision, and computes the diff between the upstream tree as of that
6939 point in time versus the current contents. This works, more or less,
6940 but requires that the local clock be in reasonably good sync with the
6941 repository.
6943 @item SVN
6944 @command{try} does a @code{svn status -u} to find the latest
6945 repository revision number (emitted on the last line in the ``Status
6946 against revision: NN'' message). It then performs an @code{svn diff
6947 -rNN} to find out how your tree differs from the repository version,
6948 and sends the resulting patch to the buildmaster. If your tree is not
6949 up to date, this will result in the ``try'' tree being created with
6950 the latest revision, then @emph{backwards} patches applied to bring it
6951 ``back'' to the version you actually checked out (plus your actual
6952 code changes), but this will still result in the correct tree being
6953 used for the build.
6955 @item baz
6956 @command{try} does a @code{baz tree-id} to determine the
6957 fully-qualified version and patch identifier for the tree
6958 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
6959 as the base revision. It then does a @code{baz diff} to obtain the
6960 patch.
6962 @item tla
6963 @command{try} does a @code{tla tree-version} to get the
6964 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
6965 first line of @code{tla logs --reverse} to figure out the base
6966 revision. Then it does @code{tla changes --diffs} to obtain the patch.
6968 @item Darcs
6969 @code{darcs changes --context} emits a text file that contains a list
6970 of all patches back to and including the last tag was made. This text
6971 file (plus the location of a repository that contains all these
6972 patches) is sufficient to re-create the tree. Therefore the contents
6973 of this ``context'' file @emph{are} the revision stamp for a
6974 Darcs-controlled source tree.
6976 So @command{try} does a @code{darcs changes --context} to determine
6977 what your tree's base revision is, and then does a @code{darcs diff
6978 -u} to compute the patch relative to that revision.
6980 @item Mercurial
6981 @code{hg identify} emits a short revision ID (basically a truncated
6982 SHA1 hash of the current revision's contents), which is used as the
6983 base revision. @code{hg diff} then provides the patch relative to that
6984 revision. For @command{try} to work, your working directory must only
6985 have patches that are available from the same remotely-available
6986 repository that the build process' @code{step.Mercurial} will use.
6988 @c TODO: monotone, git
6989 @end table
6991 @heading waiting for results
6993 If you provide the @option{--wait} option (or @code{try_wait = True}
6994 in @file{.buildbot/options}), the @command{buildbot try} command will
6995 wait until your changes have either been proven good or bad before
6996 exiting. Unless you use the @option{--quiet} option (or
6997 @code{try_quiet=True}), it will emit a progress message every 60
6998 seconds until the builds have completed.
7000 @menu
7001 * try --diff::                  
7002 @end menu
7004 @node try --diff,  , try, try
7005 @subsubsection try --diff
7007 Sometimes you might have a patch from someone else that you want to
7008 submit to the buildbot. For example, a user may have created a patch
7009 to fix some specific bug and sent it to you by email. You've inspected
7010 the patch and suspect that it might do the job (and have at least
7011 confirmed that it doesn't do anything evil). Now you want to test it
7012 out.
7014 One approach would be to check out a new local tree, apply the patch,
7015 run your local tests, then use ``buildbot try'' to run the tests on
7016 other platforms. An alternate approach is to use the @command{buildbot
7017 try --diff} form to have the buildbot test the patch without using a
7018 local tree.
7020 This form takes a @option{--diff} argument which points to a file that
7021 contains the patch you want to apply. By default this patch will be
7022 applied to the TRUNK revision, but if you give the optional
7023 @option{--baserev} argument, a tree of the given revision will be used
7024 as a starting point instead of TRUNK.
7026 You can also use @command{buildbot try --diff=-} to read the patch
7027 from stdin.
7029 Each patch has a ``patchlevel'' associated with it. This indicates the
7030 number of slashes (and preceding pathnames) that should be stripped
7031 before applying the diff. This exactly corresponds to the @option{-p}
7032 or @option{--strip} argument to the @command{patch} utility. By
7033 default @command{buildbot try --diff} uses a patchlevel of 0, but you
7034 can override this with the @option{-p} argument.
7036 When you use @option{--diff}, you do not need to use any of the other
7037 options that relate to a local tree, specifically @option{--vc},
7038 @option{--try-topfile}, or @option{--try-topdir}. These options will
7039 be ignored. Of course you must still specify how to get to the
7040 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
7043 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
7044 @section Other Tools
7046 These tools are generally used by buildmaster administrators.
7048 @menu
7049 * sendchange::                  
7050 * debugclient::                 
7051 @end menu
7053 @node sendchange, debugclient, Other Tools, Other Tools
7054 @subsection sendchange
7056 This command is used to tell the buildmaster about source changes. It
7057 is intended to be used from within a commit script, installed on the
7058 VC server. It requires that you have a PBChangeSource
7059 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
7060 @code{c['change_source']}).
7063 @example
7064 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
7065 @end example
7067 There are other (optional) arguments which can influence the
7068 @code{Change} that gets submitted:
7070 @table @code
7071 @item --branch
7072 This provides the (string) branch specifier. If omitted, it defaults
7073 to None, indicating the ``default branch''. All files included in this
7074 Change must be on the same branch.
7076 @item --revision_number
7077 This provides a (numeric) revision number for the change, used for VC systems
7078 that use numeric transaction numbers (like Subversion).
7080 @item --revision
7081 This provides a (string) revision specifier, for VC systems that use
7082 strings (Arch would use something like patch-42 etc).
7084 @item --revision_file
7085 This provides a filename which will be opened and the contents used as
7086 the revision specifier. This is specifically for Darcs, which uses the
7087 output of @command{darcs changes --context} as a revision specifier.
7088 This context file can be a couple of kilobytes long, spanning a couple
7089 lines per patch, and would be a hassle to pass as a command-line
7090 argument.
7092 @item --comments
7093 This provides the change comments as a single argument. You may want
7094 to use @option{--logfile} instead.
7096 @item --logfile
7097 This instructs the tool to read the change comments from the given
7098 file. If you use @code{-} as the filename, the tool will read the
7099 change comments from stdin.
7100 @end table
7103 @node debugclient,  , sendchange, Other Tools
7104 @subsection debugclient
7106 @example
7107 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
7108 @end example
7110 This launches a small Gtk+/Glade-based debug tool, connecting to the
7111 buildmaster's ``debug port''. This debug port shares the same port
7112 number as the slaveport (@pxref{Setting the slaveport}), but the
7113 @code{debugPort} is only enabled if you set a debug password in the
7114 buildmaster's config file (@pxref{Debug options}). The
7115 @option{--passwd} option must match the @code{c['debugPassword']}
7116 value.
7118 @option{--master} can also be provided in @file{.debug/options} by the
7119 @code{master} key. @option{--passwd} can be provided by the
7120 @code{debugPassword} key.
7122 The @code{Connect} button must be pressed before any of the other
7123 buttons will be active. This establishes the connection to the
7124 buildmaster. The other sections of the tool are as follows:
7126 @table @code
7127 @item Reload .cfg
7128 Forces the buildmaster to reload its @file{master.cfg} file. This is
7129 equivalent to sending a SIGHUP to the buildmaster, but can be done
7130 remotely through the debug port. Note that it is a good idea to be
7131 watching the buildmaster's @file{twistd.log} as you reload the config
7132 file, as any errors which are detected in the config file will be
7133 announced there.
7135 @item Rebuild .py
7136 (not yet implemented). The idea here is to use Twisted's ``rebuild''
7137 facilities to replace the buildmaster's running code with a new
7138 version. Even if this worked, it would only be used by buildbot
7139 developers.
7141 @item poke IRC
7142 This locates a @code{words.IRC} status target and causes it to emit a
7143 message on all the channels to which it is currently connected. This
7144 was used to debug a problem in which the buildmaster lost the
7145 connection to the IRC server and did not attempt to reconnect.
7147 @item Commit
7148 This allows you to inject a Change, just as if a real one had been
7149 delivered by whatever VC hook you are using. You can set the name of
7150 the committed file and the name of the user who is doing the commit.
7151 Optionally, you can also set a revision for the change. If the
7152 revision you provide looks like a number, it will be sent as an
7153 integer, otherwise it will be sent as a string.
7155 @item Force Build
7156 This lets you force a Builder (selected by name) to start a build of
7157 the current source tree.
7159 @item Currently
7160 (obsolete). This was used to manually set the status of the given
7161 Builder, but the status-assignment code was changed in an incompatible
7162 way and these buttons are no longer meaningful.
7164 @end table
7167 @node .buildbot config directory,  , Other Tools, Command-line tool
7168 @section .buildbot config directory
7170 Many of the @command{buildbot} tools must be told how to contact the
7171 buildmaster that they interact with. This specification can be
7172 provided as a command-line argument, but most of the time it will be
7173 easier to set them in an ``options'' file. The @command{buildbot}
7174 command will look for a special directory named @file{.buildbot},
7175 starting from the current directory (where the command was run) and
7176 crawling upwards, eventually looking in the user's home directory. It
7177 will look for a file named @file{options} in this directory, and will
7178 evaluate it as a python script, looking for certain names to be set.
7179 You can just put simple @code{name = 'value'} pairs in this file to
7180 set the options.
7182 For a description of the names used in this file, please see the
7183 documentation for the individual @command{buildbot} sub-commands. The
7184 following is a brief sample of what this file's contents could be.
7186 @example
7187 # for status-reading tools
7188 masterstatus = 'buildbot.example.org:12345'
7189 # for 'sendchange' or the debug port
7190 master = 'buildbot.example.org:18990'
7191 debugPassword = 'eiv7Po'
7192 @end example
7194 @table @code
7195 @item masterstatus
7196 Location of the @code{client.PBListener} status port, used by
7197 @command{statuslog} and @command{statusgui}.
7199 @item master
7200 Location of the @code{debugPort} (for @command{debugclient}). Also the
7201 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
7202 Usually shares the slaveport, but a future version may make it
7203 possible to have these listen on a separate port number.
7205 @item debugPassword
7206 Must match the value of @code{c['debugPassword']}, used to protect the
7207 debug port, for the @command{debugclient} command.
7209 @item username
7210 Provides a default username for the @command{sendchange} command.
7212 @end table
7215 The following options are used by the @code{buildbot try} command
7216 (@pxref{try}):
7218 @table @code
7219 @item try_connect
7220 This specifies how the ``try'' command should deliver its request to
7221 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
7222 @item try_builders
7223 Which builders should be used for the ``try'' build.
7224 @item try_vc
7225 This specifies the version control system being used.
7226 @item try_branch
7227 This indicates that the current tree is on a non-trunk branch.
7228 @item try_topdir
7229 @item try_topfile
7230 Use @code{try_topdir} to explicitly indicate the top of your working
7231 tree, or @code{try_topfile} to name a file that will only be found in
7232 that top-most directory.
7234 @item try_host
7235 @item try_username
7236 @item try_dir
7237 When try_connect is ``ssh'', the command will pay attention to
7238 @code{try_host}, @code{try_username}, and @code{try_dir}.
7240 @item try_username
7241 @item try_password
7242 @item try_master
7243 Instead, when @code{try_connect} is ``pb'', the command will pay
7244 attention to @code{try_username}, @code{try_password}, and
7245 @code{try_master}.
7247 @item try_wait
7248 @item masterstatus
7249 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
7250 command to wait for the requested build to complete.
7252 @end table
7256 @node Resources, Developer's Appendix, Command-line tool, Top
7257 @chapter Resources
7259 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
7261 For configuration questions and general discussion, please use the
7262 @code{buildbot-devel} mailing list. The subscription instructions and
7263 archives are available at
7264 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
7266 @node Developer's Appendix, Index of Useful Classes, Resources, Top
7267 @unnumbered Developer's Appendix
7269 This appendix contains random notes about the implementation of the
7270 Buildbot, and is likely to only be of use to people intending to
7271 extend the Buildbot's internals.
7273 The buildmaster consists of a tree of Service objects, which is shaped
7274 as follows:
7276 @example
7277 BuildMaster
7278  ChangeMaster  (in .change_svc)
7279   [IChangeSource instances]
7280  [IScheduler instances]  (in .schedulers)
7281  BotMaster  (in .botmaster)
7282   [IBuildSlave instances]
7283  [IStatusTarget instances]  (in .statusTargets)
7284 @end example
7286 The BotMaster has a collection of Builder objects as values of its
7287 @code{.builders} dictionary.
7290 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
7291 @unnumbered Index of Useful Classes
7293 This is a list of all user-visible classes. There are the ones that
7294 are useful in @file{master.cfg}, the buildmaster's configuration file.
7295 Classes that are not listed here are generally internal things that
7296 admins are unlikely to have much use for.
7299 @heading Change Sources
7300 @printindex cs
7302 @heading Schedulers and Locks
7303 @printindex sl
7305 @heading Build Factories
7306 @printindex bf
7308 @heading Build Steps
7309 @printindex bs
7311 @c undocumented steps
7312 @bsindex buildbot.steps.source.Git
7313 @bsindex buildbot.steps.maxq.MaxQ
7316 @heading Status Targets
7317 @printindex st
7319 @c TODO: undocumented targets
7321 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
7322 @unnumbered Index of master.cfg keys
7324 This is a list of all of the significant keys in master.cfg . Recall
7325 that master.cfg is effectively a small python program with exactly one
7326 responsibility: create a dictionary named @code{BuildmasterConfig}.
7327 The keys of this dictionary are listed here. The beginning of the
7328 master.cfg file typically starts with something like:
7330 @example
7331 BuildmasterConfig = c = @{@}
7332 @end example
7334 Therefore a config key of @code{change_source} will usually appear in
7335 master.cfg as @code{c['change_source']}.
7337 @printindex bc
7340 @node Index,  , Index of master.cfg keys, Top
7341 @unnumbered Index
7343 @printindex cp
7346 @bye