buildbot statuslog: add reminders to connect to a PBListener port instead of the...
[buildbot.git] / docs / buildbot.texinfo
bloba683e4aa8f3ac85aceac6b8a0a801471de673754
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.4+
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 * Creating a buildslave::       
87 * Launching the daemons::       
88 * Logfiles::                    
89 * Shutdown::                    
90 * Maintenance::                 
91 * Troubleshooting::             
93 Creating a buildslave
95 * Buildslave Options::          
97 Troubleshooting
99 * Starting the buildslave::     
100 * Connecting to the buildmaster::  
101 * Forcing Builds::              
103 Concepts
105 * Version Control Systems::     
106 * Schedulers::                  
107 * BuildSet::                    
108 * BuildRequest::                
109 * Builder::                     
110 * Users::                       
112 Version Control Systems
114 * Generalizing VC Systems::     
115 * Source Tree Specifications::  
116 * How Different VC Systems Specify Sources::  
117 * Attributes of Changes::       
119 Users
121 * Doing Things With Users::     
122 * Email Addresses::             
123 * IRC Nicknames::               
124 * Live Status Clients::         
126 Configuration
128 * Config File Format::          
129 * Loading the Config File::     
130 * Defining the Project::        
131 * Listing Change Sources and Schedulers::  
132 * Setting the slaveport::       
133 * Buildslave Specifiers::       
134 * Defining Builders::           
135 * Defining Status Targets::     
136 * Debug options::               
138 Listing Change Sources and Schedulers
140 * Scheduler Types::             
141 * Build Dependencies::          
143 Getting Source Code Changes
145 * Change Sources::              
147 Change Sources
149 * Choosing ChangeSources::      
150 * CVSToys - PBService::         
151 * CVSToys - mail notification::  
152 * Other mail notification ChangeSources::  
153 * PBChangeSource::              
154 * P4Source::                    
155 * BonsaiPoller::                
156 * SvnSource::                   
158 Build Process
160 * Build Steps::                 
161 * Interlocks::                  
162 * Build Factories::             
164 Build Steps
166 * Common Parameters::           
167 * Source Checkout::             
168 * ShellCommand::                
169 * Simple ShellCommand Subclasses::  
170 * Python BuildSteps::           
171 * Transferring Files::          
172 * Writing New BuildSteps::      
174 Source Checkout
176 * CVS::                         
177 * SVN::                         
178 * Darcs::                       
179 * Mercurial::                   
180 * Arch::                        
181 * Bazaar::                      
182 * P4::                          
184 Simple ShellCommand Subclasses
186 * Configure::                   
187 * Compile::                     
188 * Test::                        
189 * Build Properties::            
191 Python BuildSteps
193 * BuildEPYDoc::                 
194 * PyFlakes::                    
196 Writing New BuildSteps
198 * BuildStep LogFiles::          
199 * Adding LogObservers::         
200 * BuildStep URLs::              
202 Build Factories
204 * BuildStep Objects::           
205 * BuildFactory::                
206 * Process-Specific build factories::  
208 BuildStep Objects
210 * BuildFactory Attributes::     
211 * Quick builds::                
213 BuildFactory
215 * BuildFactory Attributes::     
216 * Quick builds::                
218 Process-Specific build factories
220 * GNUAutoconf::                 
221 * CPAN::                        
222 * Python distutils::            
223 * Python/Twisted/trial projects::  
225 Status Delivery
227 * HTML Waterfall::              
228 * IRC Bot::                     
229 * PBListener::                  
230 * Writing New Status Plugins::  
232 Command-line tool
234 * Administrator Tools::         
235 * Developer Tools::             
236 * Other Tools::                 
237 * .buildbot config directory::  
239 Developer Tools
241 * statuslog::                   
242 * statusgui::                   
243 * try::                         
245 Other Tools
247 * sendchange::                  
248 * debugclient::                 
250 @end detailmenu
251 @end menu
253 @node Introduction, Installation, Top, Top
254 @chapter Introduction
256 @cindex introduction
258 The BuildBot is a system to automate the compile/test cycle required by most
259 software projects to validate code changes. By automatically rebuilding and
260 testing the tree each time something has changed, build problems are
261 pinpointed quickly, before other developers are inconvenienced by the
262 failure. The guilty developer can be identified and harassed without human
263 intervention. By running the builds on a variety of platforms, developers
264 who do not have the facilities to test their changes everywhere before
265 checkin will at least know shortly afterwards whether they have broken the
266 build or not. Warning counts, lint checks, image size, compile time, and
267 other build parameters can be tracked over time, are more visible, and
268 are therefore easier to improve.
270 The overall goal is to reduce tree breakage and provide a platform to
271 run tests or code-quality checks that are too annoying or pedantic for
272 any human to waste their time with. Developers get immediate (and
273 potentially public) feedback about their changes, encouraging them to
274 be more careful about testing before checkin.
276 Features:
278 @itemize @bullet
279 @item
280 run builds on a variety of slave platforms
281 @item
282 arbitrary build process: handles projects using C, Python, whatever
283 @item
284 minimal host requirements: python and Twisted
285 @item
286 slaves can be behind a firewall if they can still do checkout
287 @item
288 status delivery through web page, email, IRC, other protocols
289 @item
290 track builds in progress, provide estimated completion time
291 @item
292 flexible configuration by subclassing generic build process classes
293 @item
294 debug tools to force a new build, submit fake Changes, query slave status
295 @item
296 released under the GPL
297 @end itemize
299 @menu
300 * History and Philosophy::      
301 * System Architecture::         
302 * Control Flow::                
303 @end menu
306 @node History and Philosophy, System Architecture, Introduction, Introduction
307 @section History and Philosophy
309 @cindex Philosophy of operation
311 The Buildbot was inspired by a similar project built for a development
312 team writing a cross-platform embedded system. The various components
313 of the project were supposed to compile and run on several flavors of
314 unix (linux, solaris, BSD), but individual developers had their own
315 preferences and tended to stick to a single platform. From time to
316 time, incompatibilities would sneak in (some unix platforms want to
317 use @code{string.h}, some prefer @code{strings.h}), and then the tree
318 would compile for some developers but not others. The buildbot was
319 written to automate the human process of walking into the office,
320 updating a tree, compiling (and discovering the breakage), finding the
321 developer at fault, and complaining to them about the problem they had
322 introduced. With multiple platforms it was difficult for developers to
323 do the right thing (compile their potential change on all platforms);
324 the buildbot offered a way to help.
326 Another problem was when programmers would change the behavior of a
327 library without warning its users, or change internal aspects that
328 other code was (unfortunately) depending upon. Adding unit tests to
329 the codebase helps here: if an application's unit tests pass despite
330 changes in the libraries it uses, you can have more confidence that
331 the library changes haven't broken anything. Many developers
332 complained that the unit tests were inconvenient or took too long to
333 run: having the buildbot run them reduces the developer's workload to
334 a minimum.
336 In general, having more visibility into the project is always good,
337 and automation makes it easier for developers to do the right thing.
338 When everyone can see the status of the project, developers are
339 encouraged to keep the tree in good working order. Unit tests that
340 aren't run on a regular basis tend to suffer from bitrot just like
341 code does: exercising them on a regular basis helps to keep them
342 functioning and useful.
344 The current version of the Buildbot is additionally targeted at
345 distributed free-software projects, where resources and platforms are
346 only available when provided by interested volunteers. The buildslaves
347 are designed to require an absolute minimum of configuration, reducing
348 the effort a potential volunteer needs to expend to be able to
349 contribute a new test environment to the project. The goal is for
350 anyone who wishes that a given project would run on their favorite
351 platform should be able to offer that project a buildslave, running on
352 that platform, where they can verify that their portability code
353 works, and keeps working.
355 @node System Architecture, Control Flow, History and Philosophy, Introduction
356 @comment  node-name,  next,  previous,  up
357 @section System Architecture
359 The Buildbot consists of a single @code{buildmaster} and one or more
360 @code{buildslaves}, connected in a star topology. The buildmaster
361 makes all decisions about what, when, and how to build. It sends
362 commands to be run on the build slaves, which simply execute the
363 commands and return the results. (certain steps involve more local
364 decision making, where the overhead of sending a lot of commands back
365 and forth would be inappropriate, but in general the buildmaster is
366 responsible for everything).
368 The buildmaster is usually fed @code{Changes} by some sort of version
369 control system (@pxref{Change Sources}), which may cause builds to be
370 run. As the builds are performed, various status messages are
371 produced, which are then sent to any registered Status Targets
372 (@pxref{Status Delivery}).
374 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
375 @image{images/overview,,,Overview Diagram,}
377 The buildmaster is configured and maintained by the ``buildmaster
378 admin'', who is generally the project team member responsible for
379 build process issues. Each buildslave is maintained by a ``buildslave
380 admin'', who do not need to be quite as involved. Generally slaves are
381 run by anyone who has an interest in seeing the project work well on
382 their favorite platform.
384 @menu
385 * BuildSlave Connections::      
386 * Buildmaster Architecture::    
387 * Status Delivery Architecture::  
388 @end menu
390 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
391 @subsection BuildSlave Connections
393 The buildslaves are typically run on a variety of separate machines,
394 at least one per platform of interest. These machines connect to the
395 buildmaster over a TCP connection to a publically-visible port. As a
396 result, the buildslaves can live behind a NAT box or similar
397 firewalls, as long as they can get to buildmaster. The TCP connections
398 are initiated by the buildslave and accepted by the buildmaster, but
399 commands and results travel both ways within this connection. The
400 buildmaster is always in charge, so all commands travel exclusively
401 from the buildmaster to the buildslave.
403 To perform builds, the buildslaves must typically obtain source code
404 from a CVS/SVN/etc repository. Therefore they must also be able to
405 reach the repository. The buildmaster provides instructions for
406 performing builds, but does not provide the source code itself.
408 @image{images/slaves,,,BuildSlave Connections,}
410 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
411 @subsection Buildmaster Architecture
413 The Buildmaster consists of several pieces:
415 @image{images/master,,,BuildMaster Architecture,}
417 @itemize @bullet
419 @item
420 Change Sources, which create a Change object each time something is
421 modified in the VC repository. Most ChangeSources listen for messages
422 from a hook script of some sort. Some sources actively poll the
423 repository on a regular basis. All Changes are fed to the Schedulers.
425 @item
426 Schedulers, which decide when builds should be performed. They collect
427 Changes into BuildRequests, which are then queued for delivery to
428 Builders until a buildslave is available.
430 @item
431 Builders, which control exactly @emph{how} each build is performed
432 (with a series of BuildSteps, configured in a BuildFactory). Each
433 Build is run on a single buildslave.
435 @item
436 Status plugins, which deliver information about the build results
437 through protocols like HTTP, mail, and IRC.
439 @end itemize
441 @image{images/slavebuilder,,,SlaveBuilders,}
443 Each Builder is configured with a list of BuildSlaves that it will use
444 for its builds. These buildslaves are expected to behave identically:
445 the only reason to use multiple BuildSlaves for a single Builder is to
446 provide a measure of load-balancing.
448 Within a single BuildSlave, each Builder creates its own SlaveBuilder
449 instance. These SlaveBuilders operate independently from each other.
450 Each gets its own base directory to work in. It is quite common to
451 have many Builders sharing the same buildslave. For example, there
452 might be two buildslaves: one for i386, and a second for PowerPC.
453 There may then be a pair of Builders that do a full compile/test run,
454 one for each architecture, and a lone Builder that creates snapshot
455 source tarballs if the full builders complete successfully. The full
456 builders would each run on a single buildslave, whereas the tarball
457 creation step might run on either buildslave (since the platform
458 doesn't matter when creating source tarballs). In this case, the
459 mapping would look like:
461 @example
462 Builder(full-i386)  ->  BuildSlaves(slave-i386)
463 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
464 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
465 @end example
467 and each BuildSlave would have two SlaveBuilders inside it, one for a
468 full builder, and a second for the source-tarball builder.
470 Once a SlaveBuilder is available, the Builder pulls one or more
471 BuildRequests off its incoming queue. (It may pull more than one if it
472 determines that it can merge the requests together; for example, there
473 may be multiple requests to build the current HEAD revision). These
474 requests are merged into a single Build instance, which includes the
475 SourceStamp that describes what exact version of the source code
476 should be used for the build. The Build is then assigned to a
477 SlaveBuilder and the build begins.
480 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
481 @subsection Status Delivery Architecture
483 The buildmaster maintains a central Status object, to which various
484 status plugins are connected. Through this Status object, a full
485 hierarchy of build status objects can be obtained.
487 @image{images/status,,,Status Delivery,}
489 The configuration file controls which status plugins are active. Each
490 status plugin gets a reference to the top-level Status object. From
491 there they can request information on each Builder, Build, Step, and
492 LogFile. This query-on-demand interface is used by the html.Waterfall
493 plugin to create the main status page each time a web browser hits the
494 main URL.
496 The status plugins can also subscribe to hear about new Builds as they
497 occur: this is used by the MailNotifier to create new email messages
498 for each recently-completed Build.
500 The Status object records the status of old builds on disk in the
501 buildmaster's base directory. This allows it to return information
502 about historical builds.
504 There are also status objects that correspond to Schedulers and
505 BuildSlaves. These allow status plugins to report information about
506 upcoming builds, and the online/offline status of each buildslave.
509 @node Control Flow,  , System Architecture, Introduction
510 @comment  node-name,  next,  previous,  up
511 @section Control Flow
513 A day in the life of the buildbot:
515 @itemize @bullet
517 @item
518 A developer commits some source code changes to the repository. A hook
519 script or commit trigger of some sort sends information about this
520 change to the buildmaster through one of its configured Change
521 Sources. This notification might arrive via email, or over a network
522 connection (either initiated by the buildmaster as it ``subscribes''
523 to changes, or by the commit trigger as it pushes Changes towards the
524 buildmaster). The Change contains information about who made the
525 change, what files were modified, which revision contains the change,
526 and any checkin comments.
528 @item
529 The buildmaster distributes this change to all of its configured
530 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
531 to be started, and the Change is added to a list of those that will go
532 into a new Build. When the timer expires, a Build is started on each
533 of a set of configured Builders, all compiling/testing the same source
534 code. Unless configured otherwise, all Builds run in parallel on the
535 various buildslaves.
537 @item
538 The Build consists of a series of Steps. Each Step causes some number
539 of commands to be invoked on the remote buildslave associated with
540 that Builder. The first step is almost always to perform a checkout of
541 the appropriate revision from the same VC system that produced the
542 Change. The rest generally perform a compile and run unit tests. As
543 each Step runs, the buildslave reports back command output and return
544 status to the buildmaster.
546 @item
547 As the Build runs, status messages like ``Build Started'', ``Step
548 Started'', ``Build Finished'', etc, are published to a collection of
549 Status Targets. One of these targets is usually the HTML ``Waterfall''
550 display, which shows a chronological list of events, and summarizes
551 the results of the most recent build at the top of each column.
552 Developers can periodically check this page to see how their changes
553 have fared. If they see red, they know that they've made a mistake and
554 need to fix it. If they see green, they know that they've done their
555 duty and don't need to worry about their change breaking anything.
557 @item
558 If a MailNotifier status target is active, the completion of a build
559 will cause email to be sent to any developers whose Changes were
560 incorporated into this Build. The MailNotifier can be configured to
561 only send mail upon failing builds, or for builds which have just
562 transitioned from passing to failing. Other status targets can provide
563 similar real-time notification via different communication channels,
564 like IRC.
566 @end itemize
569 @node Installation, Concepts, Introduction, Top
570 @chapter Installation
572 @menu
573 * Requirements::                
574 * Installing the code::         
575 * Creating a buildmaster::      
576 * Creating a buildslave::       
577 * Launching the daemons::       
578 * Logfiles::                    
579 * Shutdown::                    
580 * Maintenance::                 
581 * Troubleshooting::             
582 @end menu
584 @node Requirements, Installing the code, Installation, Installation
585 @section Requirements
587 At a bare minimum, you'll need the following (for both the buildmaster
588 and a buildslave):
590 @itemize @bullet
591 @item
592 Python: http://www.python.org
594 Buildbot requires python-2.2 or later, and is primarily developed
595 against python-2.3. The buildmaster uses generators, a feature which
596 is not available in python-2.1, and both master and slave require a
597 version of Twisted which only works with python-2.2 or later. Certain
598 features (like the inclusion of build logs in status emails) require
599 python-2.2.2 or later. The IRC ``force build'' command requires
600 python-2.3 (for the shlex.split function).
602 @item
603 Twisted: http://twistedmatrix.com
605 Both the buildmaster and the buildslaves require Twisted-1.3.0 or
606 later. It has been mainly developed against Twisted-2.0.1, but has
607 been tested against Twisted-2.1.0 (the most recent as of this
608 writing), and might even work on versions as old as Twisted-1.1.0, but
609 as always the most recent version is recommended.
611 Twisted-1.3.0 and earlier were released as a single monolithic
612 package. When you run Buildbot against Twisted-2.0.0 or later (which
613 are split into a number of smaller subpackages), you'll need at least
614 "Twisted" (the core package), and you'll also want TwistedMail,
615 TwistedWeb, and TwistedWords (for sending email, serving a web status
616 page, and delivering build status via IRC, respectively).
617 @end itemize
619 Certain other packages may be useful on the system running the
620 buildmaster:
622 @itemize @bullet
623 @item
624 CVSToys: http://purl.net/net/CVSToys
626 If your buildmaster uses FreshCVSSource to receive change notification
627 from a cvstoys daemon, it will require CVSToys be installed (tested
628 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
629 only use a mail-parsing change source, or the SVN notification
630 script), you will not need CVSToys.
632 @end itemize
634 And of course, your project's build process will impose additional
635 requirements on the buildslaves. These hosts must have all the tools
636 necessary to compile and test your project's source code.
639 @node Installing the code, Creating a buildmaster, Requirements, Installation
640 @section Installing the code
642 @cindex installation
644 The Buildbot is installed using the standard python @code{distutils}
645 module. After unpacking the tarball, the process is:
647 @example
648 python setup.py build
649 python setup.py install
650 @end example
652 where the install step may need to be done as root. This will put the
653 bulk of the code in somewhere like
654 /usr/lib/python2.3/site-packages/buildbot . It will also install the
655 @code{buildbot} command-line tool in /usr/bin/buildbot.
657 To test this, shift to a different directory (like /tmp), and run:
659 @example
660 buildbot --version
661 @end example
663 If it shows you the versions of Buildbot and Twisted, the install went
664 ok. If it says @code{no such command} or it gets an @code{ImportError}
665 when it tries to load the libaries, then something went wrong.
666 @code{pydoc buildbot} is another useful diagnostic tool.
668 Windows users will find these files in other places. You will need to
669 make sure that python can find the libraries, and will probably find
670 it convenient to have @code{buildbot} on your PATH.
672 If you wish, you can run the buildbot unit test suite like this:
674 @example
675 PYTHONPATH=. trial buildbot.test
676 @end example
678 This should run up to 192 tests, depending upon what VC tools you have
679 installed. On my desktop machine it takes about five minutes to
680 complete. Nothing should fail, a few might be skipped. If any of the
681 tests fail, you should stop and investigate the cause before
682 continuing the installation process, as it will probably be easier to
683 track down the bug early.
685 If you cannot or do not wish to install the buildbot into a site-wide
686 location like @file{/usr} or @file{/usr/local}, you can also install
687 it into the account's home directory. Do the install command like
688 this:
690 @example
691 python setup.py install --home=~
692 @end example
694 That will populate @file{~/lib/python} and create
695 @file{~/bin/buildbot}. Make sure this lib directory is on your
696 @code{PYTHONPATH}.
699 @node Creating a buildmaster, Creating a buildslave, Installing the code, Installation
700 @section Creating a buildmaster
702 As you learned earlier (@pxref{System Architecture}), the buildmaster
703 runs on a central host (usually one that is publically visible, so
704 everybody can check on the status of the project), and controls all
705 aspects of the buildbot system. Let us call this host
706 @code{buildbot.example.org}.
708 You may wish to create a separate user account for the buildmaster,
709 perhaps named @code{buildmaster}. This can help keep your personal
710 configuration distinct from that of the buildmaster and is useful if
711 you have to use a mail-based notification system (@pxref{Change
712 Sources}). However, the Buildbot will work just fine with your regular
713 user account.
715 You need to choose a directory for the buildmaster, called the
716 @code{basedir}. This directory will be owned by the buildmaster, which
717 will use configuration files therein, and create status files as it
718 runs. @file{~/Buildbot} is a likely value. If you run multiple
719 buildmasters in the same account, or if you run both masters and
720 slaves, you may want a more distinctive name like
721 @file{~/Buildbot/master/gnomovision} or
722 @file{~/Buildmasters/fooproject}. If you are using a separate user
723 account, this might just be @file{~buildmaster/masters/fooproject}.
725 Once you've picked a directory, use the @command{buildbot
726 create-master} command to create the directory and populate it with
727 startup files:
729 @example
730 buildbot create-master @var{basedir}
731 @end example
733 You will need to create a configuration file (@pxref{Configuration})
734 before starting the buildmaster. Most of the rest of this manual is
735 dedicated to explaining how to do this. A sample configuration file is
736 placed in the working directory, named @file{master.cfg.sample}, which
737 can be copied to @file{master.cfg} and edited to suit your purposes.
739 (Internal details: This command creates a file named
740 @file{buildbot.tac} that contains all the state necessary to create
741 the buildmaster. Twisted has a tool called @code{twistd} which can use
742 this .tac file to create and launch a buildmaster instance. twistd
743 takes care of logging and daemonization (running the program in the
744 background). @file{/usr/bin/buildbot} is a front end which runs twistd
745 for you.)
747 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
748 installed. This can be used as the basis for customized daemon startup,
749 @xref{Launching the daemons}.
752 @node Creating a buildslave, Launching the daemons, Creating a buildmaster, Installation
753 @section Creating a buildslave
755 Typically, you will be adding a buildslave to an existing buildmaster,
756 to provide additional architecture coverage. The buildbot
757 administrator will give you several pieces of information necessary to
758 connect to the buildmaster. You should also be somewhat familiar with
759 the project being tested, so you can troubleshoot build problems
760 locally.
762 The buildbot exists to make sure that the project's stated ``how to
763 build it'' process actually works. To this end, the buildslave should
764 run in an environment just like that of your regular developers.
765 Typically the project build process is documented somewhere
766 (@file{README}, @file{INSTALL}, etc), in a document that should
767 mention all library dependencies and contain a basic set of build
768 instructions. This document will be useful as you configure the host
769 and account in which the buildslave runs.
771 Here's a good checklist for setting up a buildslave:
773 @enumerate
774 @item
775 Set up the account
777 It is recommended (although not mandatory) to set up a separate user
778 account for the buildslave. This account is frequently named
779 @code{buildbot} or @code{buildslave}. This serves to isolate your
780 personal working environment from that of the slave's, and helps to
781 minimize the security threat posed by letting possibly-unknown
782 contributors run arbitrary code on your system. The account should
783 have a minimum of fancy init scripts.
785 @item
786 Install the buildbot code
788 Follow the instructions given earlier (@pxref{Installing the code}).
789 If you use a separate buildslave account, and you didn't install the
790 buildbot code to a shared location, then you will need to install it
791 with @code{--home=~} for each account that needs it.
793 @item
794 Set up the host
796 Make sure the host can actually reach the buildmaster. Usually the
797 buildmaster is running a status webserver on the same machine, so
798 simply point your web browser at it and see if you can get there.
799 Install whatever additional packages or libraries the project's
800 INSTALL document advises. (or not: if your buildslave is supposed to
801 make sure that building without optional libraries still works, then
802 don't install those libraries).
804 Again, these libraries don't necessarily have to be installed to a
805 site-wide shared location, but they must be available to your build
806 process. Accomplishing this is usually very specific to the build
807 process, so installing them to @file{/usr} or @file{/usr/local} is
808 usually the best approach.
810 @item
811 Test the build process
813 Follow the instructions in the INSTALL document, in the buildslave's
814 account. Perform a full CVS (or whatever) checkout, configure, make,
815 run tests, etc. Confirm that the build works without manual fussing.
816 If it doesn't work when you do it by hand, it will be unlikely to work
817 when the buildbot attempts to do it in an automated fashion.
819 @item
820 Choose a base directory
822 This should be somewhere in the buildslave's account, typically named
823 after the project which is being tested. The buildslave will not touch
824 any file outside of this directory. Something like @file{~/Buildbot}
825 or @file{~/Buildslaves/fooproject} is appropriate.
827 @item
828 Get the buildmaster host/port, botname, and password
830 When the buildbot admin configures the buildmaster to accept and use
831 your buildslave, they will provide you with the following pieces of
832 information:
834 @itemize @bullet
835 @item
836 your buildslave's name
837 @item
838 the password assigned to your buildslave
839 @item
840 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
841 @end itemize
843 @item
844 Create the buildslave
846 Now run the 'buildbot' command as follows:
848 @example
849 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
850 @end example
852 This will create the base directory and a collection of files inside,
853 including the @file{buildbot.tac} file that contains all the
854 information you passed to the @code{buildbot} command.
856 @item
857 Fill in the hostinfo files
859 When it first connects, the buildslave will send a few files up to the
860 buildmaster which describe the host that it is running on. These files
861 are presented on the web status display so that developers have more
862 information to reproduce any test failures that are witnessed by the
863 buildbot. There are sample files in the @file{info} subdirectory of
864 the buildbot's base directory. You should edit these to correctly
865 describe you and your host.
867 @file{BASEDIR/info/admin} should contain your name and email address.
868 This is the ``buildslave admin address'', and will be visible from the
869 build status page (so you may wish to munge it a bit if
870 address-harvesting spambots are a concern).
872 @file{BASEDIR/info/host} should be filled with a brief description of
873 the host: OS, version, memory size, CPU speed, versions of relevant
874 libraries installed, and finally the version of the buildbot code
875 which is running the buildslave.
877 If you run many buildslaves, you may want to create a single
878 @file{~buildslave/info} file and share it among all the buildslaves
879 with symlinks.
881 @end enumerate
883 @menu
884 * Buildslave Options::          
885 @end menu
887 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
888 @subsection Buildslave Options
890 There are a handful of options you might want to use when creating the
891 buildslave with the @command{buildbot create-slave <options> DIR <params>}
892 command. You can type @command{buildbot create-slave --help} for a summary.
893 To use these, just include them on the @command{buildbot create-slave}
894 command line, like this:
896 @example
897 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
898 @end example
900 @table @code
901 @item --usepty
902 This is a boolean flag that tells the buildslave whether to launch
903 child processes in a PTY (the default) or with regular pipes. The
904 advantage of using a PTY is that ``grandchild'' processes are more
905 likely to be cleaned up if the build is interrupted or times out
906 (since it enables the use of a ``process group'' in which all child
907 processes will be placed). The disadvantages: some forms of Unix have
908 problems with PTYs, some of your unit tests may behave differently
909 when run under a PTY (generally those which check to see if they are
910 being run interactively), and PTYs will merge the stdout and stderr
911 streams into a single output stream (which means the red-vs-black
912 coloring in the logfiles will be lost). If you encounter problems, you
913 can add @code{--usepty=0} to disable the use of PTYs. Note that
914 windows buildslaves never use PTYs.
916 @item --umask
917 This is a string (generally an octal representation of an integer)
918 which will cause the buildslave process' ``umask'' value to be set
919 shortly after initialization. The ``twistd'' daemonization utility
920 forces the umask to 077 at startup (which means that all files created
921 by the buildslave or its child processes will be unreadable by any
922 user other than the buildslave account). If you want build products to
923 be readable by other accounts, you can add @code{--umask=022} to tell
924 the buildslave to fix the umask after twistd clobbers it. If you want
925 build products to be @emph{writable} by other accounts too, use
926 @code{--umask=000}, but this is likely to be a security problem.
928 @item --keepalive
929 This is a number that indicates how frequently ``keepalive'' messages
930 should be sent from the buildslave to the buildmaster, expressed in
931 seconds. The default (600) causes a message to be sent to the
932 buildmaster at least once every 10 minutes. To set this to a lower
933 value, use e.g. @code{--keepalive=120}.
935 If the buildslave is behind a NAT box or stateful firewall, these
936 messages may help to keep the connection alive: some NAT boxes tend to
937 forget about a connection if it has not been used in a while. When
938 this happens, the buildmaster will think that the buildslave has
939 disappeared, and builds will time out. Meanwhile the buildslave will
940 not realize than anything is wrong.
942 @end table
945 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
946 @section Launching the daemons
948 Both the buildmaster and the buildslave run as daemon programs. To
949 launch them, pass the working directory to the @code{buildbot}
950 command:
952 @example
953 buildbot start @var{BASEDIR}
954 @end example
956 This command will start the daemon and then return, so normally it
957 will not produce any output. To verify that the programs are indeed
958 running, look for a pair of files named @file{twistd.log} and
959 @file{twistd.pid} that should be created in the working directory.
960 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
962 When the buildslave connects to the buildmaster, new directories will
963 start appearing in its base directory. The buildmaster tells the slave
964 to create a directory for each Builder which will be using that slave.
965 All build operations are performed within these directories: CVS
966 checkouts, compiles, and tests.
968 Once you get everything running, you will want to arrange for the
969 buildbot daemons to be started at boot time. One way is to use
970 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
971 @@reboot syntax is understood by Vixie cron, which is the flavor
972 usually provided with linux systems. Other unices may have a cron that
973 doesn't understand @@reboot}:
975 @example
976 @@reboot buildbot start @var{BASEDIR}
977 @end example
979 When you run @command{crontab} to set this up, remember to do it as
980 the buildmaster or buildslave account! If you add this to your crontab
981 when running as your regular account (or worse yet, root), then the
982 daemon will run as the wrong user, quite possibly as one with more
983 authority than you intended to provide.
985 It is important to remember that the environment provided to cron jobs
986 and init scripts can be quite different that your normal runtime.
987 There may be fewer environment variables specified, and the PATH may
988 be shorter than usual. It is a good idea to test out this method of
989 launching the buildslave by using a cron job with a time in the near
990 future, with the same command, and then check @file{twistd.log} to
991 make sure the slave actually started correctly. Common problems here
992 are for @file{/usr/local} or @file{~/bin} to not be on your
993 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
994 Sometimes @code{HOME} is messed up too.
996 To modify the way the daemons are started (perhaps you want to set
997 some environment variables first, or perform some cleanup each time),
998 you can create a file named @file{Makefile.buildbot} in the base
999 directory. When the @file{buildbot} front-end tool is told to
1000 @command{start} the daemon, and it sees this file (and
1001 @file{/usr/bin/make} exists), it will do @command{make -f
1002 Makefile.buildbot start} instead of its usual action (which involves
1003 running @command{twistd}). When the buildmaster or buildslave is
1004 installed, a @file{Makefile.sample} is created which implements the
1005 same behavior as the the @file{buildbot} tool uses, so if you want to
1006 customize the process, just copy @file{Makefile.sample} to
1007 @file{Makefile.buildbot} and edit it as necessary.
1009 @node Logfiles, Shutdown, Launching the daemons, Installation
1010 @section Logfiles
1012 @cindex logfiles
1014 While a buildbot daemon runs, it emits text to a logfile, named
1015 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1016 to watch the command output as it runs.
1018 The buildmaster will announce any errors with its configuration file
1019 in the logfile, so it is a good idea to look at the log at startup
1020 time to check for any problems. Most buildmaster activities will cause
1021 lines to be added to the log.
1023 @node Shutdown, Maintenance, Logfiles, Installation
1024 @section Shutdown
1026 To stop a buildmaster or buildslave manually, use:
1028 @example
1029 buildbot stop @var{BASEDIR}
1030 @end example
1032 This simply looks for the @file{twistd.pid} file and kills whatever
1033 process is identified within.
1035 At system shutdown, all processes are sent a @code{SIGKILL}. The
1036 buildmaster and buildslave will respond to this by shutting down
1037 normally.
1039 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1040 config file. The following shortcut is available:
1042 @example
1043 buildbot reconfig @var{BASEDIR}
1044 @end example
1046 When you update the Buildbot code to a new release, you will need to
1047 restart the buildmaster and/or buildslave before it can take advantage
1048 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1049 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1050 use the @code{restart} shortcut, which does both steps for you:
1052 @example
1053 buildbot restart @var{BASEDIR}
1054 @end example
1057 @node Maintenance, Troubleshooting, Shutdown, Installation
1058 @section Maintenance
1060 It is a good idea to check the buildmaster's status page every once in
1061 a while, to see if your buildslave is still online. Eventually the
1062 buildbot will probably be enhanced to send you email (via the
1063 @file{info/admin} email address) when the slave has been offline for
1064 more than a few hours.
1066 If you find you can no longer provide a buildslave to the project, please
1067 let the project admins know, so they can put out a call for a
1068 replacement.
1070 The Buildbot records status and logs output continually, each time a
1071 build is performed. The status tends to be small, but the build logs
1072 can become quite large. Each build and log are recorded in a separate
1073 file, arranged hierarchically under the buildmaster's base directory.
1074 To prevent these files from growing without bound, you should
1075 periodically delete old build logs. A simple cron job to delete
1076 anything older than, say, two weeks should do the job. The only trick
1077 is to leave the @file{buildbot.tac} and other support files alone, for
1078 which find's @code{-mindepth} argument helps skip everything in the
1079 top directory. You can use something like the following:
1081 @example
1082 @@weekly cd BASEDIR && find . -mindepth 2 -type f -mtime +14 -exec rm @{@} \;
1083 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1084 @end example
1086 @node Troubleshooting,  , Maintenance, Installation
1087 @section Troubleshooting
1089 Here are a few hints on diagnosing common problems.
1091 @menu
1092 * Starting the buildslave::     
1093 * Connecting to the buildmaster::  
1094 * Forcing Builds::              
1095 @end menu
1097 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1098 @subsection Starting the buildslave
1100 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1101 @file{/bin/bash}), and tilde expansion is not always performed in such
1102 commands. You may want to use explicit paths, because the @code{PATH}
1103 is usually quite short and doesn't include anything set by your
1104 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1105 you've installed buildbot (or other python libraries) to an unusual
1106 location, you may need to add a @code{PYTHONPATH} specification (note
1107 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1108 itself). Sometimes it is safer to fully-specify everything:
1110 @example
1111 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1112 @end example
1114 Take the time to get the @@reboot job set up. Otherwise, things will work
1115 fine for a while, but the first power outage or system reboot you have will
1116 stop the buildslave with nothing but the cries of sorrowful developers to
1117 remind you that it has gone away.
1119 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1120 @subsection Connecting to the buildmaster
1122 If the buildslave cannot connect to the buildmaster, the reason should
1123 be described in the @file{twistd.log} logfile. Some common problems
1124 are an incorrect master hostname or port number, or a mistyped bot
1125 name or password. If the buildslave loses the connection to the
1126 master, it is supposed to attempt to reconnect with an
1127 exponentially-increasing backoff. Each attempt (and the time of the
1128 next attempt) will be logged. If you get impatient, just manually stop
1129 and re-start the buildslave.
1131 When the buildmaster is restarted, all slaves will be disconnected,
1132 and will attempt to reconnect as usual. The reconnect time will depend
1133 upon how long the buildmaster is offline (i.e. how far up the
1134 exponential backoff curve the slaves have travelled). Again,
1135 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1136 speed up the process.
1138 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1139 @subsection Forcing Builds
1141 From the buildmaster's main status web page, you can force a build to
1142 be run on your build slave. Figure out which column is for a builder
1143 that runs on your slave, click on that builder's name, and the page
1144 that comes up will have a ``Force Build'' button. Fill in the form,
1145 hit the button, and a moment later you should see your slave's
1146 @file{twistd.log} filling with commands being run. Using @code{pstree}
1147 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1148 run by the buildslave. Note that the same web page should also show
1149 the @file{admin} and @file{host} information files that you configured
1150 earlier.
1152 @node Concepts, Configuration, Installation, Top
1153 @chapter Concepts
1155 This chapter defines some of the basic concepts that the Buildbot
1156 uses. You'll need to understand how the Buildbot sees the world to
1157 configure it properly.
1159 @menu
1160 * Version Control Systems::     
1161 * Schedulers::                  
1162 * BuildSet::                    
1163 * BuildRequest::                
1164 * Builder::                     
1165 * Users::                       
1166 @end menu
1168 @node Version Control Systems, Schedulers, Concepts, Concepts
1169 @section Version Control Systems
1171 @cindex Version Control
1173 These source trees come from a Version Control System of some kind.
1174 CVS and Subversion are two popular ones, but the Buildbot supports
1175 others. All VC systems have some notion of an upstream
1176 @code{repository} which acts as a server@footnote{except Darcs, but
1177 since the Buildbot never modifies its local source tree we can ignore
1178 the fact that Darcs uses a less centralized model}, from which clients
1179 can obtain source trees according to various parameters. The VC
1180 repository provides source trees of various projects, for different
1181 branches, and from various points in time. The first thing we have to
1182 do is to specify which source tree we want to get.
1184 @menu
1185 * Generalizing VC Systems::     
1186 * Source Tree Specifications::  
1187 * How Different VC Systems Specify Sources::  
1188 * Attributes of Changes::       
1189 @end menu
1191 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1192 @subsection Generalizing VC Systems
1194 For the purposes of the Buildbot, we will try to generalize all VC
1195 systems as having repositories that each provide sources for a variety
1196 of projects. Each project is defined as a directory tree with source
1197 files. The individual files may each have revisions, but we ignore
1198 that and treat the project as a whole as having a set of revisions.
1199 Each time someone commits a change to the project, a new revision
1200 becomes available. These revisions can be described by a tuple with
1201 two items: the first is a branch tag, and the second is some kind of
1202 timestamp or revision stamp. Complex projects may have multiple branch
1203 tags, but there is always a default branch. The timestamp may be an
1204 actual timestamp (such as the -D option to CVS), or it may be a
1205 monotonically-increasing transaction number (such as the change number
1206 used by SVN and P4, or the revision number used by Arch, or a labeled
1207 tag used in CVS)@footnote{many VC systems provide more complexity than
1208 this: in particular the local views that P4 and ClearCase can assemble
1209 out of various source directories are more complex than we're prepared
1210 to take advantage of here}. The SHA1 revision ID used by Monotone and
1211 Mercurial is also a kind of revision stamp, in that it specifies a
1212 unique copy of the source tree, as does a Darcs ``context'' file.
1214 When we aren't intending to make any changes to the sources we check out
1215 (at least not any that need to be committed back upstream), there are two
1216 basic ways to use a VC system:
1218 @itemize @bullet
1219 @item
1220 Retrieve a specific set of source revisions: some tag or key is used
1221 to index this set, which is fixed and cannot be changed by subsequent
1222 developers committing new changes to the tree. Releases are built from
1223 tagged revisions like this, so that they can be rebuilt again later
1224 (probably with controlled modifications).
1225 @item
1226 Retrieve the latest sources along a specific branch: some tag is used
1227 to indicate which branch is to be used, but within that constraint we want
1228 to get the latest revisions.
1229 @end itemize
1231 Build personnel or CM staff typically use the first approach: the
1232 build that results is (ideally) completely specified by the two
1233 parameters given to the VC system: repository and revision tag. This
1234 gives QA and end-users something concrete to point at when reporting
1235 bugs. Release engineers are also reportedly fond of shipping code that
1236 can be traced back to a concise revision tag of some sort.
1238 Developers are more likely to use the second approach: each morning
1239 the developer does an update to pull in the changes committed by the
1240 team over the last day. These builds are not easy to fully specify: it
1241 depends upon exactly when you did a checkout, and upon what local
1242 changes the developer has in their tree. Developers do not normally
1243 tag each build they produce, because there is usually significant
1244 overhead involved in creating these tags. Recreating the trees used by
1245 one of these builds can be a challenge. Some VC systems may provide
1246 implicit tags (like a revision number), while others may allow the use
1247 of timestamps to mean ``the state of the tree at time X'' as opposed
1248 to a tree-state that has been explicitly marked.
1250 The Buildbot is designed to help developers, so it usually works in
1251 terms of @emph{the latest} sources as opposed to specific tagged
1252 revisions. However, it would really prefer to build from reproducible
1253 source trees, so implicit revisions are used whenever possible.
1255 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1256 @subsection Source Tree Specifications
1258 So for the Buildbot's purposes we treat each VC system as a server
1259 which can take a list of specifications as input and produce a source
1260 tree as output. Some of these specifications are static: they are
1261 attributes of the builder and do not change over time. Others are more
1262 variable: each build will have a different value. The repository is
1263 changed over time by a sequence of Changes, each of which represents a
1264 single developer making changes to some set of files. These Changes
1265 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1266 violates this assumption of cumulative Changes, but in most situations
1267 the changes don't occur frequently enough for this to be a significant
1268 problem}.
1270 For normal builds, the Buildbot wants to get well-defined source trees
1271 that contain specific Changes, and exclude other Changes that may have
1272 occurred after the desired ones. We assume that the Changes arrive at
1273 the buildbot (through one of the mechanisms described in @pxref{Change
1274 Sources}) in the same order in which they are committed to the
1275 repository. The Buildbot waits for the tree to become ``stable''
1276 before initiating a build, for two reasons. The first is that
1277 developers frequently make multiple related commits in quick
1278 succession, even when the VC system provides ways to make atomic
1279 transactions involving multiple files at the same time. Running a
1280 build in the middle of these sets of changes would use an inconsistent
1281 set of source files, and is likely to fail (and is certain to be less
1282 useful than a build which uses the full set of changes). The
1283 tree-stable-timer is intended to avoid these useless builds that
1284 include some of the developer's changes but not all. The second reason
1285 is that some VC systems (i.e. CVS) do not provide repository-wide
1286 transaction numbers, so that timestamps are the only way to refer to
1287 a specific repository state. These timestamps may be somewhat
1288 ambiguous, due to processing and notification delays. By waiting until
1289 the tree has been stable for, say, 10 minutes, we can choose a
1290 timestamp from the middle of that period to use for our source
1291 checkout, and then be reasonably sure that any clock-skew errors will
1292 not cause the build to be performed on an inconsistent set of source
1293 files.
1295 The Schedulers always use the tree-stable-timer, with a timeout that
1296 is configured to reflect a reasonable tradeoff between build latency
1297 and change frequency. When the VC system provides coherent
1298 repository-wide revision markers (such as Subversion's revision
1299 numbers, or in fact anything other than CVS's timestamps), the
1300 resulting Build is simply performed against a source tree defined by
1301 that revision marker. When the VC system does not provide this, a
1302 timestamp from the middle of the tree-stable period is used to
1303 generate the source tree@footnote{this @code{checkoutDelay} defaults
1304 to half the tree-stable timer, but it can be overridden with an
1305 argument to the Source Step}.
1307 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1308 @subsection How Different VC Systems Specify Sources
1310 For CVS, the static specifications are @code{repository} and
1311 @code{module}. In addition to those, each build uses a timestamp (or
1312 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1313 (which defaults to HEAD). These parameters collectively specify a set
1314 of sources from which a build may be performed.
1316 @uref{http://subversion.tigris.org, Subversion} combines the
1317 repository, module, and branch into a single @code{Subversion URL}
1318 parameter. Within that scope, source checkouts can be specified by a
1319 numeric @code{revision number} (a repository-wide
1320 monotonically-increasing marker, such that each transaction that
1321 changes the repository is indexed by a different revision number), or
1322 a revision timestamp. When branches are used, the repository and
1323 module form a static @code{baseURL}, while each build has a
1324 @code{revision number} and a @code{branch} (which defaults to a
1325 statically-specified @code{defaultBranch}). The @code{baseURL} and
1326 @code{branch} are simply concatenated together to derive the
1327 @code{svnurl} to use for the checkout.
1329 @uref{http://www.perforce.com/, Perforce} is similar. The server
1330 is specified through a @code{P4PORT} parameter. Module and branch
1331 are specified in a single depot path, and revisions are
1332 depot-wide. When branches are used, the @code{p4base} and
1333 @code{defaultBranch} are concatenated together to produce the depot
1334 path.
1336 @uref{http://wiki.gnuarch.org/, Arch} and
1337 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1338 URL, as well as a @code{version} which is kind of like a branch name.
1339 Arch uses the word @code{archive} to represent the repository. Arch
1340 lets you push changes from one archive to another, removing the strict
1341 centralization required by CVS and SVN. It retains the distinction
1342 between repository and working directory that most other VC systems
1343 use. For complex multi-module directory structures, Arch has a
1344 built-in @code{build config} layer with which the checkout process has
1345 two steps. First, an initial bootstrap checkout is performed to
1346 retrieve a set of build-config files. Second, one of these files is
1347 used to figure out which archives/modules should be used to populate
1348 subdirectories of the initial checkout.
1350 Builders which use Arch and Bazaar therefore have a static archive
1351 @code{url}, and a default ``branch'' (which is a string that specifies
1352 a complete category--branch--version triple). Each build can have its
1353 own branch (the category--branch--version string) to override the
1354 default, as well as a revision number (which is turned into a
1355 --patch-NN suffix when performing the checkout).
1357 @uref{http://abridgegame.org/darcs/, Darcs} doesn't really have the
1358 notion of a single master repository. Nor does it really have
1359 branches. In Darcs, each working directory is also a repository, and
1360 there are operations to push and pull patches from one of these
1361 @code{repositories} to another. For the Buildbot's purposes, all you
1362 need to do is specify the URL of a repository that you want to build
1363 from. The build slave will then pull the latest patches from that
1364 repository and build them. Multiple branches are implemented by using
1365 multiple repositories (possibly living on the same server).
1367 Builders which use Darcs therefore have a static @code{repourl} which
1368 specifies the location of the repository. If branches are being used,
1369 the source Step is instead configured with a @code{baseURL} and a
1370 @code{defaultBranch}, and the two strings are simply concatenated
1371 together to obtain the repository's URL. Each build then has a
1372 specific branch which replaces @code{defaultBranch}, or just uses the
1373 default one. Instead of a revision number, each build can have a
1374 ``context'', which is a string that records all the patches that are
1375 present in a given tree (this is the output of @command{darcs changes
1376 --context}, and is considerably less concise than, e.g. Subversion's
1377 revision number, but the patch-reordering flexibility of Darcs makes
1378 it impossible to provide a shorter useful specification).
1380 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1381 each branch is stored in a separate repository. The @code{repourl},
1382 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1383 same way as with Darcs. The ``revision'', however, is the hash
1384 identifier returned by @command{hg identify}.
1387 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1388 @subsection Attributes of Changes
1390 @heading Who
1392 Each Change has a @code{who} attribute, which specifies which
1393 developer is responsible for the change. This is a string which comes
1394 from a namespace controlled by the VC repository. Frequently this
1395 means it is a username on the host which runs the repository, but not
1396 all VC systems require this (Arch, for example, uses a fully-qualified
1397 @code{Arch ID}, which looks like an email address, as does Darcs).
1398 Each StatusNotifier will map the @code{who} attribute into something
1399 appropriate for their particular means of communication: an email
1400 address, an IRC handle, etc.
1402 @heading Files
1404 It also has a list of @code{files}, which are just the tree-relative
1405 filenames of any files that were added, deleted, or modified for this
1406 Change. These filenames are used by the @code{isFileImportant}
1407 function (in the Scheduler) to decide whether it is worth triggering a
1408 new build or not, e.g. the function could use
1409 @code{filename.endswith(".c")} to only run a build if a C file were
1410 checked in. Certain BuildSteps can also use the list of changed files
1411 to run a more targeted series of tests, e.g. the
1412 @code{python_twisted.Trial} step can run just the unit tests that
1413 provide coverage for the modified .py files instead of running the
1414 full test suite.
1416 @heading Comments
1418 The Change also has a @code{comments} attribute, which is a string
1419 containing any checkin comments.
1421 @heading Revision
1423 Each Change can have a @code{revision} attribute, which describes how
1424 to get a tree with a specific state: a tree which includes this Change
1425 (and all that came before it) but none that come after it. If this
1426 information is unavailable, the @code{.revision} attribute will be
1427 @code{None}. These revisions are provided by the ChangeSource, and
1428 consumed by the @code{computeSourceRevision} method in the appropriate
1429 @code{step.Source} class.
1431 @table @samp
1432 @item CVS
1433 @code{revision} is an int, seconds since the epoch
1434 @item SVN
1435 @code{revision} is an int, a transation number (r%d)
1436 @item Darcs
1437 @code{revision} is a large string, the output of @code{darcs changes --context}
1438 @item Mercurial
1439 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1440 @item Arch/Bazaar
1441 @code{revision} is the full revision ID (ending in --patch-%d)
1442 @item P4
1443 @code{revision} is an int, the transaction number
1444 @end table
1446 @heading Branches
1448 The Change might also have a @code{branch} attribute. This indicates
1449 that all of the Change's files are in the same named branch. The
1450 Schedulers get to decide whether the branch should be built or not.
1452 For VC systems like CVS, Arch, and Monotone, the @code{branch} name is
1453 unrelated to the filename. (that is, the branch name and the filename
1454 inhabit unrelated namespaces). For SVN, branches are expressed as
1455 subdirectories of the repository, so the file's ``svnurl'' is a
1456 combination of some base URL, the branch name, and the filename within
1457 the branch. (In a sense, the branch name and the filename inhabit the
1458 same namespace). Darcs branches are subdirectories of a base URL just
1459 like SVN. Mercurial branches are the same as Darcs.
1461 @table @samp
1462 @item CVS
1463 branch='warner-newfeature', files=['src/foo.c']
1464 @item SVN
1465 branch='branches/warner-newfeature', files=['src/foo.c']
1466 @item Darcs
1467 branch='warner-newfeature', files=['src/foo.c']
1468 @item Mercurial
1469 branch='warner-newfeature', files=['src/foo.c']
1470 @item Arch/Bazaar
1471 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1472 @end table
1474 @heading Links
1476 @c TODO: who is using 'links'? how is it being used?
1478 Finally, the Change might have a @code{links} list, which is intended
1479 to provide a list of URLs to a @emph{viewcvs}-style web page that
1480 provides more detail for this Change, perhaps including the full file
1481 diffs.
1484 @node Schedulers, BuildSet, Version Control Systems, Concepts
1485 @section Schedulers
1487 @cindex Scheduler
1489 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1490 gets a copy of every incoming Change. The Schedulers are responsible
1491 for deciding when Builds should be run. Some Buildbot installations
1492 might have a single Scheduler, while others may have several, each for
1493 a different purpose.
1495 For example, a ``quick'' scheduler might exist to give immediate
1496 feedback to developers, hoping to catch obvious problems in the code
1497 that can be detected quickly. These typically do not run the full test
1498 suite, nor do they run on a wide variety of platforms. They also
1499 usually do a VC update rather than performing a brand-new checkout
1500 each time. You could have a ``quick'' scheduler which used a 30 second
1501 timeout, and feeds a single ``quick'' Builder that uses a VC
1502 @code{mode='update'} setting.
1504 A separate ``full'' scheduler would run more comprehensive tests a
1505 little while later, to catch more subtle problems. This scheduler
1506 would have a longer tree-stable-timer, maybe 30 minutes, and would
1507 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1508 @code{'clobber'}, or @code{'export'}).
1510 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1511 made by the Scheduler. Dependencies are also implemented here.
1512 Periodic builds (those which are run every N seconds rather than after
1513 new Changes arrive) are triggered by a special @code{Periodic}
1514 Scheduler subclass. The default Scheduler class can also be told to
1515 watch for specific branches, ignoring Changes on other branches. This
1516 may be useful if you have a trunk and a few release branches which
1517 should be tracked, but when you don't want to have the Buildbot pay
1518 attention to several dozen private user branches.
1520 Some Schedulers may trigger builds for other reasons, other than
1521 recent Changes. For example, a Scheduler subclass could connect to a
1522 remote buildmaster and watch for builds of a library to succeed before
1523 triggering a local build that uses that library.
1525 Each Scheduler creates and submits @code{BuildSet} objects to the
1526 @code{BuildMaster}, which is then responsible for making sure the
1527 individual @code{BuildRequests} are delivered to the target
1528 @code{Builders}.
1530 @code{Scheduler} instances are activated by placing them in the
1531 @code{c['schedulers']} list in the buildmaster config file. Each
1532 Scheduler has a unique name.
1535 @node BuildSet, BuildRequest, Schedulers, Concepts
1536 @section BuildSet
1538 @cindex BuildSet
1540 A @code{BuildSet} is the name given to a set of Builds that all
1541 compile/test the same version of the tree on multiple Builders. In
1542 general, all these component Builds will perform the same sequence of
1543 Steps, using the same source code, but on different platforms or
1544 against a different set of libraries.
1546 The @code{BuildSet} is tracked as a single unit, which fails if any of
1547 the component Builds have failed, and therefore can succeed only if
1548 @emph{all} of the component Builds have succeeded. There are two kinds
1549 of status notification messages that can be emitted for a BuildSet:
1550 the @code{firstFailure} type (which fires as soon as we know the
1551 BuildSet will fail), and the @code{Finished} type (which fires once
1552 the BuildSet has completely finished, regardless of whether the
1553 overall set passed or failed).
1555 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1556 (branch, revision, changes, patch), some of which may be None, and a
1557 list of Builders on which it is to be run. They are then given to the
1558 BuildMaster, which is responsible for creating a separate
1559 @code{BuildRequest} for each Builder.
1561 There are a couple of different likely values for the
1562 @code{SourceStamp}:
1564 @table @code
1565 @item (revision=None, changes=[CHANGES], patch=None)
1566 This is a @code{SourceStamp} used when a series of Changes have
1567 triggered a build. The VC step will attempt to check out a tree that
1568 contains CHANGES (and any changes that occurred before CHANGES, but
1569 not any that occurred after them).
1571 @item (revision=None, changes=None, patch=None)
1572 This builds the most recent code on the default branch. This is the
1573 sort of @code{SourceStamp} that would be used on a Build that was
1574 triggered by a user request, or a Periodic scheduler. It is also
1575 possible to configure the VC Source Step to always check out the
1576 latest sources rather than paying attention to the Changes in the
1577 SourceStamp, which will result in same behavior as this.
1579 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1580 This builds the most recent code on the given BRANCH. Again, this is
1581 generally triggered by a user request or Periodic build.
1583 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1584 This checks out the tree at the given revision REV, then applies a
1585 patch (using @code{diff -pLEVEL <DIFF}). The @ref{try} feature uses
1586 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1587 step is bypassed.
1589 @end table
1591 The buildmaster is responsible for turning the @code{BuildSet} into a
1592 set of @code{BuildRequest} objects and queueing them on the
1593 appropriate Builders.
1596 @node BuildRequest, Builder, BuildSet, Concepts
1597 @section BuildRequest
1599 @cindex BuildRequest
1601 A @code{BuildRequest} is a request to build a specific set of sources
1602 on a single specific Builder. Each Builder runs the
1603 @code{BuildRequest} as soon as it can (i.e. when an associated
1604 buildslave becomes free).
1606 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1607 The actual process of running the build (the series of Steps that will
1608 be executed) is implemented by the @code{Build} object. In this future
1609 this might be changed, to have the @code{Build} define @emph{what}
1610 gets built, and a separate @code{BuildProcess} (provided by the
1611 Builder) to define @emph{how} it gets built.
1613 The @code{BuildRequest} may be mergeable with other compatible
1614 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1615 will generally be mergeable. Builds that are triggered by user
1616 requests are generally not, unless they are multiple requests to build
1617 the @emph{latest sources} of the same branch.
1619 @node Builder, Users, BuildRequest, Concepts
1620 @section Builder
1622 @cindex Builder
1624 The @code{Builder} is a long-lived object which controls all Builds of
1625 a given type. Each one is created when the config file is first
1626 parsed, and lives forever (or rather until it is removed from the
1627 config file). It mediates the connections to the buildslaves that do
1628 all the work, and is responsible for creating the @code{Build} objects
1629 that decide @emph{how} a build is performed (i.e., which steps are
1630 executed in what order).
1632 Each @code{Builder} gets a unique name, and the path name of a
1633 directory where it gets to do all its work (there is a
1634 buildmaster-side directory for keeping status information, as well as
1635 a buildslave-side directory where the actual checkout/compile/test
1636 commands are executed). It also gets a @code{BuildFactory}, which is
1637 responsible for creating new @code{Build} instances: because the
1638 @code{Build} instance is what actually performs each build, choosing
1639 the @code{BuildFactory} is the way to specify what happens each time a
1640 build is done.
1642 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1643 A @code{Builder} which is used to perform OS-X builds (as opposed to
1644 Linux or Solaris builds) should naturally be associated with an
1645 OS-X-based buildslave.
1648 @node Users,  , Builder, Concepts
1649 @section Users
1651 @cindex Users
1653 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1654 the world consists of a set of developers, each of whom can be
1655 described by a couple of simple attributes. These developers make
1656 changes to the source code, causing builds which may succeed or fail.
1658 Each developer is primarily known through the source control system. Each
1659 Change object that arrives is tagged with a @code{who} field that
1660 typically gives the account name (on the repository machine) of the user
1661 responsible for that change. This string is the primary key by which the
1662 User is known, and is displayed on the HTML status pages and in each Build's
1663 ``blamelist''.
1665 To do more with the User than just refer to them, this username needs to
1666 be mapped into an address of some sort. The responsibility for this mapping
1667 is left up to the status module which needs the address. The core code knows
1668 nothing about email addresses or IRC nicknames, just user names.
1670 @menu
1671 * Doing Things With Users::     
1672 * Email Addresses::             
1673 * IRC Nicknames::               
1674 * Live Status Clients::         
1675 @end menu
1677 @node Doing Things With Users, Email Addresses, Users, Users
1678 @subsection Doing Things With Users
1680 Each Change has a single User who is responsible for that Change. Most
1681 Builds have a set of Changes: the Build represents the first time these
1682 Changes have been built and tested by the Buildbot. The build has a
1683 ``blamelist'' that consists of a simple union of the Users responsible
1684 for all the Build's Changes.
1686 The Build provides (through the IBuildStatus interface) a list of Users
1687 who are ``involved'' in the build. For now this is equal to the
1688 blamelist, but in the future it will be expanded to include a ``build
1689 sheriff'' (a person who is ``on duty'' at that time and responsible for
1690 watching over all builds that occur during their shift), as well as
1691 per-module owners who simply want to keep watch over their domain (chosen by
1692 subdirectory or a regexp matched against the filenames pulled out of the
1693 Changes). The Involved Users are those who probably have an interest in the
1694 results of any given build.
1696 In the future, Buildbot will acquire the concept of ``Problems'',
1697 which last longer than builds and have beginnings and ends. For example, a
1698 test case which passed in one build and then failed in the next is a
1699 Problem. The Problem lasts until the test case starts passing again, at
1700 which point the Problem is said to be ``resolved''.
1702 If there appears to be a code change that went into the tree at the
1703 same time as the test started failing, that Change is marked as being
1704 resposible for the Problem, and the user who made the change is added
1705 to the Problem's ``Guilty'' list. In addition to this user, there may
1706 be others who share responsibility for the Problem (module owners,
1707 sponsoring developers). In addition to the Responsible Users, there
1708 may be a set of Interested Users, who take an interest in the fate of
1709 the Problem.
1711 Problems therefore have sets of Users who may want to be kept aware of
1712 the condition of the problem as it changes over time. If configured, the
1713 Buildbot can pester everyone on the Responsible list with increasing
1714 harshness until the problem is resolved, with the most harshness reserved
1715 for the Guilty parties themselves. The Interested Users may merely be told
1716 when the problem starts and stops, as they are not actually responsible for
1717 fixing anything.
1719 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1720 @subsection Email Addresses
1722 The @code{buildbot.status.mail.MailNotifier} class provides a
1723 status target which can send email about the results of each build. It
1724 accepts a static list of email addresses to which each message should be
1725 delivered, but it can also be configured to send mail to the Build's
1726 Interested Users. To do this, it needs a way to convert User names into
1727 email addresses.
1729 For many VC systems, the User Name is actually an account name on the
1730 system which hosts the repository. As such, turning the name into an
1731 email address is a simple matter of appending
1732 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1733 (for example the preferred email address may be at ``project.org''
1734 despite the repository host being named ``cvs.project.org''), and some
1735 VC systems have full separation between the concept of a user and that
1736 of an account on the repository host (like Perforce). Some systems
1737 (like Arch) put a full contact email address in every change.
1739 To convert these names to addresses, the MailNotifier uses an EmailLookup
1740 object. This provides a .getAddress method which accepts a name and
1741 (eventually) returns an address. The default @code{MailNotifier}
1742 module provides an EmailLookup which simply appends a static string,
1743 configurable when the notifier is created. To create more complex behaviors
1744 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1745 determine a preferred address for the developer), provide a different object
1746 as the @code{lookup} argument.
1748 In the future, when the Problem mechanism has been set up, the Buildbot
1749 will need to send mail to arbitrary Users. It will do this by locating a
1750 MailNotifier-like object among all the buildmaster's status targets, and
1751 asking it to send messages to various Users. This means the User-to-address
1752 mapping only has to be set up once, in your MailNotifier, and every email
1753 message the buildbot emits will take advantage of it.
1755 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1756 @subsection IRC Nicknames
1758 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1759 provides a status target which can announce the results of each build. It
1760 also provides an interactive interface by responding to online queries
1761 posted in the channel or sent as private messages.
1763 In the future, the buildbot can be configured map User names to IRC
1764 nicknames, to watch for the recent presence of these nicknames, and to
1765 deliver build status messages to the interested parties. Like
1766 @code{MailNotifier} does for email addresses, the @code{IRC} object
1767 will have an @code{IRCLookup} which is responsible for nicknames. The
1768 mapping can be set up statically, or it can be updated by online users
1769 themselves (by claiming a username with some kind of ``buildbot: i am
1770 user warner'' commands).
1772 Once the mapping is established, the rest of the buildbot can ask the
1773 @code{IRC} object to send messages to various users. It can report on
1774 the likelihood that the user saw the given message (based upon how long the
1775 user has been inactive on the channel), which might prompt the Problem
1776 Hassler logic to send them an email message instead.
1778 @node Live Status Clients,  , IRC Nicknames, Users
1779 @subsection Live Status Clients
1781 The Buildbot also offers a PB-based status client interface which can
1782 display real-time build status in a GUI panel on the developer's desktop.
1783 This interface is normally anonymous, but it could be configured to let the
1784 buildmaster know @emph{which} developer is using the status client. The
1785 status client could then be used as a message-delivery service, providing an
1786 alternative way to deliver low-latency high-interruption messages to the
1787 developer (like ``hey, you broke the build'').
1790 @node Configuration, Getting Source Code Changes, Concepts, Top
1791 @chapter Configuration
1793 @cindex Configuration
1795 The buildbot's behavior is defined by the ``config file'', which
1796 normally lives in the @file{master.cfg} file in the buildmaster's base
1797 directory (but this can be changed with an option to the
1798 @code{buildbot create-master} command). This file completely specifies
1799 which Builders are to be run, which slaves they should use, how
1800 Changes should be tracked, and where the status information is to be
1801 sent. The buildmaster's @file{buildbot.tac} file names the base
1802 directory; everything else comes from the config file.
1804 A sample config file was installed for you when you created the
1805 buildmaster, but you will need to edit it before your buildbot will do
1806 anything useful.
1808 This chapter gives an overview of the format of this file and the
1809 various sections in it. You will need to read the later chapters to
1810 understand how to fill in each section properly.
1812 @menu
1813 * Config File Format::          
1814 * Loading the Config File::     
1815 * Defining the Project::        
1816 * Listing Change Sources and Schedulers::  
1817 * Setting the slaveport::       
1818 * Buildslave Specifiers::       
1819 * Defining Builders::           
1820 * Defining Status Targets::     
1821 * Debug options::               
1822 @end menu
1824 @node Config File Format, Loading the Config File, Configuration, Configuration
1825 @section Config File Format
1827 The config file is, fundamentally, just a piece of Python code which
1828 defines a dictionary named @code{BuildmasterConfig}, with a number of
1829 keys that are treated specially. You don't need to know Python to do
1830 basic configuration, though, you can just copy the syntax of the
1831 sample file. If you @emph{are} comfortable writing Python code,
1832 however, you can use all the power of a full programming language to
1833 achieve more complicated configurations.
1835 The @code{BuildmasterConfig} name is the only one which matters: all
1836 other names defined during the execution of the file are discarded.
1837 When parsing the config file, the Buildmaster generally compares the
1838 old configuration with the new one and performs the minimum set of
1839 actions necessary to bring the buildbot up to date: Builders which are
1840 not changed are left untouched, and Builders which are modified get to
1841 keep their old event history.
1843 Basic Python syntax: comments start with a hash character (``#''),
1844 tuples are defined with @code{(parenthesis, pairs)}, arrays are
1845 defined with @code{[square, brackets]}, tuples and arrays are mostly
1846 interchangeable. Dictionaries (data structures which map ``keys'' to
1847 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
1848 'key2': 'value2'@} }. Function calls (and object instantiation) can use
1849 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
1851 The config file starts with a series of @code{import} statements,
1852 which make various kinds of Steps and Status targets available for
1853 later use. The main @code{BuildmasterConfig} dictionary is created,
1854 then it is populated with a variety of keys. These keys are broken
1855 roughly into the following sections, each of which is documented in
1856 the rest of this chapter:
1858 @itemize @bullet
1859 @item
1860 Project Definitions
1861 @item
1862 Change Sources / Schedulers
1863 @item
1864 Slaveport
1865 @item
1866 Buildslave Configuration
1867 @item
1868 Builders / Interlocks
1869 @item
1870 Status Targets
1871 @item
1872 Debug options
1873 @end itemize
1875 The config file can use a few names which are placed into its namespace:
1877 @table @code
1878 @item basedir
1879 the base directory for the buildmaster. This string has not been
1880 expanded, so it may start with a tilde. It needs to be expanded before
1881 use. The config file is located in
1882 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
1884 @end table
1887 @node Loading the Config File, Defining the Project, Config File Format, Configuration
1888 @section Loading the Config File
1890 The config file is only read at specific points in time. It is first
1891 read when the buildmaster is launched. Once it is running, there are
1892 various ways to ask it to reload the config file. If you are on the
1893 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
1894 it: the @command{buildbot} tool has a shortcut for this:
1896 @example
1897 buildbot reconfig @var{BASEDIR}
1898 @end example
1900 This command will show you all of the lines from @file{twistd.log}
1901 that relate to the reconfiguration. If there are any problems during
1902 the config-file reload, they will be displayed in these lines.
1904 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
1905 ``Reload .cfg'' button which will also trigger a reload. In the
1906 future, there will be other ways to accomplish this step (probably a
1907 password-protected button on the web page, as well as a privileged IRC
1908 command).
1910 When reloading the config file, the buildmaster will endeavor to
1911 change as little as possible about the running system. For example,
1912 although old status targets may be shut down and new ones started up,
1913 any status targets that were not changed since the last time the
1914 config file was read will be left running and untouched. Likewise any
1915 Builders which have not been changed will be left running. If a
1916 Builder is modified (say, the build process is changed) while a Build
1917 is currently running, that Build will keep running with the old
1918 process until it completes. Any previously queued Builds (or Builds
1919 which get queued after the reconfig) will use the new process.
1921 @node Defining the Project, Listing Change Sources and Schedulers, Loading the Config File, Configuration
1922 @section Defining the Project
1924 There are a couple of basic settings that you use to tell the buildbot
1925 what project it is working on. This information is used by status
1926 reporters to let users find out more about the codebase being
1927 exercised by this particular Buildbot installation.
1929 @example
1930 c['projectName'] = "Buildbot"
1931 c['projectURL'] = "http://buildbot.sourceforge.net/"
1932 c['buildbotURL'] = "http://localhost:8010/"
1933 @end example
1935 @bcindex c['projectName']
1936 @code{projectName} is a short string will be used to describe the
1937 project that this buildbot is working on. For example, it is used as
1938 the title of the waterfall HTML page. 
1940 @bcindex c['projectURL']
1941 @code{projectURL} is a string that gives a URL for the project as a
1942 whole. HTML status displays will show @code{projectName} as a link to
1943 @code{projectURL}, to provide a link from buildbot HTML pages to your
1944 project's home page.
1946 @bcindex c['buildbotURL']
1947 The @code{buildbotURL} string should point to the location where the
1948 buildbot's internal web server (usually the @code{html.Waterfall}
1949 page) is visible. This typically uses the port number set when you
1950 create the @code{Waterfall} object: the buildbot needs your help to
1951 figure out a suitable externally-visible host name.
1953 When status notices are sent to users (either by email or over IRC),
1954 @code{buildbotURL} will be used to create a URL to the specific build
1955 or problem that they are being notified about. It will also be made
1956 available to queriers (over IRC) who want to find out where to get
1957 more information about this buildbot.
1960 @node Listing Change Sources and Schedulers, Setting the slaveport, Defining the Project, Configuration
1961 @section Listing Change Sources and Schedulers
1963 @bcindex c['sources']
1964 The @code{c['sources']} key is a list of ChangeSource
1965 instances@footnote{To be precise, it is a list of objects which all
1966 implement the @code{buildbot.interfaces.IChangeSource} Interface}.
1967 This defines how the buildmaster learns about source code changes.
1968 More information about what goes here is available in @xref{Getting
1969 Source Code Changes}.
1971 @example
1972 import buildbot.changes.pb
1973 c['sources'] = [buildbot.changes.pb.PBChangeSource()]
1974 @end example
1976 @bcindex c['schedulers']
1977 @code{c['schedulers']} is a list of Scheduler instances, each of which
1978 causes builds to be started on a particular set of Builders. The two
1979 basic Scheduler classes you are likely to start with are
1980 @code{Scheduler} and @code{Periodic}, but you can write a customized
1981 subclass to implement more complicated build scheduling.
1983 The docstring for @code{buildbot.scheduler.Scheduler} is the best
1984 place to see all the options that can be used. Type @code{pydoc
1985 buildbot.scheduler.Scheduler} to see it, or look in
1986 @file{buildbot/scheduler.py} directly.
1988 The basic Scheduler takes four arguments:
1990 @table @code
1991 @item name
1992 Each Scheduler must have a unique name. This is only used in status
1993 displays.
1995 @item branch
1996 This Scheduler will pay attention to a single branch, ignoring Changes
1997 that occur on other branches. Setting @code{branch} equal to the
1998 special value of @code{None} means it should only pay attention to the
1999 default branch. Note that @code{None} is a keyword, not a string, so
2000 you want to use @code{None} and not @code{"None"}.
2002 @item treeStableTimer
2003 The Scheduler will wait for this many seconds before starting the
2004 build. If new changes are made during this interval, the timer will be
2005 restarted, so really the build will be started after a change and then
2006 after this many seconds of inactivity.
2008 @item builderNames
2009 When the tree-stable-timer finally expires, builds will be started on
2010 these Builders. Each Builder gets a unique name: these strings must
2011 match.
2013 @end table
2015 @example
2016 from buildbot import scheduler
2017 quick = scheduler.Scheduler("quick", None, 60,
2018                             ["quick-linux", "quick-netbsd"])
2019 full = scheduler.Scheduler("full", None, 5*60,
2020                            ["full-linux", "full-netbsd", "full-OSX"])
2021 nightly = scheduler.Periodic("nightly", ["full-solaris"], 24*60*60)
2022 c['schedulers'] = [quick, full, nightly]
2023 @end example
2025 In this example, the two ``quick'' builds are triggered 60 seconds
2026 after the tree has been changed. The ``full'' builds do not run quite
2027 so quickly (they wait 5 minutes), so hopefully if the quick builds
2028 fail due to a missing file or really simple typo, the developer can
2029 discover and fix the problem before the full builds are started. Both
2030 Schedulers only pay attention to the default branch: any changes on
2031 other branches are ignored by these Schedulers. Each Scheduler
2032 triggers a different set of Builders, referenced by name.
2034 The third Scheduler in this example just runs the full solaris build
2035 once per day. (note that this Scheduler only lets you control the time
2036 between builds, not the absolute time-of-day of each Build, so this
2037 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2038 depending upon when it was first activated).
2040 @menu
2041 * Scheduler Types::             
2042 * Build Dependencies::          
2043 @end menu
2045 @node Scheduler Types, Build Dependencies, Listing Change Sources and Schedulers, Listing Change Sources and Schedulers
2046 @subsection Scheduler Types
2048 @slindex buildbot.scheduler.Scheduler
2049 @slindex buildbot.scheduler.AnyBranchScheduler
2050 @slindex buildbot.scheduler.Periodic
2051 @slindex buildbot.scheduler.Nightly
2053 Here is a brief catalog of the available Scheduler types. All these
2054 Schedulers are classes in @code{buildbot.scheduler}, and the
2055 docstrings there are the best source of documentation on the arguments
2056 taken by each one.
2058 @table @code
2059 @item Scheduler
2060 This is the default Scheduler class. It follows exactly one branch,
2061 and starts a configurable tree-stable-timer after each change on that
2062 branch. When the timer expires, it starts a build on some set of
2063 Builders. The Scheduler accepts a @code{fileIsImportant} function
2064 which can be used to ignore some Changes if they do not affect any
2065 ``important'' files.
2067 @item AnyBranchScheduler
2068 This scheduler uses a tree-stable-timer like the default one, but
2069 follows multiple branches at once. Each branch gets a separate timer.
2071 @item Dependent
2072 This scheduler watches an ``upstream'' Builder. When that Builder
2073 successfully builds a particular set of Changes, it triggers builds of
2074 the same code on a configured set of ``downstream'' builders. The next
2075 section (@pxref{Build Dependencies}) describes this scheduler in more
2076 detail.
2078 @item Periodic
2079 This simple scheduler just triggers a build every N seconds.
2081 @item Nightly
2082 This is highly configurable periodic build scheduler, which triggers a
2083 build at particular times of day, week, month, or year. The
2084 configuration syntax is very similar to the well-known @code{crontab}
2085 format, in which you provide values for minute, hour, day, and month
2086 (some of which can be wildcards), and a build is triggered whenever
2087 the current time matches the given constraints. This can run a build
2088 every night, every morning, every weekend, alternate Thursdays, on
2089 your boss's birthday, etc.
2091 @item Try_Jobdir / Try_Userpass
2092 This scheduler allows developers to use the @code{buildbot try}
2093 command to trigger builds of code they have not yet committed. See
2094 @ref{try} for complete details.
2096 @end table
2098 @node Build Dependencies,  , Scheduler Types, Listing Change Sources and Schedulers
2099 @subsection Build Dependencies
2101 @cindex Dependent
2102 @cindex Dependencies
2103 @slindex buildbot.scheduler.Dependent
2105 It is common to wind up with one kind of build which should only be
2106 performed if the same source code was successfully handled by some
2107 other kind of build first. An example might be a packaging step: you
2108 might only want to produce .deb or RPM packages from a tree that was
2109 known to compile successfully and pass all unit tests. You could put
2110 the packaging step in the same Build as the compile and testing steps,
2111 but there might be other reasons to not do this (in particular you
2112 might have several Builders worth of compiles/tests, but only wish to
2113 do the packaging once). Another example is if you want to skip the
2114 ``full'' builds after a failing ``quick'' build of the same source
2115 code. Or, if one Build creates a product (like a compiled library)
2116 that is used by some other Builder, you'd want to make sure the
2117 consuming Build is run @emph{after} the producing one.
2119 You can use @code{Dependencies} to express this relationship to the
2120 Buildbot. There is a special kind of Scheduler named
2121 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2122 for builds to complete successfully (on all of its Builders). Each
2123 time that happens, the same source code (i.e. the same
2124 @code{SourceStamp}) will be used to start a new set of builds, on a
2125 different set of Builders. This ``downstream'' scheduler doesn't pay
2126 attention to Changes at all, it only pays attention to the upstream
2127 scheduler.
2129 If the SourceStamp fails on any of the Builders in the upstream set,
2130 the downstream builds will not fire.
2132 @example
2133 from buildbot import scheduler
2134 tests = scheduler.Scheduler("tests", None, 5*60,
2135                             ["full-linux", "full-netbsd", "full-OSX"])
2136 package = scheduler.Dependent("package",
2137                               tests, # upstream scheduler
2138                               ["make-tarball", "make-deb", "make-rpm"])
2139 c['schedulers'] = [tests, package]
2140 @end example
2142 Note that @code{Dependent}'s upstream scheduler argument is given as a
2143 @code{Scheduler} @emph{instance}, not a name. This makes it impossible
2144 to create circular dependencies in the config file.
2147 @node Setting the slaveport, Buildslave Specifiers, Listing Change Sources and Schedulers, Configuration
2148 @section Setting the slaveport
2150 @bcindex c['slavePortnum']
2152 The buildmaster will listen on a TCP port of your choosing for
2153 connections from buildslaves. It can also use this port for
2154 connections from remote Change Sources, status clients, and debug
2155 tools. This port should be visible to the outside world, and you'll
2156 need to tell your buildslave admins about your choice.
2158 It does not matter which port you pick, as long it is externally
2159 visible, however you should probably use something larger than 1024,
2160 since most operating systems don't allow non-root processes to bind to
2161 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2162 box of some sort, you may have to configure your firewall to permit
2163 inbound connections to this port.
2165 @example
2166 c['slavePortnum'] = 10000
2167 @end example
2169 @code{c['slavePortnum']} is a @emph{strports} specification string,
2170 defined in the @code{twisted.application.strports} module (try
2171 @command{pydoc twisted.application.strports} to get documentation on
2172 the format). This means that you can have the buildmaster listen on a
2173 localhost-only port by doing:
2175 @example
2176 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2177 @end example
2179 This might be useful if you only run buildslaves on the same machine,
2180 and they are all configured to contact the buildmaster at
2181 @code{localhost:10000}.
2184 @node Buildslave Specifiers, Defining Builders, Setting the slaveport, Configuration
2185 @section Buildslave Specifiers
2187 @bcindex c['bots']
2189 The @code{c['bots']} key is a list of known buildslaves. Each
2190 buildslave is defined by a tuple of (slavename, slavepassword). These
2191 are the same two values that need to be provided to the buildslave
2192 administrator when they create the buildslave.
2194 @example
2195 c['bots'] = [('bot-solaris', 'solarispasswd'),
2196              ('bot-bsd', 'bsdpasswd'),
2197             ]
2198 @end example
2200 The slavenames must be unique, of course. The password exists to
2201 prevent evildoers from interfering with the buildbot by inserting
2202 their own (broken) buildslaves into the system and thus displacing the
2203 real ones.
2205 Buildslaves with an unrecognized slavename or a non-matching password
2206 will be rejected when they attempt to connect, and a message
2207 describing the problem will be put in the log file (see @ref{Logfiles}).
2210 @node Defining Builders, Defining Status Targets, Buildslave Specifiers, Configuration
2211 @section Defining Builders
2213 @bcindex c['builders']
2215 The @code{c['builders']} key is a list of dictionaries which specify
2216 the Builders. The Buildmaster runs a collection of Builders, each of
2217 which handles a single type of build (e.g. full versus quick), on a
2218 single build slave. A Buildbot which makes sure that the latest code
2219 (``HEAD'') compiles correctly across four separate architecture will
2220 have four Builders, each performing the same build but on different
2221 slaves (one per platform).
2223 Each Builder gets a separate column in the waterfall display. In
2224 general, each Builder runs independently (although various kinds of
2225 interlocks can cause one Builder to have an effect on another).
2227 Each Builder specification dictionary has several required keys:
2229 @table @code
2230 @item name
2231 This specifies the Builder's name, which is used in status
2232 reports.
2234 @item slavename
2235 This specifies which buildslave will be used by this Builder.
2236 @code{slavename} must appear in the @code{c['bots']} list. Each
2237 buildslave can accomodate multiple Builders.
2239 @item slavenames
2240 If you provide @code{slavenames} instead of @code{slavename}, you can
2241 give a list of buildslaves which are capable of running this Builder.
2242 If multiple buildslaves are available for any given Builder, you will
2243 have some measure of redundancy: in case one slave goes offline, the
2244 others can still keep the Builder working. In addition, multiple
2245 buildslaves will allow multiple simultaneous builds for the same
2246 Builder, which might be useful if you have a lot of forced or ``try''
2247 builds taking place.
2249 If you use this feature, it is important to make sure that the
2250 buildslaves are all, in fact, capable of running the given build. The
2251 slave hosts should be configured similarly, otherwise you will spend a
2252 lot of time trying (unsuccessfully) to reproduce a failure that only
2253 occurs on some of the buildslaves and not the others. Different
2254 platforms, operating systems, versions of major programs or libraries,
2255 all these things mean you should use separate Builders.
2257 @item builddir
2258 This specifies the name of a subdirectory (under the base directory)
2259 in which everything related to this builder will be placed. On the
2260 buildmaster, this holds build status information. On the buildslave,
2261 this is where checkouts, compiles, and tests are run.
2263 @item factory
2264 This is a @code{buildbot.process.factory.BuildFactory} instance which
2265 controls how the build is performed. Full details appear in their own
2266 chapter, @xref{Build Process}. Parameters like the location of the CVS
2267 repository and the compile-time options used for the build are
2268 generally provided as arguments to the factory's constructor.
2270 @end table
2272 Other optional keys may be set on each Builder:
2274 @table @code
2276 @item category
2277 If provided, this is a string that identifies a category for the
2278 builder to be a part of. Status clients can limit themselves to a
2279 subset of the available categories. A common use for this is to add
2280 new builders to your setup (for a new module, or for a new buildslave)
2281 that do not work correctly yet and allow you to integrate them with
2282 the active builders. You can put these new builders in a test
2283 category, make your main status clients ignore them, and have only
2284 private status clients pick them up. As soon as they work, you can
2285 move them over to the active category.
2287 @end table
2290 @node Defining Status Targets, Debug options, Defining Builders, Configuration
2291 @section Defining Status Targets
2293 The Buildmaster has a variety of ways to present build status to
2294 various users. Each such delivery method is a ``Status Target'' object
2295 in the configuration's @code{status} list. To add status targets, you
2296 just append more objects to this list:
2298 @bcindex c['status']
2300 @example
2301 c['status'] = []
2303 from buildbot.status import html
2304 c['status'].append(html.Waterfall(http_port=8010))
2306 from buildbot.status import mail
2307 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
2308                       extraRecipients=["builds@@lists.example.com"],
2309                       sendToInterestedUsers=False)
2310 c['status'].append(m)
2312 from buildbot.status import words
2313 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
2314                              channels=["#example"]))
2315 @end example
2317 Status delivery has its own chapter, @xref{Status Delivery}, in which
2318 all the built-in status targets are documented.
2321 @node Debug options,  , Defining Status Targets, Configuration
2322 @section Debug options
2325 @bcindex c['debugPassword']
2326 If you set @code{c['debugPassword']}, then you can connect to the
2327 buildmaster with the diagnostic tool launched by @code{buildbot
2328 debugclient MASTER:PORT}. From this tool, you can reload the config
2329 file, manually force builds, and inject changes, which may be useful
2330 for testing your buildmaster without actually commiting changes to
2331 your repository (or before you have the Change Sources set up). The
2332 debug tool uses the same port number as the slaves do:
2333 @code{c['slavePortnum']}, and is authenticated with this password.
2335 @example
2336 c['debugPassword'] = "debugpassword"
2337 @end example
2339 @bcindex c['manhole']
2340 If you set @code{c['manhole']} to an instance of one of the classes in
2341 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
2342 and get an interactive Python shell, which may be useful for debugging
2343 buildbot internals. It is probably only useful for buildbot
2344 developers. It exposes full access to the buildmaster's account
2345 (including the ability to modify and delete files), so it should not
2346 be enabled with a weak or easily guessable password.
2348 There are three separate @code{Manhole} classes. Two of them use SSH,
2349 one uses unencrypted telnet. Two of them use a username+password
2350 combination to grant access, one of them uses an SSH-style
2351 @file{authorized_keys} file which contains a list of ssh public keys.
2353 @table @code
2354 @item manhole.AuthorizedKeysManhole
2355 You construct this with the name of a file that contains one SSH
2356 public key per line, just like @file{~/.ssh/authorized_keys}. If you
2357 provide a non-absolute filename, it will be interpreted relative to
2358 the buildmaster's base directory.
2360 @item manhole.PasswordManhole
2361 This one accepts SSH connections but asks for a username and password
2362 when authenticating. It accepts only one such pair.
2365 @item manhole.TelnetManhole
2366 This accepts regular unencrypted telnet connections, and asks for a
2367 username/password pair before providing access. Because this
2368 username/password is transmitted in the clear, and because Manhole
2369 access to the buildmaster is equivalent to granting full shell
2370 privileges to both the buildmaster and all the buildslaves (and to all
2371 accounts which then run code produced by the buildslaves), it is
2372 highly recommended that you use one of the SSH manholes instead.
2374 @end table
2376 @example
2377 # some examples:
2378 from buildbot import manhole
2379 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
2380 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
2381 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
2382 @end example
2384 The @code{Manhole} instance can be configured to listen on a specific
2385 port. You may wish to have this listening port bind to the loopback
2386 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
2387 restrict access to clients which are running on the same host.
2389 @example
2390 from buildbot.manhole import PasswordManhole
2391 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
2392 @end example
2394 To have the @code{Manhole} listen on all interfaces, use
2395 @code{"tcp:9999"} or simply 9999. This port specification uses
2396 @code{twisted.application.strports}, so you can make it listen on SSL
2397 or even UNIX-domain sockets if you want.
2399 Note that using any Manhole requires that the TwistedConch package be
2400 installed, and that you be using Twisted version 2.0 or later.
2402 The buildmaster's SSH server will use a different host key than the
2403 normal sshd running on a typical unix host. This will cause the ssh
2404 client to complain about a ``host key mismatch'', because it does not
2405 realize there are two separate servers running on the same host. To
2406 avoid this, use a clause like the following in your @file{.ssh/config}
2407 file:
2409 @example
2410 Host remotehost-buildbot
2411  HostName remotehost
2412  HostKeyAlias remotehost-buildbot
2413  Port 9999
2414  # use 'user' if you use PasswordManhole and your name is not 'admin'.
2415  # if you use AuthorizedKeysManhole, this probably doesn't matter.
2416  User admin
2417 @end example
2420 @node Getting Source Code Changes, Build Process, Configuration, Top
2421 @chapter Getting Source Code Changes
2423 The most common way to use the Buildbot is centered around the idea of
2424 @code{Source Trees}: a directory tree filled with source code of some form
2425 which can be compiled and/or tested. Some projects use languages that don't
2426 involve any compilation step: nevertheless there may be a @code{build} phase
2427 where files are copied or rearranged into a form that is suitable for
2428 installation. Some projects do not have unit tests, and the Buildbot is
2429 merely helping to make sure that the sources can compile correctly. But in
2430 all of these cases, the thing-being-tested is a single source tree.
2432 A Version Control System mantains a source tree, and tells the
2433 buildmaster when it changes. The first step of each Build is typically
2434 to acquire a copy of some version of this tree.
2436 This chapter describes how the Buildbot learns about what Changes have
2437 occurred. For more information on VC systems and Changes, see
2438 @ref{Version Control Systems}.
2441 @menu
2442 * Change Sources::              
2443 @end menu
2447 @node Change Sources,  , Getting Source Code Changes, Getting Source Code Changes
2448 @section Change Sources
2450 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
2451 @c so narrow-minded anymore
2453 Each Buildmaster watches a single source tree. Changes can be provided
2454 by a variety of ChangeSource types, however any given project will
2455 typically have only a single ChangeSource active. This section
2456 provides a description of all available ChangeSource types and
2457 explains how to set up each of them.
2459 There are a variety of ChangeSources available, some of which are
2460 meant to be used in conjunction with other tools to deliver Change
2461 events from the VC repository to the buildmaster.
2463 @itemize @bullet
2465 @item CVSToys
2466 This ChangeSource opens a TCP connection from the buildmaster to a
2467 waiting FreshCVS daemon that lives on the repository machine, and
2468 subscribes to hear about Changes.
2470 @item MaildirSource
2471 This one watches a local maildir-format inbox for email sent out by
2472 the repository when a change is made. When a message arrives, it is
2473 parsed to create the Change object. A variety of parsing functions are
2474 available to accomodate different email-sending tools.
2476 @item PBChangeSource
2477 This ChangeSource listens on a local TCP socket for inbound
2478 connections from a separate tool. Usually, this tool would be run on
2479 the VC repository machine in a commit hook. It is expected to connect
2480 to the TCP socket and send a Change message over the network
2481 connection. The @command{buildbot sendchange} command is one example
2482 of a tool that knows how to send these messages, so you can write a
2483 commit script for your VC system that calls it to deliver the Change.
2484 There are other tools in the contrib/ directory that use the same
2485 protocol.
2487 @end itemize
2489 As a quick guide, here is a list of VC systems and the ChangeSources
2490 that might be useful with them. All of these ChangeSources are in the
2491 @code{buildbot.changes} module.
2493 @table @code
2494 @item CVS
2496 @itemize @bullet
2497 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
2498 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
2499 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
2500 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
2501 @item pb.PBChangeSource (listening for connections from @code{buildbot
2502 sendchange} run in a loginfo script)
2503 @item pb.PBChangeSource (listening for connections from a long-running
2504 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
2505 database directly
2506 @end itemize
2508 @item SVN
2509 @itemize @bullet
2510 @item pb.PBChangeSource (listening for connections from
2511 @code{contrib/svn_buildbot.py} run in a postcommit script)
2512 @item pb.PBChangeSource (listening for connections from a long-running
2513 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
2514 process
2515 @end itemize
2517 @item Darcs
2518 @itemize @bullet
2519 @item pb.PBChangeSource (listening for connections from
2520 @code{contrib/darcs_buildbot.py} in a commit script
2521 @end itemize
2523 @item Mercurial
2524 @itemize @bullet
2525 @item pb.PBChangeSource (listening for connections from
2526 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
2527 @end itemize
2529 @item Arch/Bazaar
2530 @itemize @bullet
2531 @item pb.PBChangeSource (listening for connections from
2532 @code{contrib/arch_buildbot.py} run in a commit hook)
2533 @end itemize
2535 @end table
2537 All VC systems can be driven by a PBChangeSource and the
2538 @code{buildbot sendchange} tool run from some form of commit script.
2539 If you write an email parsing function, they can also all be driven by
2540 a suitable @code{MaildirSource}.
2543 * SvnSource::                    
2544 @menu
2545 * Choosing ChangeSources::      
2546 * CVSToys - PBService::         
2547 * CVSToys - mail notification::  
2548 * Other mail notification ChangeSources::  
2549 * PBChangeSource::              
2550 * P4Source::                    
2551 * BonsaiPoller::                
2552 * SvnSource::                   
2553 @end menu
2555 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Change Sources
2556 @subsection Choosing ChangeSources
2558 The @code{master.cfg} configuration file has a dictionary key named
2559 @code{BuildmasterConfig['sources']}, which holds a list of
2560 @code{IChangeSource} objects. The config file will typically create an
2561 object from one of the classes described below and stuff it into the
2562 list.
2564 @example
2565 s = FreshCVSSourceNewcred(host="host", port=4519,
2566                           user="alice", passwd="secret",
2567                           prefix="Twisted")
2568 BuildmasterConfig['sources'] = [s]
2569 @end example
2571 Each source tree has a nominal @code{top}. Each Change has a list of
2572 filenames, which are all relative to this top location. The
2573 ChangeSource is responsible for doing whatever is necessary to
2574 accomplish this. Most sources have a @code{prefix} argument: a partial
2575 pathname which is stripped from the front of all filenames provided to
2576 that @code{ChangeSource}. Files which are outside this sub-tree are
2577 ignored by the changesource: it does not generate Changes for those
2578 files.
2581 @node CVSToys - PBService, CVSToys - mail notification, Choosing ChangeSources, Change Sources
2582 @subsection CVSToys - PBService
2584 @csindex buildbot.changes.freshcvs.FreshCVSSource
2586 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
2587 server which runs on the machine that hosts the CVS repository it
2588 watches. It has a variety of ways to distribute commit notifications,
2589 and offers a flexible regexp-based way to filter out uninteresting
2590 changes. One of the notification options is named @code{PBService} and
2591 works by listening on a TCP port for clients. These clients subscribe
2592 to hear about commit notifications.
2594 The buildmaster has a CVSToys-compatible @code{PBService} client built
2595 in. There are two versions of it, one for old versions of CVSToys
2596 (1.0.9 and earlier) which used the @code{oldcred} authentication
2597 framework, and one for newer versions (1.0.10 and later) which use
2598 @code{newcred}. Both are classes in the
2599 @code{buildbot.changes.freshcvs} package.
2601 @code{FreshCVSSourceNewcred} objects are created with the following
2602 parameters:
2604 @table @samp
2606 @item @code{host} and @code{port}
2607 these specify where the CVSToys server can be reached
2609 @item @code{user} and @code{passwd}
2610 these specify the login information for the CVSToys server
2611 (@code{freshcvs}). These must match the server's values, which are
2612 defined in the @code{freshCfg} configuration file (which lives in the
2613 CVSROOT directory of the repository).
2615 @item @code{prefix}
2616 this is the prefix to be found and stripped from filenames delivered
2617 by the CVSToys server. Most projects live in sub-directories of the
2618 main repository, as siblings of the CVSROOT sub-directory, so
2619 typically this prefix is set to that top sub-directory name.
2621 @end table
2623 @heading Example
2625 To set up the freshCVS server, add a statement like the following to
2626 your @file{freshCfg} file:
2628 @example
2629 pb = ConfigurationSet([
2630     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
2631     ])
2632 @end example
2634 This will announce all changes to a client which connects to port 4519
2635 using a username of 'foo' and a password of 'bar'.
2637 Then add a clause like this to your buildmaster's @file{master.cfg}:
2639 @example
2640 BuildmasterConfig['sources'] = [FreshCVSSource("cvs.example.com", 4519,
2641                                 "foo", "bar",
2642                                 prefix="glib/")]
2643 @end example
2645 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
2646 "glib" is the top-level directory (relative to the repository's root) where
2647 all your source code lives. Most projects keep one or more projects in the
2648 same repository (along with CVSROOT/ to hold admin files like loginfo and
2649 freshCfg); the prefix= argument tells the buildmaster to ignore everything
2650 outside that directory, and to strip that common prefix from all pathnames
2651 it handles.
2655 @node CVSToys - mail notification, Other mail notification ChangeSources, CVSToys - PBService, Change Sources
2656 @subsection CVSToys - mail notification
2658 @csindex buildbot.changes.mail.FCMaildirSource
2660 CVSToys also provides a @code{MailNotification} action which will send
2661 email to a list of recipients for each commit. This tends to work
2662 better than using @code{/bin/mail} from within the CVSROOT/loginfo
2663 file directly, as CVSToys will batch together all files changed during
2664 the same CVS invocation, and can provide more information (like
2665 creating a ViewCVS URL for each file changed).
2667 The Buildbot's @code{FCMaildirSource} is a ChangeSource which knows
2668 how to parse these CVSToys messages and turn them into Change objects.
2669 It watches a Maildir for new messages. The usually installation
2670 process looks like:
2672 @enumerate
2673 @item
2674 Create a mailing list, @code{projectname-commits}.
2675 @item
2676 In CVSToys' freshCfg file, use a @code{MailNotification} action to
2677 send commit mail to this mailing list.
2678 @item
2679 Subscribe the buildbot user to the mailing list.
2680 @item
2681 Configure your .qmail or .forward file to deliver these messages into
2682 a maildir.
2683 @item
2684 In the Buildbot's master.cfg file, use a @code{FCMaildirSource} to
2685 watch the maildir for commit messages.
2686 @end enumerate
2688 The @code{FCMaildirSource} is created with two parameters: the
2689 directory name of the maildir root, and the prefix to strip.
2691 @node Other mail notification ChangeSources, PBChangeSource, CVSToys - mail notification, Change Sources
2692 @subsection Other mail notification ChangeSources
2694 @csindex buildbot.changes.mail.SyncmailMaildirSource
2695 @csindex buildbot.changes.mail.BonsaiMaildirSource
2697 There are other types of maildir-watching ChangeSources, which only
2698 differ in the function used to parse the message body.
2700 @code{SyncmailMaildirSource} knows how to parse the message format
2701 used in mail sent by Syncmail.
2703 @code{BonsaiMaildirSource} parses messages sent out by Bonsai.
2705 @node PBChangeSource, P4Source, Other mail notification ChangeSources, Change Sources
2706 @subsection PBChangeSource
2708 @csindex buildbot.changes.pb.PBChangeSource
2710 The last kind of ChangeSource actually listens on a TCP port for
2711 clients to connect and push change notices @emph{into} the
2712 Buildmaster. This is used by the built-in @code{buildbot sendchange}
2713 notification tool, as well as the VC-specific
2714 @file{contrib/svn_buildbot.py} and @file{contrib/arch_buildbot.py}
2715 tools. These tools are run by the repository (in a commit hook
2716 script), and connect to the buildmaster directly each time a file is
2717 comitted. This is also useful for creating new kinds of change sources
2718 that work on a @code{push} model instead of some kind of subscription
2719 scheme, for example a script which is run out of an email .forward
2720 file.
2722 This ChangeSource can be configured to listen on its own TCP port, or
2723 it can share the port that the buildmaster is already using for the
2724 buildslaves to connect. (This is possible because the
2725 @code{PBChangeSource} uses the same protocol as the buildslaves, and
2726 they can be distinguished by the @code{username} attribute used when
2727 the initial connection is established). It might be useful to have it
2728 listen on a different port if, for example, you wanted to establish
2729 different firewall rules for that port. You could allow only the SVN
2730 repository machine access to the @code{PBChangeSource} port, while
2731 allowing only the buildslave machines access to the slave port. Or you
2732 could just expose one port and run everything over it. @emph{Note:
2733 this feature is not yet implemented, the PBChangeSource will always
2734 share the slave port and will always have a @code{user} name of
2735 @code{change}, and a passwd of @code{changepw}. These limitations will
2736 be removed in the future.}.
2739 The @code{PBChangeSource} is created with the following arguments. All
2740 are optional.
2742 @table @samp
2743 @item @code{port}
2744 which port to listen on. If @code{None} (which is the default), it
2745 shares the port used for buildslave connections. @emph{Not
2746 Implemented, always set to @code{None}}.
2748 @item @code{user} and @code{passwd}
2749 The user/passwd account information that the client program must use
2750 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
2751 Implemented, @code{user} is currently always set to @code{change},
2752 @code{passwd} is always set to @code{changepw}}.
2754 @item @code{prefix}
2755 The prefix to be found and stripped from filenames delivered over the
2756 connection. Any filenames which do not start with this prefix will be
2757 removed. If all the filenames in a given Change are removed, the that
2758 whole Change will be dropped. This string should probably end with a
2759 directory separator.
2761 This is useful for changes coming from version control systems that
2762 represent branches as parent directories within the repository (like
2763 SVN and Perforce). Use a prefix of 'trunk/' or
2764 'project/branches/foobranch/' to only follow one branch and to get
2765 correct tree-relative filenames. Without a prefix, the PBChangeSource
2766 will probably deliver Changes with filenames like @file{trunk/foo.c}
2767 instead of just @file{foo.c}. Of course this also depends upon the
2768 tool sending the Changes in (like @command{buildbot sendchange}) and
2769 what filenames it is delivering: that tool may be filtering and
2770 stripping prefixes at the sending end.
2772 @end table
2774 @node P4Source, BonsaiPoller, PBChangeSource, Change Sources
2775 @subsection P4Source
2777 @csindex buildbot.changes.p4poller.P4Source
2779 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
2780 Perforce} depot for changes. It accepts the following arguments:
2782 @table @samp
2783 @item @code{p4base}
2784 The base depot path to watch, without the trailing '/...'.
2786 @item @code{p4port}
2787 The Perforce server to connect to (as host:port).
2789 @item @code{p4user}
2790 The Perforce user.
2792 @item @code{p4passwd}
2793 The Perforce password.
2795 @item @code{split_file}
2796 A function that maps a pathname, without the leading @code{p4base}, to a
2797 (branch, filename) tuple. The default just returns (None, branchfile),
2798 which effectively disables branch support. You should supply a function
2799 which understands your repository structure.
2801 @item @code{pollinterval}
2802 How often to poll, in seconds. Defaults to 600 (10 minutes).
2804 @item @code{histmax}
2805 The maximum number of changes to inspect at a time. If more than this
2806 number occur since the last poll, older changes will be silently
2807 ignored.
2808 @end table
2810 @heading Example
2812 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
2813 specified in the buildmaster's environment. It watches a project in which the
2814 branch name is simply the next path component, and the file is all path
2815 components after.
2817 @example
2818 import buildbot.changes.p4poller
2819 c['sources'].append(p4poller.P4Source(
2820         p4base='//depot/project/',
2821         split_file=lambda branchfile: branchfile.split('/',1)
2823 @end example
2825 @node BonsaiPoller, SvnSource, P4Source, Change Sources
2826 @subsection BonsaiPoller
2828 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
2830 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
2831 CGI script accessed through a web server that provides information
2832 about a CVS tree, for example the Mozilla bonsai server at
2833 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
2834 humans and machines. In this case, the buildbot's change source forms
2835 a query which asks about any files in the specified branch which have
2836 changed since the last query.
2838 Please take a look at the BonsaiPoller docstring for details about the
2839 arguments it accepts.
2842 @node SvnSource,  , BonsaiPoller, Change Sources
2843 @subsection SvnSource
2845 @csindex buildbot.changes.svnpoller.SvnSource
2847 The @code{buildbot.changes.svnpoller.SvnSource} is a ChangeSource
2848 which periodically polls a @uref{http://subversion.tigris.org/,
2849 Subversion} repository for new revisions, by running the @code{svn
2850 log} command in a subshell. It can watch a single branch or multiple
2851 branches.
2853 @code{SvnSource} accepts the following arguments:
2855 @table @code
2856 @item svnurl
2857 The base URL path to watch, like
2858 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
2859 @code{http://divmod.org/svn/Divmod/}, or even
2860 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
2861 include the access scheme, the location of the repository (both the
2862 hostname for remote ones, and any additional directory names necessary
2863 to get to the repository), and the sub-path within the repository's
2864 virtual filesystem for the project and branch of interest.
2866 The @code{SvnSource} will only pay attention to files inside the
2867 subdirectory specified by the complete svnurl.
2869 @item split_file
2870 A function to convert pathnames into (branch, relative_pathname)
2871 tuples. Use this to explain your repository's branch-naming policy to
2872 @code{SvnSource}. This function must accept a single string and return
2873 a two-entry tuple. There are a few utility functions in
2874 @code{buildbot.changes.svnpoller} that can be used as a
2875 @code{split_file} function, see below for details.
2877 The default value always returns (None, path), which indicates that
2878 all files are on the trunk.
2880 Subclasses of @code{SvnSource} can override the @code{split_file}
2881 method instead of using the @code{split_file=} argument.
2883 @item svnuser
2884 An optional string parameter. If set, the @code{--user} argument will
2885 be added to all @code{svn} commands. Use this if you have to
2886 authenticate to the svn server before you can do @code{svn info} or
2887 @code{svn log} commands.
2889 @item svnpasswd
2890 Like @code{svnuser}, this will cause a @code{--password} argument to
2891 be passed to all svn commands.
2893 @item pollinterval
2894 How often to poll, in seconds. Defaults to 600 (checking once every 10
2895 minutes). Lower this if you want the buildbot to notice changes
2896 faster, raise it if you want to reduce the network and CPU load on
2897 your svn server. Please be considerate of public SVN repositories by
2898 using a large interval when polling them.
2900 @item histmax
2901 The maximum number of changes to inspect at a time. Every POLLINTERVAL
2902 seconds, the @code{SvnSource} asks for the last HISTMAX changes and
2903 looks through them for any ones it does not already know about. If
2904 more than HISTMAX revisions have been committed since the last poll,
2905 older changes will be silently ignored. Larger values of histmax will
2906 cause more time and memory to be consumed on each poll attempt.
2907 @code{histmax} defaults to 100.
2909 @item svnbin
2910 This controls the @code{svn} executable to use. If subversion is
2911 installed in a weird place on your system (outside of the
2912 buildmaster's @code{$PATH}), use this to tell @code{SvnSource} where
2913 to find it. The default value of ``svn'' will almost always be
2914 sufficient.
2916 @end table
2918 @heading Branches
2920 Each source file that is tracked by a Subversion repository has a
2921 fully-qualified SVN URL in the following form:
2922 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
2923 @code{SvnSource}, you give it a @code{svnurl} value that includes all
2924 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
2925 string. The @code{SvnSource} is responsible for producing Changes that
2926 contain a branch name and a FILEPATH (which is relative to the top of
2927 a checked-out tree). The details of how these strings are split up
2928 depend upon how your repository names its branches.
2930 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
2932 One common layout is to have all the various projects that share a
2933 repository get a single top-level directory each. Then under a given
2934 project's directory, you get two subdirectories, one named ``trunk''
2935 and another named ``branches''. Under ``branches'' you have a bunch of
2936 other directories, one per branch, with names like ``1.5.x'' and
2937 ``testing''. It is also common to see directories like ``tags'' and
2938 ``releases'' next to ``branches'' and ``trunk''.
2940 For example, the Twisted project has a subversion server on
2941 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
2942 repository is available through a SCHEME of ``svn:''. The primary
2943 sub-project is Twisted, of course, with a repository root of
2944 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
2945 Informant, with a root of
2946 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
2947 checked-out Twisted tree, there is a file named bin/trial (which is
2948 used to run unit test suites).
2950 The trunk for Twisted is in
2951 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
2952 fully-qualified SVN URL for the trunk version of @code{trial} would be
2953 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
2954 SVNURL for that file on a branch named ``1.5.x'' would be
2955 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
2957 To set up a @code{SvnSource} that watches the Twisted trunk (and
2958 nothing else), we would use the following:
2960 @example
2961 from buildbot.changes.svnpoller import SvnSource
2962 s = SvnSource("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
2963 c['sources'].append(ss)
2964 @end example
2966 In this case, every Change that our @code{SvnSource} produces will
2967 have @code{.branch=None}, to indicate that the Change is on the trunk.
2968 No other sub-projects or branches will be tracked.
2970 If we want our ChangeSource to follow multiple branches, we have to do
2971 two things. First we have to change our @code{svnurl=} argument to
2972 watch more than just ``.../Twisted/trunk''. We will set it to
2973 ``.../Twisted'' so that we'll see both the trunk and all the branches.
2974 Second, we have to tell @code{SvnSource} how to split the
2975 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
2976 out into (BRANCH) and (FILEPATH) pairs.
2978 We do the latter by providing a ``split_file'' function. This function
2979 is responsible for splitting something like
2980 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
2981 @code{filepath}=''bin/trial''. This function is always given a string
2982 that names a file relative to the subdirectory pointed to by the
2983 @code{SvnSource}'s @code{svnurl=} argument. It is expected to return a
2984 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
2985 branch indicated), or None to indicate that the file is outside any
2986 project of interest.
2988 (note that we want to see ``branches/1.5.x'' rather than just
2989 ``1.5.x'' because when we perform the SVN checkout, we will probably
2990 append the branch name to the baseURL, which requires that we keep the
2991 ``branches'' component in there. Other VC schemes use a different
2992 approach towards branches and may not require this artifact.)
2994 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
2995 scheme, the following function will work:
2997 @example
2998 def split_file_branches(path):
2999     pieces = path.split('/')
3000     if pieces[0] == 'trunk':
3001         return (None, '/'.join(pieces[1:]))
3002     elif pieces[0] == 'branches':
3003         return ('/'.join(pieces[0:2]),
3004                 '/'.join(pieces[2:]))
3005     else:
3006         return None
3007 @end example
3009 This function is provided as
3010 @code{buildbot.changes.svnpoller.split_file_branches} for your
3011 convenience. So to have our Twisted-watching @code{SvnSource} follow
3012 multiple branches, we would use this:
3014 @example
3015 from buildbot.changes.svnpoller import SvnSource, split_file_branches
3016 s = SvnSource("svn://svn.twistedmatrix.com/svn/Twisted",
3017               split_file=split_file_branches)
3018 c['sources'].append(ss)
3019 @end example
3021 Changes for all sorts of branches (with names like ``branches/1.5.x'',
3022 and None to indicate the trunk) will be delivered to the Schedulers.
3023 Each Scheduler is then free to use or ignore each branch as it sees
3024 fit.
3026 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
3028 Another common way to organize a Subversion repository is to put the
3029 branch name at the top, and the projects underneath. This is
3030 especially frequent when there are a number of related sub-projects
3031 that all get released in a group.
3033 For example, Divmod.org hosts a project named ``Nevow'' as well as one
3034 named ``Quotient''. In a checked-out Nevow tree there is a directory
3035 named ``formless'' that contains a python source file named
3036 ``webform.py''. This repository is accessible via webdav (and thus
3037 uses an ``http:'' scheme) through the divmod.org hostname. There are
3038 many branches in this repository, and they use a
3039 (BRANCHNAME)/(PROJECT) naming policy.
3041 The fully-qualified SVN URL for the trunk version of webform.py is
3042 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
3043 You can do an @code{svn co} with that URL and get a copy of the latest
3044 version. The 1.5.x branch version of this file would have a URL of
3045 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
3046 The whole Nevow trunk would be checked out with
3047 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
3048 trunk would be checked out using
3049 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
3051 Now suppose we want to have an @code{SvnSource} that only cares about
3052 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
3053 described earlier:
3055 @example
3056 from buildbot.changes.svnpoller import SvnSource
3057 s = SvnSource("http://divmod.org/svn/Divmod/trunk/Nevow")
3058 c['sources'].append(ss)
3059 @end example
3061 But what happens when we want to track multiple Nevow branches? We
3062 have to point our @code{svnurl=} high enough to see all those
3063 branches, but we also don't want to include Quotient changes (since
3064 we're only building Nevow). To accomplish this, we must rely upon the
3065 @code{split_file} function to help us tell the difference between
3066 files that belong to Nevow and those that belong to Quotient, as well
3067 as figuring out which branch each one is on.
3069 @example
3070 from buildbot.changes.svnpoller import SvnSource
3071 s = SvnSource("http://divmod.org/svn/Divmod",
3072               split_file=my_file_splitter)
3073 c['sources'].append(ss)
3074 @end example
3076 The @code{my_file_splitter} function will be called with
3077 repository-relative pathnames like:
3079 @table @code
3080 @item trunk/Nevow/formless/webform.py
3081 This is a Nevow file, on the trunk. We want the Change that includes this
3082 to see a filename of @code{formless/webform.py"}, and a branch of None
3084 @item branches/1.5.x/Nevow/formless/webform.py
3085 This is a Nevow file, on a branch. We want to get
3086 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
3088 @item trunk/Quotient/setup.py
3089 This is a Quotient file, so we want to ignore it by having
3090 @code{my_file_splitter} return None.
3092 @item branches/1.5.x/Quotient/setup.py
3093 This is also a Quotient file, which should be ignored.
3094 @end table
3096 The following definition for @code{my_file_splitter} will do the job:
3098 @example
3099 def my_file_splitter(path):
3100     pieces = path.split('/')
3101     if pieces[0] == 'trunk':
3102         branch = None
3103         pieces.pop(0) # remove 'trunk'
3104     elif pieces[0] == 'branches':
3105         pieces.pop(0) # remove 'branches'
3106         # grab branch name
3107         branch = 'branches/' + pieces.pop(0)
3108     else:
3109         return None # something weird
3110     projectname = pieces.pop(0)
3111     if projectname != 'Nevow':
3112         return None # wrong project
3113     return (branch, '/'.join(pieces))
3114 @end example
3117 @node Build Process, Status Delivery, Getting Source Code Changes, Top
3118 @chapter Build Process
3120 A @code{Build} object is responsible for actually performing a build.
3121 It gets access to a remote @code{SlaveBuilder} where it may run
3122 commands, and a @code{BuildStatus} object where it must emit status
3123 events. The @code{Build} is created by the Builder's
3124 @code{BuildFactory}.
3126 The default @code{Build} class is made up of a fixed sequence of
3127 @code{BuildSteps}, executed one after another until all are complete
3128 (or one of them indicates that the build should be halted early). The
3129 default @code{BuildFactory} creates instances of this @code{Build}
3130 class with a list of @code{BuildSteps}, so the basic way to configure
3131 the build is to provide a list of @code{BuildSteps} to your
3132 @code{BuildFactory}.
3134 More complicated @code{Build} subclasses can make other decisions:
3135 execute some steps only if certain files were changed, or if certain
3136 previous steps passed or failed. The base class has been written to
3137 allow users to express basic control flow without writing code, but
3138 you can always subclass and customize to achieve more specialized
3139 behavior.
3141 @menu
3142 * Build Steps::                 
3143 * Interlocks::                  
3144 * Build Factories::             
3145 @end menu
3147 @node Build Steps, Interlocks, Build Process, Build Process
3148 @section Build Steps
3150 @code{BuildStep}s are usually specified in the buildmaster's
3151 configuration file, in a list of ``step specifications'' that is used
3152 to create the @code{BuildFactory}. These ``step specifications'' are
3153 not actual steps, but rather a tuple of the @code{BuildStep} subclass
3154 to be created and a dictionary of arguments. (the actual
3155 @code{BuildStep} instances are not created until the Build is started,
3156 so that each Build gets an independent copy of each BuildStep). The
3157 preferred way to create these step specifications is with the
3158 @code{BuildFactory}'s @code{addStep} method:
3160 @example
3161 from buildbot.steps import source, shell
3162 from buildbot.process import factory
3164 f = factory.BuildFactory()
3165 f.addStep(source.SVN, svnurl="http://svn.example.org/Trunk/")
3166 f.addStep(shell.ShellCommand, command=["make", "all"])
3167 f.addStep(shell.ShellCommand, command=["make", "test"])
3168 @end example
3170 The rest of this section lists all the standard BuildStep objects
3171 available for use in a Build, and the parameters which can be used to
3172 control each.
3174 @menu
3175 * Common Parameters::           
3176 * Source Checkout::             
3177 * ShellCommand::                
3178 * Simple ShellCommand Subclasses::  
3179 * Python BuildSteps::           
3180 * Transferring Files::          
3181 * Writing New BuildSteps::      
3182 @end menu
3184 @node Common Parameters, Source Checkout, Build Steps, Build Steps
3185 @subsection Common Parameters
3187 The standard @code{Build} runs a series of @code{BuildStep}s in order,
3188 only stopping when it runs out of steps or if one of them requests
3189 that the build be halted. It collects status information from each one
3190 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
3192 All BuildSteps accept some common parameters. Some of these control
3193 how their individual status affects the overall build. Others are used
3194 to specify which @code{Locks} (see @pxref{Interlocks}) should be
3195 acquired before allowing the step to run.
3197 Arguments common to all @code{BuildStep} subclasses:
3200 @table @code
3201 @item name
3202 the name used to describe the step on the status display. It is also
3203 used to give a name to any LogFiles created by this step.
3205 @item haltOnFailure
3206 if True, a FAILURE of this build step will cause the build to halt
3207 immediately with an overall result of FAILURE.
3209 @item flunkOnWarnings
3210 when True, a WARNINGS or FAILURE of this build step will mark the
3211 overall build as FAILURE. The remaining steps will still be executed.
3213 @item flunkOnFailure
3214 when True, a FAILURE of this build step will mark the overall build as
3215 a FAILURE. The remaining steps will still be executed.
3217 @item warnOnWarnings
3218 when True, a WARNINGS or FAILURE of this build step will mark the
3219 overall build as having WARNINGS. The remaining steps will still be
3220 executed.
3222 @item warnOnFailure
3223 when True, a FAILURE of this build step will mark the overall build as
3224 having WARNINGS. The remaining steps will still be executed.
3226 @item locks
3227 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
3228 @code{buildbot.locks.MasterLock}) that should be acquired before
3229 starting this Step. The Locks will be released when the step is
3230 complete. Note that this is a list of actual Lock instances, not
3231 names. Also note that all Locks must have unique names.
3233 @end table
3236 @node Source Checkout, ShellCommand, Common Parameters, Build Steps
3237 @subsection Source Checkout
3239 The first step of any build is typically to acquire the source code
3240 from which the build will be performed. There are several classes to
3241 handle this, one for each of the different source control system that
3242 Buildbot knows about. For a description of how Buildbot treats source
3243 control in general, see @ref{Version Control Systems}.
3245 All source checkout steps accept some common parameters to control how
3246 they get the sources and where they should be placed. The remaining
3247 per-VC-system parameters are mostly to specify where exactly the
3248 sources are coming from.
3250 @table @code
3251 @item mode
3253 a string describing the kind of VC operation that is desired. Defaults
3254 to @code{update}.
3256 @table @code
3257 @item update
3258 specifies that the CVS checkout/update should be performed directly
3259 into the workdir. Each build is performed in the same directory,
3260 allowing for incremental builds. This minimizes disk space, bandwidth,
3261 and CPU time. However, it may encounter problems if the build process
3262 does not handle dependencies properly (sometimes you must do a ``clean
3263 build'' to make sure everything gets compiled), or if source files are
3264 deleted but generated files can influence test behavior (e.g. python's
3265 .pyc files), or when source directories are deleted but generated
3266 files prevent CVS from removing them. Builds ought to be correct
3267 regardless of whether they are done ``from scratch'' or incrementally,
3268 but it is useful to test both kinds: this mode exercises the
3269 incremental-build style.
3271 @item copy
3272 specifies that the CVS workspace should be maintained in a separate
3273 directory (called the 'copydir'), using checkout or update as
3274 necessary. For each build, a new workdir is created with a copy of the
3275 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
3276 disk space required, but keeps the bandwidth low (update instead of a
3277 full checkout). A full 'clean' build is performed each time. This
3278 avoids any generated-file build problems, but is still occasionally
3279 vulnerable to CVS problems such as a repository being manually
3280 rearranged, causing CVS errors on update which are not an issue with a
3281 full checkout.
3283 @c TODO: something is screwy about this, revisit. Is it the source
3284 @c directory or the working directory that is deleted each time?
3286 @item clobber
3287 specifes that the working directory should be deleted each time,
3288 necessitating a full checkout for each build. This insures a clean
3289 build off a complete checkout, avoiding any of the problems described
3290 above. This mode exercises the ``from-scratch'' build style.
3292 @item export
3293 this is like @code{clobber}, except that the 'cvs export' command is
3294 used to create the working directory. This command removes all CVS
3295 metadata files (the CVS/ directories) from the tree, which is
3296 sometimes useful for creating source tarballs (to avoid including the
3297 metadata in the tar file).
3298 @end table
3300 @item workdir
3301 like all Steps, this indicates the directory where the build will take
3302 place. Source Steps are special in that they perform some operations
3303 outside of the workdir (like creating the workdir itself).
3305 @item alwaysUseLatest
3306 if True, bypass the usual ``update to the last Change'' behavior, and
3307 always update to the latest changes instead.
3309 @item retry
3310 If set, this specifies a tuple of @code{(delay, repeats)} which means
3311 that when a full VC checkout fails, it should be retried up to
3312 @var{repeats} times, waiting @var{delay} seconds between attempts. If
3313 you don't provide this, it defaults to @code{None}, which means VC
3314 operations should not be retried. This is provided to make life easier
3315 for buildslaves which are stuck behind poor network connections.
3317 @end table
3320 My habit as a developer is to do a @code{cvs update} and @code{make} each
3321 morning. Problems can occur, either because of bad code being checked in, or
3322 by incomplete dependencies causing a partial rebuild to fail where a
3323 complete from-scratch build might succeed. A quick Builder which emulates
3324 this incremental-build behavior would use the @code{mode='update'}
3325 setting.
3327 On the other hand, other kinds of dependency problems can cause a clean
3328 build to fail where a partial build might succeed. This frequently results
3329 from a link step that depends upon an object file that was removed from a
3330 later version of the tree: in the partial tree, the object file is still
3331 around (even though the Makefiles no longer know how to create it).
3333 ``official'' builds (traceable builds performed from a known set of
3334 source revisions) are always done as clean builds, to make sure it is
3335 not influenced by any uncontrolled factors (like leftover files from a
3336 previous build). A ``full'' Builder which behaves this way would want
3337 to use the @code{mode='clobber'} setting.
3339 Each VC system has a corresponding source checkout class: their
3340 arguments are described on the following pages.
3343 @menu
3344 * CVS::                         
3345 * SVN::                         
3346 * Darcs::                       
3347 * Mercurial::                   
3348 * Arch::                        
3349 * Bazaar::                      
3350 * P4::                          
3351 @end menu
3353 @node CVS, SVN, Source Checkout, Source Checkout
3354 @subsubsection CVS
3356 @cindex CVS Checkout
3357 @bsindex buildbot.steps.source.CVS
3360 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
3361 CVS} checkout or update. It takes the following arguments:
3363 @table @code
3364 @item cvsroot
3365 (required): specify the CVSROOT value, which points to a CVS
3366 repository, probably on a remote machine. For example, the cvsroot
3367 value you would use to get a copy of the Buildbot source code is
3368 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
3370 @item cvsmodule
3371 (required): specify the cvs @code{module}, which is generally a
3372 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
3373 code is @code{buildbot}.
3375 @item branch
3376 a string which will be used in a @code{-r} argument. This is most
3377 useful for specifying a branch to work on. Defaults to @code{HEAD}.
3379 @item global_options
3380 a list of flags to be put before the verb in the CVS command.
3382 @item checkoutDelay
3383 if set, the number of seconds to put between the timestamp of the last
3384 known Change and the value used for the @code{-D} option. Defaults to
3385 half of the parent Build's treeStableTimer.
3387 @end table
3390 @node SVN, Darcs, CVS, Source Checkout
3391 @subsubsection SVN
3393 @cindex SVN Checkout
3394 @bsindex buildbot.steps.source.SVN
3397 The @code{SVN} build step performs a
3398 @uref{http://subversion.tigris.org, Subversion} checkout or update.
3399 There are two basic ways of setting up the checkout step, depending
3400 upon whether you are using multiple branches or not.
3402 If all of your builds use the same branch, then you should create the
3403 @code{SVN} step with the @code{svnurl} argument:
3405 @table @code
3406 @item svnurl
3407 (required): this specifies the @code{URL} argument that will be given
3408 to the @code{svn checkout} command. It dictates both where the
3409 repository is located and which sub-tree should be extracted. In this
3410 respect, it is like a combination of the CVS @code{cvsroot} and
3411 @code{cvsmodule} arguments. For example, if you are using a remote
3412 Subversion repository which is accessible through HTTP at a URL of
3413 @code{http://svn.example.com/repos}, and you wanted to check out the
3414 @code{trunk/calc} sub-tree, you would use
3415 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
3416 to your @code{SVN} step.
3417 @end table
3419 If, on the other hand, you are building from multiple branches, then
3420 you should create the @code{SVN} step with the @code{baseURL} and
3421 @code{defaultBranch} arguments instead:
3423 @table @code
3424 @item baseURL
3425 (required): this specifies the base repository URL, to which a branch
3426 name will be appended. It should probably end in a slash.
3428 @item defaultBranch
3429 this specifies the name of the branch to use when a Build does not
3430 provide one of its own. This will be appended to @code{baseURL} to
3431 create the string that will be passed to the @code{svn checkout}
3432 command.
3433 @end table
3435 If you are using branches, you must also make sure your
3436 @code{ChangeSource} will report the correct branch names.
3438 @heading branch example
3440 Let's suppose that the ``MyProject'' repository uses branches for the
3441 trunk, for various users' individual development efforts, and for
3442 several new features that will require some amount of work (involving
3443 multiple developers) before they are ready to merge onto the trunk.
3444 Such a repository might be organized as follows:
3446 @example
3447 svn://svn.example.org/MyProject/trunk
3448 svn://svn.example.org/MyProject/branches/User1/foo
3449 svn://svn.example.org/MyProject/branches/User1/bar
3450 svn://svn.example.org/MyProject/branches/User2/baz
3451 svn://svn.example.org/MyProject/features/newthing
3452 svn://svn.example.org/MyProject/features/otherthing
3453 @end example
3455 Further assume that we want the Buildbot to run tests against the
3456 trunk and against all the feature branches (i.e., do a
3457 checkout/compile/build of branch X when a file has been changed on
3458 branch X, when X is in the set [trunk, features/newthing,
3459 features/otherthing]). We do not want the Buildbot to automatically
3460 build any of the user branches, but it should be willing to build a
3461 user branch when explicitly requested (most likely by the user who
3462 owns that branch).
3464 There are three things that need to be set up to accomodate this
3465 system. The first is a ChangeSource that is capable of identifying the
3466 branch which owns any given file. This depends upon a user-supplied
3467 function, in an external program that runs in the SVN commit hook and
3468 connects to the buildmaster's @code{PBChangeSource} over a TCP
3469 connection. (you can use the ``@code{buildbot sendchange}'' utility
3470 for this purpose, but you will still need an external program to
3471 decide what value should be passed to the @code{--branch=} argument).
3472 For example, a change to a file with the SVN url of
3473 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
3474 be broken down into a Change instance with
3475 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
3477 The second piece is an @code{AnyBranchScheduler} which will pay
3478 attention to the desired branches. It will not pay attention to the
3479 user branches, so it will not automatically start builds in response
3480 to changes there. The AnyBranchScheduler class requires you to
3481 explicitly list all the branches you want it to use, but it would not
3482 be difficult to write a subclass which used
3483 @code{branch.startswith('features/'} to remove the need for this
3484 explicit list. Or, if you want to build user branches too, you can use
3485 AnyBranchScheduler with @code{branches=None} to indicate that you want
3486 it to pay attention to all branches.
3488 The third piece is an @code{SVN} checkout step that is configured to
3489 handle the branches correctly, with a @code{baseURL} value that
3490 matches the way the ChangeSource splits each file's URL into base,
3491 branch, and file.
3493 @example
3494 from buildbot.changes.pb import PBChangeSource
3495 from buildbot.scheduler import AnyBranchScheduler
3496 from buildbot.process import source, factory
3497 from buildbot.steps import source, shell
3499 c['sources'] = [PBChangeSource()]
3500 s1 = AnyBranchScheduler('main',
3501                         ['trunk', 'features/newthing', 'features/otherthing'],
3502                         10*60, ['test-i386', 'test-ppc'])
3503 c['schedulers'] = [s1]
3505 f = factory.BuildFactory()
3506 f.addStep(source.SVN, mode='update',
3507           baseURL='svn://svn.example.org/MyProject/',
3508           defaultBranch='trunk')
3509 f.addStep(shell.Compile, command="make all")
3510 f.addStep(shell.Test, command="make test")
3512 c['builders'] = [
3513   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
3514                        'factory':f @},
3515   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
3516                       'factory':f @},
3518 @end example
3520 In this example, when a change arrives with a @code{branch} attribute
3521 of ``trunk'', the resulting build will have an SVN step that
3522 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
3523 ``trunk'' (the branch name) to get the correct svn command. If the
3524 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
3525 will concatenate ``svn://svn.example.org/MyProject/'' with
3526 ``features/newthing'' to get the svnurl for checkout.
3528 @node Darcs, Mercurial, SVN, Source Checkout
3529 @subsubsection Darcs
3531 @cindex Darcs Checkout
3532 @bsindex buildbot.steps.source.Darcs
3535 The @code{Darcs} build step performs a
3536 @uref{http://abridgegame.org/darcs/, Darcs} checkout or update.
3538 Like @xref{SVN}, this step can either be configured to always check
3539 out a specific tree, or set up to pull from a particular branch that
3540 gets specified separately for each build. Also like SVN, the
3541 repository URL given to Darcs is created by concatenating a
3542 @code{baseURL} with the branch name, and if no particular branch is
3543 requested, it uses a @code{defaultBranch}. The only difference in
3544 usage is that each potential Darcs repository URL must point to a
3545 fully-fledged repository, whereas SVN URLs usually point to sub-trees
3546 of the main Subversion repository. In other words, doing an SVN
3547 checkout of @code{baseURL} is legal, but silly, since you'd probably
3548 wind up with a copy of every single branch in the whole repository.
3549 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
3550 the parent directory of a collection of Darcs repositories is not
3551 itself a valid repository.
3553 The Darcs step takes the following arguments:
3555 @table @code
3556 @item repourl
3557 (required unless @code{baseURL} is provided): the URL at which the
3558 Darcs source repository is available.
3560 @item baseURL
3561 (required unless @code{repourl} is provided): the base repository URL,
3562 to which a branch name will be appended. It should probably end in a
3563 slash.
3565 @item defaultBranch
3566 (allowed if and only if @code{baseURL} is provided): this specifies
3567 the name of the branch to use when a Build does not provide one of its
3568 own. This will be appended to @code{baseURL} to create the string that
3569 will be passed to the @code{darcs get} command.
3570 @end table
3572 @node Mercurial, Arch, Darcs, Source Checkout
3573 @subsubsection Mercurial
3575 @cindex Mercurial Checkout
3576 @bsindex buildbot.steps.source.Mercurial
3579 The @code{Mercurial} build step performs a
3580 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
3581 or update.
3583 Branches are handled just like @xref{Darcs}.
3585 The Mercurial step takes the following arguments:
3587 @table @code
3588 @item repourl
3589 (required unless @code{baseURL} is provided): the URL at which the
3590 Mercurial source repository is available.
3592 @item baseURL
3593 (required unless @code{repourl} is provided): the base repository URL,
3594 to which a branch name will be appended. It should probably end in a
3595 slash.
3597 @item defaultBranch
3598 (allowed if and only if @code{baseURL} is provided): this specifies
3599 the name of the branch to use when a Build does not provide one of its
3600 own. This will be appended to @code{baseURL} to create the string that
3601 will be passed to the @code{hg clone} command.
3602 @end table
3605 @node Arch, Bazaar, Mercurial, Source Checkout
3606 @subsubsection Arch
3608 @cindex Arch Checkout
3609 @bsindex buildbot.steps.source.Arch
3612 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
3613 Arch} checkout or update using the @code{tla} client. It takes the
3614 following arguments:
3616 @table @code
3617 @item url
3618 (required): this specifies the URL at which the Arch source archive is
3619 available.
3621 @item version
3622 (required): this specifies which ``development line'' (like a branch)
3623 should be used. This provides the default branch name, but individual
3624 builds may specify a different one.
3626 @item archive
3627 (optional): Each repository knows its own archive name. If this
3628 parameter is provided, it must match the repository's archive name.
3629 The parameter is accepted for compatibility with the @code{Bazaar}
3630 step, below.
3632 @end table
3634 @node Bazaar, P4, Arch, Source Checkout
3635 @subsubsection Bazaar
3637 @cindex Bazaar Checkout
3638 @bsindex buildbot.steps.source.Bazaar
3641 @code{Bazaar} is an alternate implementation of the Arch VC system,
3642 which uses a client named @code{baz}. The checkout semantics are just
3643 different enough from @code{tla} that there is a separate BuildStep for
3646 It takes exactly the same arguments as @code{Arch}, except that the
3647 @code{archive=} parameter is required. (baz does not emit the archive
3648 name when you do @code{baz register-archive}, so we must provide it
3649 ourselves).
3652 @node P4,  , Bazaar, Source Checkout
3653 @subsubsection P4
3655 @cindex Perforce Update
3656 @bsindex buildbot.steps.source.P4
3657 @c TODO @bsindex buildbot.steps.source.P4Sync
3660 The @code{P4} build step creates a @uref{http://www.perforce.com/,
3661 Perforce} client specification and performs an update.
3663 @table @code
3664 @item p4base
3665 A view into the Perforce depot without branch name or trailing "...".
3666 Typically "//depot/proj/".
3667 @item defaultBranch
3668 A branch name to append on build requests if none is specified.
3669 Typically "trunk".
3670 @item p4port
3671 (optional): the host:port string describing how to get to the P4 Depot
3672 (repository), used as the -p argument for all p4 commands.
3673 @item p4user
3674 (optional): the Perforce user, used as the -u argument to all p4
3675 commands.
3676 @item p4passwd
3677 (optional): the Perforce password, used as the -p argument to all p4
3678 commands.
3679 @item p4extra_views
3680 (optional): a list of (depotpath, clientpath) tuples containing extra
3681 views to be mapped into the client specification. Both will have
3682 "/..." appended automatically. The client name and source directory
3683 will be prepended to the client path.
3684 @item p4client
3685 (optional): The name of the client to use. In mode='copy' and
3686 mode='update', it's particularly important that a unique name is used
3687 for each checkout directory to avoid incorrect synchronization. For
3688 this reason, Python percent substitution will be performed on this value
3689 to replace %(slave)s with the slave name and %(builder)s with the
3690 builder name. The default is "buildbot_%(slave)s_%(build)s".
3691 @end table
3693 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
3694 @subsection ShellCommand
3696 @bsindex buildbot.steps.shell.ShellCommand
3697 @c TODO @bsindex buildbot.steps.shell.TreeSize
3699 This is a useful base class for just about everything you might want
3700 to do during a build (except for the initial source checkout). It runs
3701 a single command in a child shell on the buildslave. All stdout/stderr
3702 is recorded into a LogFile. The step finishes with a status of FAILURE
3703 if the command's exit code is non-zero, otherwise it has a status of
3704 SUCCESS.
3706 The preferred way to specify the command is with a list of argv strings,
3707 since this allows for spaces in filenames and avoids doing any fragile
3708 shell-escaping. You can also specify the command with a single string, in
3709 which case the string is given to '/bin/sh -c COMMAND' for parsing.
3711 All ShellCommands are run by default in the ``workdir'', which
3712 defaults to the ``@file{build}'' subdirectory of the slave builder's
3713 base directory. The absolute path of the workdir will thus be the
3714 slave's basedir (set as an option to @code{buildbot create-slave},
3715 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
3716 builder's @code{c['builddir']} key in master.cfg) plus the workdir
3717 itself (a class-level attribute of the BuildFactory, defaults to
3718 ``@file{build}'').
3720 @code{ShellCommand} arguments:
3722 @table @code
3723 @item command
3724 a list of strings (preferred) or single string (discouraged) which
3725 specifies the command to be run. A list of strings is preferred
3726 because it can be used directly as an argv array. Using a single
3727 string (with embedded spaces) requires the buildslave to pass the
3728 string to /bin/sh for interpretation, which raises all sorts of
3729 difficult questions about how to escape or interpret shell
3730 metacharacters.
3732 @item env
3733 a dictionary of environment strings which will be added to the child
3734 command's environment. For example, to run tests with a different i18n
3735 language setting, you might use
3737 @example
3738 f.addStep(ShellCommand, command=["make", "test"],
3739           env=@{'LANG': 'fr_FR'@})
3740 @end example
3742 These variable settings will override any existing ones in the
3743 buildslave's environment. The exception is PYTHONPATH, which is merged
3744 with (actually prepended to) any existing $PYTHONPATH setting. The
3745 value is treated as a list of directories to prepend, and a single
3746 string is treated like a one-item list. For example, to prepend both
3747 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
3748 to any existing $PYTHONPATH setting, you would do something like the
3749 following:
3751 @example
3752 f.addStep(ShellCommand, command=["make", "test"],
3753           env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
3754                               "/home/buildbot/lib/python"] @})
3755 @end example
3757 @item want_stdout
3758 if False, stdout from the child process is discarded rather than being
3759 sent to the buildmaster for inclusion in the step's LogFile.
3761 @item want_stderr
3762 like @code{want_stdout} but for stderr. Note that commands run through
3763 a PTY do not have separate stdout/stderr streams: both are merged into
3764 stdout.
3766 @item logfiles
3767 Sometimes commands will log interesting data to a local file, rather
3768 than emitting everything to stdout or stderr. For example, Twisted's
3769 ``trial'' command (which runs unit tests) only presents summary
3770 information to stdout, and puts the rest into a file named
3771 @file{_trial_temp/test.log}. It is often useful to watch these files
3772 as the command runs, rather than using @command{/bin/cat} to dump
3773 their contents afterwards.
3775 The @code{logfiles=} argument allows you to collect data from these
3776 secondary logfiles in near-real-time, as the step is running. It
3777 accepts a dictionary which maps from a local Log name (which is how
3778 the log data is presented in the build results) to a remote filename
3779 (interpreted relative to the build's working directory). Each named
3780 file will be polled on a regular basis (every couple of seconds) as
3781 the build runs, and any new text will be sent over to the buildmaster.
3783 @example
3784 f.addStep(ShellCommand, command=["make", "test"],
3785           logfiles=@{"triallog": "_trial_temp/test.log"@})
3786 @end example
3789 @item timeout
3790 if the command fails to produce any output for this many seconds, it
3791 is assumed to be locked up and will be killed.
3793 @item description
3794 This will be used to describe the command (on the Waterfall display)
3795 while the command is still running. It should be a single
3796 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
3797 form is a list of short strings, which allows the HTML Waterfall
3798 display to create narrower columns by emitting a <br> tag between each
3799 word. You may also provide a single string.
3801 @item descriptionDone
3802 This will be used to describe the command once it has finished. A
3803 simple noun like ``compile'' or ``tests'' should be used. Like
3804 @code{description}, this may either be a list of short strings or a
3805 single string.
3807 If neither @code{description} nor @code{descriptionDone} are set, the
3808 actual command arguments will be used to construct the description.
3809 This may be a bit too wide to fit comfortably on the Waterfall
3810 display.
3812 @example
3813 f.addStep(ShellCommand, command=["make", "test"],
3814           description=["testing"],
3815           descriptionDone=["tests"])
3816 @end example
3818 @end table
3820 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
3821 @subsection Simple ShellCommand Subclasses
3823 Several subclasses of ShellCommand are provided as starting points for
3824 common build steps. These are all very simple: they just override a few
3825 parameters so you don't have to specify them yourself, making the master.cfg
3826 file less verbose.
3828 @menu
3829 * Configure::                   
3830 * Compile::                     
3831 * Test::                        
3832 * Build Properties::            
3833 @end menu
3835 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
3836 @subsubsection Configure
3838 @bsindex buildbot.steps.shell.Configure
3840 This is intended to handle the @code{./configure} step from
3841 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
3842 MakeMaker.pm-style modules. The default command is @code{./configure}
3843 but you can change this by providing a @code{command=} parameter.
3845 @node Compile, Test, Configure, Simple ShellCommand Subclasses
3846 @subsubsection Compile
3848 @bsindex buildbot.steps.shell.Compile
3850 This is meant to handle compiling or building a project written in C. The
3851 default command is @code{make all}. When the compile is finished, the
3852 log file is scanned for GCC error/warning messages and a summary log is
3853 created with any problems that were seen (TODO: the summary is not yet
3854 created).
3856 @node Test, Build Properties, Compile, Simple ShellCommand Subclasses
3857 @subsubsection Test
3859 @bsindex buildbot.steps.shell.Test
3861 This is meant to handle unit tests. The default command is @code{make
3862 test}, and the @code{warnOnFailure} flag is set.
3866 @node Build Properties,  , Test, Simple ShellCommand Subclasses
3867 @subsubsection Build Properties
3869 @cindex build properties
3871 Each build has a set of ``Build Properties'', which can be used by its
3872 BuildStep to modify their actions. For example, the SVN revision
3873 number of the source code being built is available as a build
3874 property, and a ShellCommand step could incorporate this number into a
3875 command which create a numbered release tarball.
3877 Some build properties are set when the build starts, such as the
3878 SourceStamp information. Other properties can be set by BuildSteps as
3879 they run, for example the various Source steps will set the
3880 @code{got_revision} property to the source revision that was actually
3881 checked out (which can be useful when the SourceStamp in use merely
3882 requested the ``latest revision'': @code{got_revision} will tell you
3883 what was actually built).
3885 In custom BuildSteps, you can get and set the build properties with
3886 the @code{getProperty}/@code{setProperty} methods. Each takes a string
3887 for the name of the property, and returns or accepts an
3888 arbitrary@footnote{Build properties are serialized along with the
3889 build results, so they must be serializable. For this reason, the
3890 value of any build property should be simple inert data: strings,
3891 numbers, lists, tuples, and dictionaries. They should not contain
3892 class instances.} object. For example:
3894 @example
3895 class MakeTarball(ShellCommand):
3896     def start(self):
3897         self.setCommand(["tar", "czf",
3898                          "build-%s.tar.gz" % self.getProperty("revision"),
3899                          "source"])
3900         ShellCommand.start(self)
3901 @end example
3903 @cindex WithProperties
3905 You can use build properties in ShellCommands by using the
3906 @code{WithProperties} wrapper when setting the arguments of the
3907 ShellCommand. This interpolates the named build properties into the
3908 generated shell command.
3910 @example
3911 from buildbot.steps.shell import ShellCommand, WithProperties
3913 f.addStep(ShellCommand,
3914           command=["tar", "czf",
3915                    WithProperties("build-%s.tar.gz", "revision"),
3916                    "source"])
3917 @end example
3919 If this BuildStep were used in a tree obtained from Subversion, it
3920 would create a tarball with a name like @file{build-1234.tar.gz}.
3922 The @code{WithProperties} function does @code{printf}-style string
3923 interpolation, using strings obtained by calling
3924 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
3925 @code{%d}, etc), you must have exactly one additional argument to
3926 indicate which build property you want to insert.
3929 You can also use python dictionary-style string interpolation by using
3930 the @code{%(propname)s} syntax. In this form, the property name goes
3931 in the parentheses, and WithProperties takes @emph{no} additional
3932 arguments:
3934 @example
3935 f.addStep(ShellCommand,
3936           command=["tar", "czf",
3937                    WithProperties("build-%(revision)s.tar.gz"),
3938                    "source"])
3939 @end example
3941 Don't forget the extra ``s'' after the closing parenthesis! This is
3942 the cause of many confusing errors.
3944 Note that, like python, you can either do positional-argument
3945 interpolation @emph{or} keyword-argument interpolation, not both. Thus
3946 you cannot use a string like
3947 @code{WithProperties("foo-%(revision)s-%s", "branch")}.
3949 At the moment, the only way to set build properties is by writing a
3950 custom BuildStep.
3952 @heading Common Build Properties
3954 The following build properties are set when the build is started, and
3955 are available to all steps.
3957 @table @code
3958 @item branch
3960 This comes from the build's SourceStamp, and describes which branch is
3961 being checked out. This will be @code{None} (which interpolates into
3962 @code{WithProperties} as an empty string) if the build is on the
3963 default branch, which is generally the trunk. Otherwise it will be a
3964 string like ``branches/beta1.4''. The exact syntax depends upon the VC
3965 system being used.
3967 @item revision
3969 This also comes from the SourceStamp, and is the revision of the
3970 source code tree that was requested from the VC system. When a build
3971 is requested of a specific revision (as is generally the case when the
3972 build is triggered by Changes), this will contain the revision
3973 specification. The syntax depends upon the VC system in use: for SVN
3974 it is an integer, for Mercurial it is a short string, for Darcs it is
3975 a rather large string, etc.
3977 If the ``force build'' button was pressed, the revision will be
3978 @code{None}, which means to use the most recent revision available.
3979 This is a ``trunk build''. This will be interpolated as an empty
3980 string.
3982 @item got_revision
3984 This is set when a Source step checks out the source tree, and
3985 provides the revision that was actually obtained from the VC system.
3986 In general this should be the same as @code{revision}, except for
3987 trunk builds, where @code{got_revision} indicates what revision was
3988 current when the checkout was performed. This can be used to rebuild
3989 the same source code later.
3991 Note that for some VC systems (Darcs in particular), the revision is a
3992 large string containing newlines, and is not suitable for
3993 interpolation into a filename.
3995 @item buildername
3997 This is a string that indicates which Builder the build was a part of.
3998 The combination of buildername and buildnumber uniquely identify a
3999 build.
4001 @item buildnumber
4003 Each build gets a number, scoped to the Builder (so the first build
4004 performed on any given Builder will have a build number of 0). This
4005 integer property contains the build's number.
4007 @item slavename
4009 This is a string which identifies which buildslave the build is
4010 running on.
4012 @end table
4014 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
4015 @subsection Python BuildSteps
4017 Here are some BuildSteps that are specifcally useful for projects
4018 implemented in Python.
4020 @menu
4021 * BuildEPYDoc::                 
4022 * PyFlakes::                    
4023 @end menu
4025 @node BuildEPYDoc, PyFlakes, Python BuildSteps, Python BuildSteps
4026 @subsubsection BuildEPYDoc
4028 @bsindex buildbot.steps.python.BuildEPYDoc
4030 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
4031 API documentation for Python modules from their docstrings. It reads
4032 all the .py files from your source tree, processes the docstrings
4033 therein, and creates a large tree of .html files (or a single .pdf
4034 file).
4036 The @code{buildbot.steps.python.BuildEPYDoc} step will run
4037 @command{epydoc} to produce this API documentation, and will count the
4038 errors and warnings from its output.
4040 You must supply the command line to be used. The default is
4041 @command{make epydocs}, which assumes that your project has a Makefile
4042 with an ``epydocs'' target. You might wish to use something like
4043 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
4044 to add @command{--pdf} to generate a PDF file instead of a large tree
4045 of HTML files.
4047 The API docs are generated in-place in the build tree (under the
4048 workdir, in the subdirectory controlled by the ``-o'' argument). To
4049 make them useful, you will probably have to copy them to somewhere
4050 they can be read. A command like @command{rsync -ad apiref/
4051 dev.example.com:~public_html/current-apiref/} might be useful. You
4052 might instead want to bundle them into a tarball and publish it in the
4053 same place where the generated install tarball is placed.
4055 @example
4056 from buildbot.steps.python import BuildEPYDoc
4059 f.addStep(BuildEPYDoc, command=["epydoc", "-o", "apiref", "source/mypkg"])
4060 @end example
4063 @node PyFlakes,  , BuildEPYDoc, Python BuildSteps
4064 @subsubsection PyFlakes
4066 @bsindex buildbot.steps.python.PyFlakes
4068 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
4069 to perform basic static analysis of Python code to look for simple
4070 errors, like missing imports and references of undefined names. It is
4071 like a fast and simple form of the C ``lint'' program. Other tools
4072 (like pychecker) provide more detailed results but take longer to run.
4074 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
4075 count the various kinds of errors and warnings it detects.
4077 You must supply the command line to be used. The default is
4078 @command{make pyflakes}, which assumes you have a top-level Makefile
4079 with a ``pyflakes'' target. You might want to use something like
4080 @command{pyflakes .} or @command{pyflakes src}.
4082 @example
4083 from buildbot.steps.python import PyFlakes
4086 f.addStep(PyFlakes, command=["pyflakes", "src"])
4087 @end example
4090 @node Transferring Files, Writing New BuildSteps, Python BuildSteps, Build Steps
4091 @subsection Transferring Files
4093 @cindex File Transfer
4094 @bsindex buildbot.steps.transfer.FileUpload
4095 @bsindex buildbot.steps.transfer.FileDownload
4097 Most of the work involved in a build will take place on the
4098 buildslave. But occasionally it is useful to do some work on the
4099 buildmaster side. The most basic way to involve the buildmaster is
4100 simply to move a file from the slave to the master, or vice versa.
4101 There are a pair of BuildSteps named @code{FileUpload} and
4102 @code{FileDownload} to provide this functionality. @code{FileUpload}
4103 moves a file @emph{up to} the master, while @code{FileDownload} moves
4104 a file @emph{down from} the master.
4106 As an example, let's assume that there is a step which produces an
4107 HTML file within the source tree that contains some sort of generated
4108 project documentation. We want to move this file to the buildmaster,
4109 into a @file{~/public_html} directory, so it can be visible to
4110 developers. This file will wind up in the slave-side working directory
4111 under the name @file{docs/reference.html}. We want to put it into the
4112 master-side @file{~/public_html/ref.html}.
4114 @example
4115 from buildbot.steps.shell import ShellCommand
4116 from buildbot.steps.transfer import FileUpload
4118 f.addStep(ShellCommand, command=["make", "docs"])
4119 f.addStep(FileUpload,
4120           slavesrc="docs/reference.html",
4121           masterdest="~/public_html/ref.html")
4122 @end example
4124 The @code{masterdest=} argument will be passed to os.path.expanduser,
4125 so things like ``~'' will be expanded properly. Non-absolute paths
4126 will be interpreted relative to the buildmaster's base directory.
4127 Likewise, the @code{slavesrc=} argument will be expanded and
4128 interpreted relative to the builder's working directory.
4131 To move a file from the master to the slave, use the
4132 @code{FileDownload} command. For example, let's assume that some step
4133 requires a configuration file that, for whatever reason, could not be
4134 recorded in the source code repository or generated on the buildslave
4135 side:
4137 @example
4138 from buildbot.steps.shell import ShellCommand
4139 from buildbot.steps.transfer import FileUpload
4141 f.addStep(FileDownload
4142           mastersrc="~/todays_build_config.txt",
4143           slavedest="build_config.txt")
4144 f.addStep(ShellCommand, command=["make", "config"])
4145 @end example
4147 @c TODO: document other parameters
4150 @node Writing New BuildSteps,  , Transferring Files, Build Steps
4151 @subsection Writing New BuildSteps
4153 While it is a good idea to keep your build process self-contained in
4154 the source code tree, sometimes it is convenient to put more
4155 intelligence into your Buildbot configuration. One was to do this is
4156 to write a custom BuildStep. Once written, this Step can be used in
4157 the @file{master.cfg} file.
4159 The best reason for writing a custom BuildStep is to better parse the
4160 results of the command being run. For example, a BuildStep that knows
4161 about JUnit could look at the logfiles to determine which tests had
4162 been run, how many passed and how many failed, and then report more
4163 detailed information than a simple @code{rc==0} -based ``good/bad''
4164 decision.
4166 TODO: add more description of BuildSteps.
4168 @menu
4169 * BuildStep LogFiles::          
4170 * Adding LogObservers::         
4171 * BuildStep URLs::              
4172 @end menu
4174 @node BuildStep LogFiles, Adding LogObservers, Writing New BuildSteps, Writing New BuildSteps
4175 @subsubsection BuildStep LogFiles
4177 Each BuildStep has a collection of ``logfiles''. Each one has a short
4178 name, like ``stdio'' or ``warnings''. Each LogFile contains an
4179 arbitrary amount of text, usually the contents of some output file
4180 generated during a build or test step, or a record of everything that
4181 was printed to stdout/stderr during the execution of some command.
4183 These LogFiles are stored to disk, so they can be retrieved later.
4185 Each can contain multiple ``channels'', generally limited to three
4186 basic ones: stdout, stderr, and ``headers''. For example, when a
4187 ShellCommand runs, it writes a few lines to the ``headers'' channel to
4188 indicate the exact argv strings being run, which directory the command
4189 is being executed in, and the contents of the current environment
4190 variables. Then, as the command runs, it adds a lot of ``stdout'' and
4191 ``stderr'' messages. When the command finishes, a final ``header''
4192 line is added with the exit code of the process.
4194 Status display plugins can format these different channels in
4195 different ways. For example, the web page shows LogFiles as text/html,
4196 with header lines in blue text, stdout in black, and stderr in red. A
4197 different URL is available which provides a text/plain format, in
4198 which stdout and stderr are collapsed together, and header lines are
4199 stripped completely. This latter option makes it easy to save the
4200 results to a file and run @command{grep} or whatever against the
4201 output.
4203 Each BuildStep contains a mapping (implemented in a python dictionary)
4204 from LogFile name to the actual LogFile objects. Status plugins can
4205 get a list of LogFiles to display, for example, a list of HREF links
4206 that, when clicked, provide the full contents of the LogFile.
4208 @heading Using LogFiles in custom BuildSteps
4210 The most common way for a custom BuildStep to use a LogFile is to
4211 summarize the results of a ShellCommand (after the command has
4212 finished running). For example, a compile step with thousands of lines
4213 of output might want to create a summary of just the warning messages.
4214 If you were doing this from a shell, you would use something like:
4216 @example
4217 grep "warning:" output.log >warnings.log
4218 @end example
4220 In a custom BuildStep, you could instead create a ``warnings'' LogFile
4221 that contained the same text. To do this, you would add code to your
4222 @code{createSummary} method that pulls lines from the main output log
4223 and creates a new LogFile with the results:
4225 @example
4226     def createSummary(self, log):
4227         warnings = []
4228         for line in log.readlines():
4229             if "warning:" in line:
4230                 warnings.append()
4231         self.addCompleteLog('warnings', "".join(warnings))
4232 @end example
4234 This example uses the @code{addCompleteLog} method, which creates a
4235 new LogFile, puts some text in it, and then ``closes'' it, meaning
4236 that no further contents will be added. This LogFile will appear in
4237 the HTML display under an HREF with the name ``warnings'', since that
4238 is the name of the LogFile.
4240 You can also use @code{addHTMLLog} to create a complete (closed)
4241 LogFile that contains HTML instead of plain text. The normal LogFile
4242 will be HTML-escaped if presented through a web page, but the HTML
4243 LogFile will not. At the moment this is only used to present a pretty
4244 HTML representation of an otherwise ugly exception traceback when
4245 something goes badly wrong during the BuildStep.
4247 In contrast, you might want to create a new LogFile at the beginning
4248 of the step, and add text to it as the command runs. You can create
4249 the LogFile and attach it to the build by calling @code{addLog}, which
4250 returns the LogFile object. You then add text to this LogFile by
4251 calling methods like @code{addStdout} and @code{addHeader}. When you
4252 are done, you must call the @code{finish} method so the LogFile can be
4253 closed. It may be useful to create and populate a LogFile like this
4254 from a LogObserver method @xref{Adding LogObservers}.
4256 The @code{logfiles=} argument to @code{ShellCommand} (see
4257 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
4258 by asking the buildslave to watch a actual file on disk. The
4259 buildslave will look for additions in the target file and report them
4260 back to the BuildStep. These additions will be added to the LogFile by
4261 calling @code{addStdout}. These secondary LogFiles can be used as the
4262 source of a LogObserver just like the normal ``stdio'' LogFile.
4265 @node Adding LogObservers, BuildStep URLs, BuildStep LogFiles, Writing New BuildSteps
4266 @subsubsection Adding LogObservers
4268 @cindex LogObserver
4269 @cindex LogLineObserver
4271 Most shell commands emit messages to stdout or stderr as they operate,
4272 especially if you ask them nicely with a @code{--verbose} flag of some
4273 sort. They may also write text to a log file while they run. Your
4274 BuildStep can watch this output as it arrives, to keep track of how
4275 much progress the command has made. You can get a better measure of
4276 progress by counting the number of source files compiled or test cases
4277 run than by merely tracking the number of bytes that have been written
4278 to stdout. This improves the accuracy and the smoothness of the ETA
4279 display.
4281 To accomplish this, you will need to attach a @code{LogObserver} to
4282 one of the log channels, most commonly to the ``stdio'' channel but
4283 perhaps to another one which tracks a log file. This observer is given
4284 all text as it is emitted from the command, and has the opportunity to
4285 parse that output incrementally. Once the observer has decided that
4286 some event has occurred (like a source file being compiled), it can
4287 use the @code{setProgress} method to tell the BuildStep about the
4288 progress that this event represents.
4290 There are a number of pre-built @code{LogObserver} classes that you
4291 can choose from (defined in @code{buildbot.process.buildstep}, and of
4292 course you can subclass them to add further customization. The
4293 @code{LogLineObserver} class handles the grunt work of buffering and
4294 scanning for end-of-line delimiters, allowing your parser to operate
4295 on complete stdout/stderr lines.
4297 For example, let's take a look at the @code{TrialTestCaseCounter},
4298 which is used by the Trial step to count test cases as they are run.
4299 As Trial executes, it emits lines like the following:
4301 @example
4302 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
4303 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
4304 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
4305 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
4306 @end example
4308 When the tests are finished, trial emits a long line of ``======'' and
4309 then some lines which summarize the tests that failed. We want to
4310 avoid parsing these trailing lines, because their format is less
4311 well-defined than the ``[OK]'' lines.
4313 The parser class looks like this:
4315 @example
4316 from buildbot.process.buildstep import LogLineObserver
4318 class TrialTestCaseCounter(LogLineObserver):
4319     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
4320     numTests = 0
4321     finished = False
4323     def outLineReceived(self, line):
4324         if self.finished:
4325             return
4326         if line.startswith("=" * 40):
4327             self.finished = True
4328             return
4330         m = self._line_re.search(line.strip())
4331         if m:
4332             testname, result = m.groups()
4333             self.numTests += 1
4334             self.step.setProgress('tests', self.numTests)
4335 @end example
4337 This parser only pays attention to stdout, since that's where trial
4338 writes the progress lines. It has a mode flag named @code{finished} to
4339 ignore everything after the ``===='' marker, and a scary-looking
4340 regular expression to match each line while hopefully ignoring other
4341 messages that might get displayed as the test runs.
4343 Each time it identifies a test has been completed, it increments its
4344 counter and delivers the new progress value to the step with
4345 @code{self.step.setProgress}. This class is specifically measuring
4346 progress along the ``tests'' metric, in units of test cases (as
4347 opposed to other kinds of progress like the ``output'' metric, which
4348 measures in units of bytes). The Progress-tracking code uses each
4349 progress metric separately to come up with an overall completion
4350 percentage and an ETA value.
4352 To connect this parser into the @code{Trial} BuildStep,
4353 @code{Trial.__init__} ends with the following clause:
4355 @example
4356         # this counter will feed Progress along the 'test cases' metric
4357         counter = TrialTestCaseCounter()
4358         self.addLogObserver('stdio', counter)
4359 @end example
4361 This creates a TrialTestCaseCounter and tells the step that the
4362 counter wants to watch the ``stdio'' log. The observer is
4363 automatically given a reference to the step in its @code{.step}
4364 attribute.
4366 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
4367 @subsubsection BuildStep URLs
4369 @cindex links
4370 @cindex BuildStep URLs
4371 @cindex addURL
4373 Each BuildStep has a collection of ``links''. Like its collection of
4374 LogFiles, each link has a name and a target URL. The web status page
4375 creates HREFs for each link in the same box as it does for LogFiles,
4376 except that the target of the link is the external URL instead of an
4377 internal link to a page that shows the contents of the LogFile.
4379 These external links can be used to point at build information hosted
4380 on other servers. For example, the test process might produce an
4381 intricate description of which tests passed and failed, or some sort
4382 of code coverage data in HTML form, or a PNG or GIF image with a graph
4383 of memory usage over time. The external link can provide an easy way
4384 for users to navigate from the buildbot's status page to these
4385 external web sites or file servers. Note that the step itself is
4386 responsible for insuring that there will be a document available at
4387 the given URL (perhaps by using @command{scp} to copy the HTML output
4388 to a @file{~/public_html/} directory on a remote web server). Calling
4389 @code{addURL} does not magically populate a web server.
4391 To set one of these links, the BuildStep should call the @code{addURL}
4392 method with the name of the link and the target URL. Multiple URLs can
4393 be set.
4395 In this example, we assume that the @command{make test} command causes
4396 a collection of HTML files to be created and put somewhere on the
4397 coverage.example.org web server, in a filename that incorporates the
4398 build number.
4400 @example
4401 class TestWithCodeCoverage(BuildStep):
4402     command = ["make", "test",
4403                WithProperties("buildnum=%s" % "buildnumber")]
4405     def createSummary(self, log):
4406         buildnumber = self.getProperty("buildnumber")
4407         url = "http://coverage.example.org/builds/%s.html" % buildnumber
4408         self.addURL("coverage", url)
4409 @end example
4411 You might also want to extract the URL from some special message
4412 output by the build process itself:
4414 @example
4415 class TestWithCodeCoverage(BuildStep):
4416     command = ["make", "test",
4417                WithProperties("buildnum=%s" % "buildnumber")]
4419     def createSummary(self, log):
4420         output = StringIO(log.getText())
4421         for line in output.readlines():
4422             if line.startswith("coverage-url:"):
4423                 url = line[len("coverage-url:"):].strip()
4424                 self.addURL("coverage", url)
4425                 return
4426 @end example
4428 Note that a build process which emits both stdout and stderr might
4429 cause this line to be split or interleaved between other lines. It
4430 might be necessary to restrict the getText() call to only stdout with
4431 something like this:
4433 @example
4434         output = StringIO("".join([c[1]
4435                                    for c in log.getChunks()
4436                                    if c[0] == LOG_CHANNEL_STDOUT]))
4437 @end example
4439 Of course if the build is run under a PTY, then stdout and stderr will
4440 be merged before the buildbot ever sees them, so such interleaving
4441 will be unavoidable.
4444 @node Interlocks, Build Factories, Build Steps, Build Process
4445 @section Interlocks
4447 @cindex locks
4448 @slindex buildbot.locks.MasterLock
4449 @slindex buildbot.locks.SlaveLock
4451 For various reasons, you may want to prevent certain Steps (or perhaps
4452 entire Builds) from running simultaneously. Limited CPU speed or
4453 network bandwidth to the VC server, problems with simultaneous access
4454 to a database server used by unit tests, or multiple Builds which
4455 access shared state may all require some kind of interlock to prevent
4456 corruption, confusion, or resource overload. These resources might
4457 require completely exclusive access, or it might be sufficient to
4458 establish a limit of two or three simultaneous builds.
4460 @code{Locks} are the mechanism used to express these kinds of
4461 constraints on when Builds or Steps can be run. There are two kinds of
4462 @code{Locks}, each with their own scope: @code{MasterLock} instances
4463 are scoped to the buildbot as a whole, while @code{SlaveLock}s are
4464 scoped to a single buildslave. This means that each buildslave has a
4465 separate copy of each @code{SlaveLock}, which could enforce a
4466 one-Build-at-a-time limit for each machine, but still allow as many
4467 simultaneous builds as there are machines.
4469 Each @code{Lock} is created with a unique name. Each lock gets a count
4470 of how many owners it may have: how many processes can claim it at ths
4471 same time. This limit defaults to one, and is controllable through the
4472 @code{maxCount} argument. On @code{SlaveLock}s you can set the owner
4473 count on a per-slave basis by providing a dictionary (that maps from
4474 slavename to maximum owner count) to its @code{maxCountForSlave}
4475 argument. Any buildslaves that aren't mentioned in
4476 @code{maxCountForSlave} get their owner count from @code{maxCount}.
4478 To use a lock, simply include it in the @code{locks=} argument of the
4479 @code{BuildStep} object that should obtain the lock before it runs.
4480 This argument accepts a list of @code{Lock} objects: the Step will
4481 acquire all of them before it runs.
4483 To claim a lock for the whole Build, add a @code{'locks'} key to the
4484 builder specification dictionary with the same list of @code{Lock}
4485 objects. (This is the dictionary that has the @code{'name'},
4486 @code{'slavename'}, @code{'builddir'}, and @code{'factory'} keys). The
4487 @code{Build} object also accepts a @code{locks=} argument, but unless
4488 you are writing your own @code{BuildFactory} subclass then it will be
4489 easier to set the locks in the builder dictionary.
4491 Note that there are no partial-acquire or partial-release semantics:
4492 this prevents deadlocks caused by two Steps each waiting for a lock
4493 held by the other@footnote{Also note that a clever buildmaster admin
4494 could still create the opportunity for deadlock: Build A obtains Lock
4495 1, inside which Step A.two tries to acquire Lock 2 at the Step level.
4496 Meanwhile Build B obtains Lock 2, and has a Step B.two which wants to
4497 acquire Lock 1 at the Step level. Don't Do That.}. This also means
4498 that waiting to acquire a @code{Lock} can take an arbitrarily long
4499 time: if the buildmaster is very busy, a Step or Build which requires
4500 only one @code{Lock} may starve another that is waiting for that
4501 @code{Lock} plus some others.
4504 In the following example, we run the same build on three different
4505 platforms. The unit-test steps of these builds all use a common
4506 database server, and would interfere with each other if allowed to run
4507 simultaneously. The @code{Lock} prevents more than one of these builds
4508 from happening at the same time.
4510 @example
4511 from buildbot import locks
4512 from buildbot.steps import source, shell
4513 from buildbot.process import factory
4515 db_lock = locks.MasterLock("database")
4516 f = factory.BuildFactory()
4517 f.addStep(source.SVN, svnurl="http://example.org/svn/Trunk")
4518 f.addStep(shell.ShellCommand, command="make all")
4519 f.addStep(shell.ShellCommand, command="make test", locks=[db_lock])
4520 b1 = @{'name': 'full1', 'slavename': 'bot-1', builddir='f1', 'factory': f@}
4521 b2 = @{'name': 'full2', 'slavename': 'bot-2', builddir='f2', 'factory': f@}
4522 b3 = @{'name': 'full3', 'slavename': 'bot-3', builddir='f3', 'factory': f@}
4523 c['builders'] = [b1, b2, b3]
4524 @end example
4526 In the next example, we have one buildslave hosting three separate
4527 Builders (each running tests against a different version of Python).
4528 The machine which hosts this buildslave is not particularly fast, so
4529 we want to prevent all three builds from all happening at the same
4530 time. (Assume we've experimentally determined that one build leaves
4531 unused CPU capacity, three builds causes a lot of disk thrashing, but
4532 two builds at a time is Just Right). We use a @code{SlaveLock} because
4533 the builds happening on this one slow slave should not affect builds
4534 running on other slaves, and we use the lock on the build as a whole
4535 because the slave is so slow that even multiple simultaneous SVN
4536 checkouts would be too taxing. We set @code{maxCount=2} to achieve our
4537 goal of two simultaneous builds per slave.
4539 @example
4540 from buildbot import locks
4541 from buildbot.steps import source
4542 from buildbot.process import s, factory
4544 slow_lock = locks.SlaveLock("cpu", maxCount=2)
4545 source = s(source.SVN, svnurl="http://example.org/svn/Trunk")
4546 f22 = factory.Trial(source, trialpython=["python2.2"])
4547 f23 = factory.Trial(source, trialpython=["python2.3"])
4548 f24 = factory.Trial(source, trialpython=["python2.4"])
4549 b1 = @{'name': 'p22', 'slavename': 'bot-1', builddir='p22', 'factory': f22,
4550       'locks': [slow_lock] @}
4551 b2 = @{'name': 'p23', 'slavename': 'bot-1', builddir='p23', 'factory': f23,
4552       'locks': [slow_lock] @}
4553 b3 = @{'name': 'p24', 'slavename': 'bot-1', builddir='p24', 'factory': f24,
4554       'locks': [slow_lock] @}
4555 c['builders'] = [b1, b2, b3]
4556 @end example
4558 In the last example, we use two Locks at the same time. In this case,
4559 we're concerned about both of the previous constraints, but we'll say
4560 that only the tests are computationally intensive, and that they have
4561 been split into those which use the database and those which do not.
4562 In addition, two of the Builds run on a fast machine which does not
4563 need to worry about the cpu lock, but which still must be prevented
4564 from simultaneous database access. We use @code{maxCountForSlave} to
4565 limit the slow machine to one simultanous build, but allow practically
4566 unlimited concurrent builds on the fast machine.
4568 @example
4569 from buildbot import locks
4570 from buildbot.steps import source, shell
4571 from buildbot.process import factory
4573 db_lock = locks.MasterLock("database")
4574 slavecounts = @{"bot-slow": 1, "bot-fast": 100@}
4575 cpu_lock = locks.SlaveLock("cpu", maxCountForSlave=slavecounts)
4576 f = factory.BuildFactory()
4577 f.addStep(source.SVN, svnurl="http://example.org/svn/Trunk")
4578 f.addStep(shell.ShellCommand, command="make all", locks=[cpu_lock])
4579 f.addStep(shell.ShellCommand, command="make test", locks=[cpu_lock])
4580 f.addStep(shell.ShellCommand, command="make db-test",
4581                               locks=[db_lock, cpu_lock])
4583 b1 = @{'name': 'full1', 'slavename': 'bot-slow', builddir='full1',
4584       'factory': f@}
4585 b2 = @{'name': 'full2', 'slavename': 'bot-slow', builddir='full2',
4586       'factory': f@}
4587 b3 = @{'name': 'full3', 'slavename': 'bot-fast', builddir='full3',
4588       'factory': f@}
4589 b4 = @{'name': 'full4', 'slavename': 'bot-fast', builddir='full4',
4590       'factory': f@}
4591 c['builders'] = [b1, b2, b3, b4]
4592 @end example
4594 As a final note, remember that a unit test system which breaks when
4595 multiple people run it at the same time is fragile and should be
4596 fixed. Asking your human developers to serialize themselves when
4597 running unit tests will just discourage them from running the unit
4598 tests at all. Find a way to fix this: change the database tests to
4599 create a new (uniquely-named) user or table for each test run, don't
4600 use fixed listening TCP ports for network tests (instead listen on
4601 port 0 to let the kernel choose a port for you and then query the
4602 socket to find out what port was allocated). @code{MasterLock}s can be
4603 used to accomodate broken test systems like this, but are really
4604 intended for other purposes: build processes that store or retrieve
4605 products in shared directories, or which do things that human
4606 developers would not (or which might slow down or break in ways that
4607 require human attention to deal with).
4609 @code{SlaveLocks}s can be used to keep automated performance tests
4610 from interfering with each other, when there are multiple Builders all
4611 using the same buildslave. But they can't prevent other users from
4612 running CPU-intensive jobs on that host while the tests are running.
4614 @node Build Factories,  , Interlocks, Build Process
4615 @section Build Factories
4618 Each Builder is equipped with a ``build factory'', which is
4619 responsible for producing the actual @code{Build} objects that perform
4620 each build. This factory is created in the configuration file, and
4621 attached to a Builder through the @code{factory} element of its
4622 dictionary.
4624 The standard @code{BuildFactory} object creates @code{Build} objects
4625 by default. These Builds will each execute a collection of BuildSteps
4626 in a fixed sequence. Each step can affect the results of the build,
4627 but in general there is little intelligence to tie the different steps
4628 together. You can create subclasses of @code{Build} to implement more
4629 sophisticated build processes, and then use a subclass of
4630 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
4631 create instances of your new Build subclass.
4634 @menu
4635 * BuildStep Objects::           
4636 * BuildFactory::                
4637 * Process-Specific build factories::  
4638 @end menu
4640 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
4641 @subsection BuildStep Objects
4643 The steps used by these builds are all subclasses of @code{BuildStep}.
4644 The standard ones provided with Buildbot are documented later,
4645 @xref{Build Steps}. You can also write your own subclasses to use in
4646 builds.
4648 The basic behavior for a @code{BuildStep} is to:
4650 @itemize @bullet
4651 @item
4652 run for a while, then stop
4653 @item
4654 possibly invoke some RemoteCommands on the attached build slave
4655 @item
4656 possibly produce a set of log files
4657 @item
4658 finish with a status described by one of four values defined in
4659 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
4660 @item
4661 provide a list of short strings to describe the step
4662 @item
4663 define a color (generally green, orange, or red) with which the
4664 step should be displayed
4665 @end itemize
4668 More sophisticated steps may produce additional information and
4669 provide it to later build steps, or store it in the factory to provide
4670 to later builds.
4673 @menu
4674 * BuildFactory Attributes::     
4675 * Quick builds::                
4676 @end menu
4678 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
4679 @subsection BuildFactory
4681 @bfindex buildbot.process.factory.BuildFactory
4682 @bfindex buildbot.process.factory.BasicBuildFactory
4683 @c TODO: what is BasicSVN anyway?
4684 @bfindex buildbot.process.factory.BasicSVN
4686 The default @code{BuildFactory}, provided in the
4687 @code{buildbot.process.factory} module, contains a list of ``BuildStep
4688 specifications'': a list of @code{(step_class, kwargs)} tuples for
4689 each. When asked to create a Build, it loads the list of steps into
4690 the new Build object. When the Build is actually started, these step
4691 specifications are used to create the actual set of BuildSteps, which
4692 are then executed one at a time. For example, a build which consists
4693 of a CVS checkout followed by a @code{make build} would be constructed
4694 as follows:
4696 @example
4697 from buildbot.steps import source, shell
4698 from buildbot.process import factory
4700 f = factory.BuildFactory()
4701 f.addStep(source.CVS, cvsroot=CVSROOT, cvsmodule="project", mode="update")
4702 f.addStep(shell.Compile, command=["make", "build"])
4703 @end example
4705 It is also possible to pass a list of step specifications into the
4706 @code{BuildFactory} when it is created. Using @code{addStep} is
4707 usually simpler, but there are cases where is is more convenient to
4708 create the list of steps ahead of time. To make this approach easier,
4709 a convenience function named @code{s} is available:
4711 @example
4712 from buildbot.steps import source, shell
4713 from buildbot.process import factory
4714 from buildbot.factory import s
4715 # s is a convenience function, defined with:
4716 # def s(steptype, **kwargs): return (steptype, kwargs)
4718 all_steps = [s(source.CVS, cvsroot=CVSROOT, cvsmodule="project",
4719                mode="update"),
4720              s(shell.Compile, command=["make", "build"]),
4721             ]
4722 f = factory.BuildFactory(all_steps)
4723 @end example
4726 Each step can affect the build process in the following ways:
4728 @itemize @bullet
4729 @item
4730 If the step's @code{haltOnFailure} attribute is True, then a failure
4731 in the step (i.e. if it completes with a result of FAILURE) will cause
4732 the whole build to be terminated immediately: no further steps will be
4733 executed. This is useful for setup steps upon which the rest of the
4734 build depends: if the CVS checkout or @code{./configure} process
4735 fails, there is no point in trying to compile or test the resulting
4736 tree.
4738 @item
4739 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
4740 then a result of FAILURE or WARNINGS will mark the build as a whole as
4741 FAILED. However, the remaining steps will still be executed. This is
4742 appropriate for things like multiple testing steps: a failure in any
4743 one of them will indicate that the build has failed, however it is
4744 still useful to run them all to completion.
4746 @item
4747 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
4748 is set, then a result of FAILURE or WARNINGS will mark the build as
4749 having WARNINGS, and the remaining steps will still be executed. This
4750 may be appropriate for certain kinds of optional build or test steps.
4751 For example, a failure experienced while building documentation files
4752 should be made visible with a WARNINGS result but not be serious
4753 enough to warrant marking the whole build with a FAILURE.
4755 @end itemize
4757 In addition, each Step produces its own results, may create logfiles,
4758 etc. However only the flags described above have any effect on the
4759 build as a whole.
4761 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
4762 reasonably appropriate flags set on them already. For example, without
4763 a source tree there is no point in continuing the build, so the
4764 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
4765 in @file{buildbot/process/step.py} to see how the other Steps are
4766 marked.
4768 Each Step is created with an additional @code{workdir} argument that
4769 indicates where its actions should take place. This is specified as a
4770 subdirectory of the slave builder's base directory, with a default
4771 value of @code{build}. This is only implemented as a step argument (as
4772 opposed to simply being a part of the base directory) because the
4773 CVS/SVN steps need to perform their checkouts from the parent
4774 directory.
4776 @menu
4777 * BuildFactory Attributes::     
4778 * Quick builds::                
4779 @end menu
4781 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
4782 @subsubsection BuildFactory Attributes
4784 Some attributes from the BuildFactory are copied into each Build.
4786 @cindex treeStableTimer
4788 @table @code
4789 @item useProgress
4790 (defaults to True): if True, the buildmaster keeps track of how long
4791 each step takes, so it can provide estimates of how long future builds
4792 will take. If builds are not expected to take a consistent amount of
4793 time (such as incremental builds in which a random set of files are
4794 recompiled or tested each time), this should be set to False to
4795 inhibit progress-tracking.
4797 @end table
4800 @node Quick builds,  , BuildFactory Attributes, BuildFactory
4801 @subsubsection Quick builds
4803 @bfindex buildbot.process.factory.QuickBuildFactory
4805 The difference between a ``full build'' and a ``quick build'' is that
4806 quick builds are generally done incrementally, starting with the tree
4807 where the previous build was performed. That simply means that the
4808 source-checkout step should be given a @code{mode='update'} flag, to
4809 do the source update in-place.
4811 In addition to that, the @code{useProgress} flag should be set to
4812 False. Incremental builds will (or at least the ought to) compile as
4813 few files as necessary, so they will take an unpredictable amount of
4814 time to run. Therefore it would be misleading to claim to predict how
4815 long the build will take.
4818 @node Process-Specific build factories,  , BuildFactory, Build Factories
4819 @subsection Process-Specific build factories
4821 Many projects use one of a few popular build frameworks to simplify
4822 the creation and maintenance of Makefiles or other compilation
4823 structures. Buildbot provides several pre-configured BuildFactory
4824 subclasses which let you build these projects with a minimum of fuss.
4826 @menu
4827 * GNUAutoconf::                 
4828 * CPAN::                        
4829 * Python distutils::            
4830 * Python/Twisted/trial projects::  
4831 @end menu
4833 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
4834 @subsubsection GNUAutoconf
4836 @bfindex buildbot.process.factory.GNUAutoconf
4838 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
4839 software portability tool, intended to make it possible to write
4840 programs in C (and other languages) which will run on a variety of
4841 UNIX-like systems. Most GNU software is built using autoconf. It is
4842 frequently used in combination with GNU automake. These tools both
4843 encourage a build process which usually looks like this:
4845 @example
4846 % CONFIG_ENV=foo ./configure --with-flags
4847 % make all
4848 % make check
4849 # make install
4850 @end example
4852 (except of course the Buildbot always skips the @code{make install}
4853 part).
4855 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
4856 designed to build projects which use GNU autoconf and/or automake. The
4857 configuration environment variables, the configure flags, and command
4858 lines used for the compile and test are all configurable, in general
4859 the default values will be suitable.
4861 Example:
4863 @example
4864 # use the s() convenience function defined earlier
4865 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
4866                         flags=["--disable-nls"])
4867 @end example
4869 Required Arguments:
4871 @table @code
4872 @item source
4873 This argument must be a step specification tuple that provides a
4874 BuildStep to generate the source tree.
4875 @end table
4877 Optional Arguments:
4879 @table @code
4880 @item configure
4881 The command used to configure the tree. Defaults to
4882 @code{./configure}. Accepts either a string or a list of shell argv
4883 elements.
4885 @item configureEnv
4886 The environment used for the initial configuration step. This accepts
4887 a dictionary which will be merged into the buildslave's normal
4888 environment. This is commonly used to provide things like
4889 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
4890 Defaults to an empty dictionary.
4892 @item configureFlags
4893 A list of flags to be appended to the argument list of the configure
4894 command. This is commonly used to enable or disable specific features
4895 of the autoconf-controlled package, like @code{["--without-x"]} to
4896 disable windowing support. Defaults to an empty list.
4898 @item compile
4899 this is a shell command or list of argv values which is used to
4900 actually compile the tree. It defaults to @code{make all}. If set to
4901 None, the compile step is skipped.
4903 @item test
4904 this is a shell command or list of argv values which is used to run
4905 the tree's self-tests. It defaults to @code{make check}. If set to
4906 None, the test step is skipped.
4908 @end table
4911 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
4912 @subsubsection CPAN
4914 @bfindex buildbot.process.factory.CPAN
4916 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
4917 archive use the @code{MakeMaker} module to provide configuration,
4918 build, and test services. The standard build routine for these modules
4919 looks like:
4921 @example
4922 % perl Makefile.PL
4923 % make
4924 % make test
4925 # make install
4926 @end example
4928 (except again Buildbot skips the install step)
4930 Buildbot provides a @code{CPAN} factory to compile and test these
4931 projects.
4934 Arguments:
4935 @table @code
4936 @item source
4937 (required): A step specification tuple, that that used by GNUAutoconf.
4939 @item perl
4940 A string which specifies the @code{perl} executable to use. Defaults
4941 to just @code{perl}.
4943 @end table
4946 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
4947 @subsubsection Python distutils
4949 @bfindex buildbot.process.factory.Distutils
4951 Most Python modules use the @code{distutils} package to provide
4952 configuration and build services. The standard build process looks
4953 like:
4955 @example
4956 % python ./setup.py build
4957 % python ./setup.py install
4958 @end example
4960 Unfortunately, although Python provides a standard unit-test framework
4961 named @code{unittest}, to the best of my knowledge @code{distutils}
4962 does not provide a standardized target to run such unit tests. (please
4963 let me know if I'm wrong, and I will update this factory).
4965 The @code{Distutils} factory provides support for running the build
4966 part of this process. It accepts the same @code{source=} parameter as
4967 the other build factories.
4970 Arguments:
4971 @table @code
4972 @item source
4973 (required): A step specification tuple, that that used by GNUAutoconf.
4974   
4975 @item python
4976 A string which specifies the @code{python} executable to use. Defaults
4977 to just @code{python}.
4979 @item test
4980 Provides a shell command which runs unit tests. This accepts either a
4981 string or a list. The default value is None, which disables the test
4982 step (since there is no common default command to run unit tests in
4983 distutils modules).
4985 @end table
4988 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
4989 @subsubsection Python/Twisted/trial projects
4991 @bfindex buildbot.process.factory.Trial
4992 @c TODO: document these steps better
4993 @bsindex buildbot.steps.python_twisted.HLint
4994 @bsindex buildbot.steps.python_twisted.Trial
4995 @bsindex buildbot.steps.python_twisted.ProcessDocs
4996 @bsindex buildbot.steps.python_twisted.BuildDebs
4997 @bsindex buildbot.steps.python_twisted.RemovePYCs
4999 Twisted provides a unit test tool named @code{trial} which provides a
5000 few improvements over Python's built-in @code{unittest} module. Many
5001 python projects which use Twisted for their networking or application
5002 services also use trial for their unit tests. These modules are
5003 usually built and tested with something like the following:
5005 @example
5006 % python ./setup.py build
5007 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
5008 % python ./setup.py install
5009 @end example
5011 Unfortunately, the @file{build/lib} directory into which the
5012 built/copied .py files are placed is actually architecture-dependent,
5013 and I do not yet know of a simple way to calculate its value. For many
5014 projects it is sufficient to import their libraries ``in place'' from
5015 the tree's base directory (@code{PYTHONPATH=.}).
5017 In addition, the @var{PROJECTNAME} value where the test files are
5018 located is project-dependent: it is usually just the project's
5019 top-level library directory, as common practice suggests the unit test
5020 files are put in the @code{test} sub-module. This value cannot be
5021 guessed, the @code{Trial} class must be told where to find the test
5022 files.
5024 The @code{Trial} class provides support for building and testing
5025 projects which use distutils and trial. If the test module name is
5026 specified, trial will be invoked. The library path used for testing
5027 can also be set.
5029 One advantage of trial is that the Buildbot happens to know how to
5030 parse trial output, letting it identify which tests passed and which
5031 ones failed. The Buildbot can then provide fine-grained reports about
5032 how many tests have failed, when individual tests fail when they had
5033 been passing previously, etc.
5035 Another feature of trial is that you can give it a series of source
5036 .py files, and it will search them for special @code{test-case-name}
5037 tags that indicate which test cases provide coverage for that file.
5038 Trial can then run just the appropriate tests. This is useful for
5039 quick builds, where you want to only run the test cases that cover the
5040 changed functionality.
5042 Arguments:
5043 @table @code
5044 @item source
5045 (required): A step specification tuple, like that used by GNUAutoconf.
5047 @item buildpython
5048 A list (argv array) of strings which specifies the @code{python}
5049 executable to use when building the package. Defaults to just
5050 @code{['python']}. It may be useful to add flags here, to supress
5051 warnings during compilation of extension modules. This list is
5052 extended with @code{['./setup.py', 'build']} and then executed in a
5053 ShellCommand.
5055 @item testpath
5056 Provides a directory to add to @code{PYTHONPATH} when running the unit
5057 tests, if tests are being run. Defaults to @code{.} to include the
5058 project files in-place. The generated build library is frequently
5059 architecture-dependent, but may simply be @file{build/lib} for
5060 pure-python modules.
5062 @item trialpython
5063 Another list of strings used to build the command that actually runs
5064 trial. This is prepended to the contents of the @code{trial} argument
5065 below. It may be useful to add @code{-W} flags here to supress
5066 warnings that occur while tests are being run. Defaults to an empty
5067 list, meaning @code{trial} will be run without an explicit
5068 interpreter, which is generally what you want if you're using
5069 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
5070 lives in the Twisted source tree.
5072 @item trial
5073 provides the name of the @code{trial} command. It is occasionally
5074 useful to use an alternate executable, such as @code{trial2.2} which
5075 might run the tests under an older version of Python. Defaults to
5076 @code{trial}.
5078 @item tests
5079 Provides a module name or names which contain the unit tests for this
5080 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
5081 list of strings. Defaults to None, indicating that no tests should be
5082 run. You must either set this or @code{useTestCaseNames} to do anyting
5083 useful with the Trial factory.
5085 @item useTestCaseNames
5086 Tells the Step to provide the names of all changed .py files to trial,
5087 so it can look for test-case-name tags and run just the matching test
5088 cases. Suitable for use in quick builds. Defaults to False.
5090 @item randomly
5091 If @code{True}, tells Trial (with the @code{--random=0} argument) to
5092 run the test cases in random order, which sometimes catches subtle
5093 inter-test dependency bugs. Defaults to @code{False}.
5095 @item recurse
5096 If @code{True}, tells Trial (with the @code{--recurse} argument) to
5097 look in all subdirectories for additional test cases. It isn't clear
5098 to me how this works, but it may be useful to deal with the
5099 unknown-PROJECTNAME problem described above, and is currently used in
5100 the Twisted buildbot to accomodate the fact that test cases are now
5101 distributed through multiple twisted.SUBPROJECT.test directories.
5103 @end table  
5105 Unless one of @code{trialModule} or @code{useTestCaseNames}
5106 are set, no tests will be run.
5108 Some quick examples follow. Most of these examples assume that the
5109 target python code (the ``code under test'') can be reached directly
5110 from the root of the target tree, rather than being in a @file{lib/}
5111 subdirectory.
5113 @example
5114 #  Trial(source, tests="toplevel.test") does:
5115 #   python ./setup.py build
5116 #   PYTHONPATH=. trial -to toplevel.test
5118 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
5119 #   python ./setup.py build
5120 #   PYTHONPATH=. trial -to toplevel.test other.test
5122 #  Trial(source, useTestCaseNames=True) does:
5123 #   python ./setup.py build
5124 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
5126 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
5127 #   python2.3 -Wall ./setup.py build
5128 #   PYTHONPATH=. trial -to foo.tests
5130 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
5131 #        tests="foo.tests") does:
5132 #   python2.3 -Wall ./setup.py build
5133 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
5135 # For running trial out of the tree being tested (only useful when the
5136 # tree being built is Twisted itself):
5137 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
5138 #        tests="foo.tests") does:
5139 #   python2.3 -Wall ./setup.py build
5140 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
5141 @end example
5143 If the output directory of @code{./setup.py build} is known, you can
5144 pull the python code from the built location instead of the source
5145 directories. This should be able to handle variations in where the
5146 source comes from, as well as accomodating binary extension modules:
5148 @example
5149 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
5150 # does:
5151 #  python ./setup.py build
5152 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
5153 @end example
5156 @node Status Delivery, Command-line tool, Build Process, Top
5157 @chapter Status Delivery
5159 More details are available in the docstrings for each class, use
5160 @code{pydoc buildbot.status.html.Waterfall} to see them. Most status
5161 delivery objects take a @code{categories=} argument, which can contain
5162 a list of ``category'' names: in this case, it will only show status
5163 for Builders that are in one of the named categories.
5165 (implementor's note: each of these objects should be a
5166 service.MultiService which will be attached to the BuildMaster object
5167 when the configuration is processed. They should use
5168 @code{self.parent.getStatus()} to get access to the top-level IStatus
5169 object, either inside @code{startService} or later. They may call
5170 @code{status.subscribe()} in @code{startService} to receive
5171 notifications of builder events, in which case they must define
5172 @code{builderAdded} and related methods. See the docstrings in
5173 @file{buildbot/interfaces.py} for full details.)
5175 @menu
5176 * HTML Waterfall::              
5177 * IRC Bot::                     
5178 * PBListener::                  
5179 * Writing New Status Plugins::  
5180 @end menu
5182 @c @node Email Delivery,  , Status Delivery, Status Delivery
5183 @c @subsection Email Delivery
5185 @c DOCUMENT THIS
5187 @node HTML Waterfall, IRC Bot, Status Delivery, Status Delivery
5188 @section HTML Waterfall
5190 @cindex Waterfall
5191 @stindex buildbot.status.html.Waterfall
5194 @example
5195 from buildbot.status import html
5196 w = html.Waterfall(http_port=8080)
5197 c['status'].append(w)
5198 @end example
5200 The @code{buildbot.status.html.Waterfall} status target creates an
5201 HTML ``waterfall display'', which shows a time-based chart of events.
5202 This display provides detailed information about all steps of all
5203 recent builds, and provides hyperlinks to look at individual build
5204 logs and source changes. If the @code{http_port} argument is provided,
5205 it provides a strports specification for the port that the web server
5206 should listen on. This can be a simple port number, or a string like
5207 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
5208 loopback interface, and therefore to clients running on the same
5209 host)@footnote{It may even be possible to provide SSL access by using
5210 a specification like
5211 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
5212 completely untested}.
5214 If instead (or in addition) you provide the @code{distrib_port}
5215 argument, a twisted.web distributed server will be started either on a
5216 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
5217 likely on a UNIX socket (if @code{distrib_port} is like
5218 @code{"unix:/path/to/socket"}).
5220 The @code{distrib_port} option means that, on a host with a
5221 suitably-configured twisted-web server, you do not need to consume a
5222 separate TCP port for the buildmaster's status web page. When the web
5223 server is constructed with @code{mktap web --user}, URLs that point to
5224 @code{http://host/~username/} are dispatched to a sub-server that is
5225 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
5226 such a system, it is convenient to create a dedicated @code{buildbot}
5227 user, then set @code{distrib_port} to
5228 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
5229 configuration will make the HTML status page available at
5230 @code{http://host/~buildbot/} . Suitable URL remapping can make it
5231 appear at @code{http://host/buildbot/}, and the right virtual host
5232 setup can even place it at @code{http://buildbot.host/} .
5234 Other arguments:
5236 @table @code
5237 @item allowForce
5238 If set to True (the default), then the web page will provide a ``Force
5239 Build'' button that allows visitors to manually trigger builds. This
5240 is useful for developers to re-run builds that have failed because of
5241 intermittent problems in the test suite, or because of libraries that
5242 were not installed at the time of the previous build. You may not wish
5243 to allow strangers to cause a build to run: in that case, set this to
5244 False to remove these buttons.
5246 @item favicon
5247 If set to a string, this will be interpreted as a filename containing
5248 a ``favicon'': a small image that contains an icon for the web site.
5249 This is returned to browsers that request the @code{favicon.ico} file,
5250 and should point to a .png or .ico image file. The default value uses
5251 the buildbot/buildbot.png image (a small hex nut) contained in the
5252 buildbot distribution. You can set this to None to avoid using a
5253 favicon at all.
5255 @item robots_txt
5256 If set to a string, this will be interpreted as a filename containing
5257 the contents of ``robots.txt''. Many search engine spiders request
5258 this file before indexing the site. Setting it to a file which
5259 contains:
5260 @example
5261 User-agent: *
5262 Disallow: /
5263 @end example
5264 will prevent most search engines from trawling the (voluminous)
5265 generated status pages.
5267 @end table
5270 @node IRC Bot, PBListener, HTML Waterfall, Status Delivery
5271 @section IRC Bot
5273 @cindex IRC
5274 @stindex buildbot.status.words.IRC
5277 The @code{buildbot.status.words.IRC} status target creates an IRC bot
5278 which will attach to certain channels and be available for status
5279 queries. It can also be asked to announce builds as they occur, or be
5280 told to shut up.
5282 @example
5283 from twisted.status import words
5284 irc = words.IRC("irc.example.org", "botnickname", 
5285                 channels=["channel1", "channel2"],
5286                 password="mysecretpassword")
5287 c['status'].append(irc)
5288 @end example
5290 Take a look at the docstring for @code{words.IRC} for more details on
5291 configuring this service. The @code{password} argument, if provided,
5292 will be sent to Nickserv to claim the nickname: some IRC servers will
5293 not allow clients to send private messages until they have logged in
5294 with a password.
5296 To use the service, you address messages at the buildbot, either
5297 normally (@code{botnickname: status}) or with private messages
5298 (@code{/msg botnickname status}). The buildbot will respond in kind.
5300 Some of the commands currently available:
5302 @table @code
5304 @item list builders
5305 Emit a list of all configured builders
5306 @item status BUILDER
5307 Announce the status of a specific Builder: what it is doing right now.
5308 @item status all
5309 Announce the status of all Builders
5310 @item watch BUILDER
5311 If the given Builder is currently running, wait until the Build is
5312 finished and then announce the results.
5313 @item last BUILDER
5314 Return the results of the last build to run on the given Builder.
5316 @item help COMMAND
5317 Describe a command. Use @code{help commands} to get a list of known
5318 commands.
5319 @item source
5320 Announce the URL of the Buildbot's home page.
5321 @item version
5322 Announce the version of this Buildbot.
5323 @end table
5325 If the @code{allowForce=True} option was used, some addtional commands
5326 will be available:
5328 @table @code
5329 @item force build BUILDER REASON
5330 Tell the given Builder to start a build of the latest code. The user
5331 requesting the build and REASON are recorded in the Build status. The
5332 buildbot will announce the build's status when it finishes.
5334 @item stop build BUILDER REASON
5335 Terminate any running build in the given Builder. REASON will be added
5336 to the build status to explain why it was stopped. You might use this
5337 if you committed a bug, corrected it right away, and don't want to
5338 wait for the first build (which is destined to fail) to complete
5339 before starting the second (hopefully fixed) build.
5340 @end table
5342 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
5343 @section PBListener
5345 @cindex PBListener
5346 @stindex buildbot.status.client.PBListener
5349 @example
5350 import buildbot.status.client
5351 pbl = buildbot.status.client.PBListener(port=int, user=str,
5352                                         passwd=str)
5353 c['status'].append(pbl)
5354 @end example
5356 This sets up a PB listener on the given TCP port, to which a PB-based
5357 status client can connect and retrieve status information.
5358 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
5359 status client. The @code{port} argument can also be a strports
5360 specification string.
5362 @node Writing New Status Plugins,  , PBListener, Status Delivery
5363 @section Writing New Status Plugins
5365 TODO: this needs a lot more examples
5367 Each status plugin is an object which provides the
5368 @code{twisted.application.service.IService} interface, which creates a
5369 tree of Services with the buildmaster at the top [not strictly true].
5370 The status plugins are all children of an object which implements
5371 @code{buildbot.interfaces.IStatus}, the main status object. From this
5372 object, the plugin can retrieve anything it wants about current and
5373 past builds. It can also subscribe to hear about new and upcoming
5374 builds.
5376 Status plugins which only react to human queries (like the Waterfall
5377 display) never need to subscribe to anything: they are idle until
5378 someone asks a question, then wake up and extract the information they
5379 need to answer it, then they go back to sleep. Plugins which need to
5380 act spontaneously when builds complete (like the Mail plugin) need to
5381 subscribe to hear about new builds.
5383 If the status plugin needs to run network services (like the HTTP
5384 server used by the Waterfall plugin), they can be attached as Service
5385 children of the plugin itself, using the @code{IServiceCollection}
5386 interface.
5390 @node Command-line tool, Resources, Status Delivery, Top
5391 @chapter Command-line tool
5393 The @command{buildbot} command-line tool can be used to start or stop a
5394 buildmaster or buildbot, and to interact with a running buildmaster.
5395 Some of its subcommands are intended for buildmaster admins, while
5396 some are for developers who are editing the code that the buildbot is
5397 monitoring.
5399 @menu
5400 * Administrator Tools::         
5401 * Developer Tools::             
5402 * Other Tools::                 
5403 * .buildbot config directory::  
5404 @end menu
5406 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
5407 @section Administrator Tools
5409 The following @command{buildbot} sub-commands are intended for
5410 buildmaster administrators:
5412 @heading create-master
5414 This creates a new directory and populates it with files that allow it
5415 to be used as a buildmaster's base directory.
5417 @example
5418 buildbot create-master BASEDIR
5419 @end example
5421 @heading create-slave
5423 This creates a new directory and populates it with files that let it
5424 be used as a buildslave's base directory. You must provide several
5425 arguments, which are used to create the initial @file{buildbot.tac}
5426 file.
5428 @example
5429 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
5430 @end example
5432 @heading start
5434 This starts a buildmaster or buildslave which was already created in
5435 the given base directory. The daemon is launched in the background,
5436 with events logged to a file named @file{twistd.log}.
5438 @example
5439 buildbot start BASEDIR
5440 @end example
5442 @heading stop
5444 This terminates the daemon (either buildmaster or buildslave) running
5445 in the given directory.
5447 @example
5448 buildbot stop BASEDIR
5449 @end example
5451 @heading sighup
5453 This sends a SIGHUP to the buildmaster running in the given directory,
5454 which causes it to re-read its @file{master.cfg} file.
5456 @example
5457 buildbot sighup BASEDIR
5458 @end example
5460 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
5461 @section Developer Tools
5463 These tools are provided for use by the developers who are working on
5464 the code that the buildbot is monitoring.
5466 @menu
5467 * statuslog::                   
5468 * statusgui::                   
5469 * try::                         
5470 @end menu
5472 @node statuslog, statusgui, Developer Tools, Developer Tools
5473 @subsection statuslog
5475 @example
5476 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
5477 @end example
5479 This command starts a simple text-based status client, one which just
5480 prints out a new line each time an event occurs on the buildmaster.
5482 The @option{--master} option provides the location of the
5483 @code{buildbot.status.client.PBListener} status port, used to deliver
5484 build information to realtime status clients. The option is always in
5485 the form of a string, with hostname and port number separated by a
5486 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
5487 same as the slaveport (although a future version may allow the same
5488 port number to be used for both purposes). If you get an error message
5489 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
5490 this may indicate that you are connecting to the slaveport rather than
5491 a @code{PBListener} port.
5493 The @option{--master} option can also be provided by the
5494 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
5495 config directory}).
5497 @node statusgui, try, statuslog, Developer Tools
5498 @subsection statusgui
5500 @cindex statusgui
5502 If you have set up a PBListener (@pxref{PBListener}), you will be able
5503 to monitor your Buildbot using a simple Gtk+ application invoked with
5504 the @code{buildbot statusgui} command:
5506 @example
5507 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
5508 @end example
5510 This command starts a simple Gtk+-based status client, which contains
5511 a few boxes for each Builder that change color as events occur. It
5512 uses the same @option{--master} argument as the @command{buildbot
5513 statuslog} command (@pxref{statuslog}).
5515 @node try,  , statusgui, Developer Tools
5516 @subsection try
5518 This lets a developer to ask the question ``What would happen if I
5519 committed this patch right now?''. It runs the unit test suite (across
5520 multiple build platforms) on the developer's current code, allowing
5521 them to make sure they will not break the tree when they finally
5522 commit their changes.
5524 The @command{buildbot try} command is meant to be run from within a
5525 developer's local tree, and starts by figuring out the base revision
5526 of that tree (what revision was current the last time the tree was
5527 updated), and a patch that can be applied to that revision of the tree
5528 to make it match the developer's copy. This (revision, patch) pair is
5529 then sent to the buildmaster, which runs a build with that
5530 SourceStamp. If you want, the tool will emit status messages as the
5531 builds run, and will not terminate until the first failure has been
5532 detected (or the last success).
5534 For this command to work, several pieces must be in place:
5537 @heading TryScheduler
5539 @slindex buildbot.scheduler.Try_Jobdir
5540 @slindex buildbot.scheduler.Try_Userpass
5542 The buildmaster must have a @code{scheduler.Try} instance in
5543 the config file's @code{c['schedulers']} list. This lets the
5544 administrator control who may initiate these ``trial'' builds, which
5545 branches are eligible for trial builds, and which Builders should be
5546 used for them.
5548 The @code{TryScheduler} has various means to accept build requests:
5549 all of them enforce more security than the usual buildmaster ports do.
5550 Any source code being built can be used to compromise the buildslave
5551 accounts, but in general that code must be checked out from the VC
5552 repository first, so only people with commit privileges can get
5553 control of the buildslaves. The usual force-build control channels can
5554 waste buildslave time but do not allow arbitrary commands to be
5555 executed by people who don't have those commit privileges. However,
5556 the source code patch that is provided with the trial build does not
5557 have to go through the VC system first, so it is important to make
5558 sure these builds cannot be abused by a non-committer to acquire as
5559 much control over the buildslaves as a committer has. Ideally, only
5560 developers who have commit access to the VC repository would be able
5561 to start trial builds, but unfortunately the buildmaster does not, in
5562 general, have access to VC system's user list.
5564 As a result, the @code{TryScheduler} requires a bit more
5565 configuration. There are currently two ways to set this up:
5567 @table @strong
5568 @item jobdir (ssh)
5570 This approach creates a command queue directory, called the
5571 ``jobdir'', in the buildmaster's working directory. The buildmaster
5572 admin sets the ownership and permissions of this directory to only
5573 grant write access to the desired set of developers, all of whom must
5574 have accounts on the machine. The @code{buildbot try} command creates
5575 a special file containing the source stamp information and drops it in
5576 the jobdir, just like a standard maildir. When the buildmaster notices
5577 the new file, it unpacks the information inside and starts the builds.
5579 The config file entries used by 'buildbot try' either specify a local
5580 queuedir (for which write and mv are used) or a remote one (using scp
5581 and ssh).
5583 The advantage of this scheme is that it is quite secure, the
5584 disadvantage is that it requires fiddling outside the buildmaster
5585 config (to set the permissions on the jobdir correctly). If the
5586 buildmaster machine happens to also house the VC repository, then it
5587 can be fairly easy to keep the VC userlist in sync with the
5588 trial-build userlist. If they are on different machines, this will be
5589 much more of a hassle. It may also involve granting developer accounts
5590 on a machine that would not otherwise require them.
5592 To implement this, the buildslave invokes 'ssh -l username host
5593 buildbot tryserver ARGS', passing the patch contents over stdin. The
5594 arguments must include the inlet directory and the revision
5595 information.
5597 @item user+password (PB)
5599 In this approach, each developer gets a username/password pair, which
5600 are all listed in the buildmaster's configuration file. When the
5601 developer runs @code{buildbot try}, their machine connects to the
5602 buildmaster via PB and authenticates themselves using that username
5603 and password, then sends a PB command to start the trial build.
5605 The advantage of this scheme is that the entire configuration is
5606 performed inside the buildmaster's config file. The disadvantages are
5607 that it is less secure (while the ``cred'' authentication system does
5608 not expose the password in plaintext over the wire, it does not offer
5609 most of the other security properties that SSH does). In addition, the
5610 buildmaster admin is responsible for maintaining the username/password
5611 list, adding and deleting entries as developers come and go.
5613 @end table
5616 For example, to set up the ``jobdir'' style of trial build, using a
5617 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
5618 all your project developers were members of the @code{developers} unix
5619 group), you would first create that directory (with @command{mkdir
5620 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
5621 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
5622 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
5623 MASTERDIR/jobdir/*}), and then use the following scheduler in the
5624 buildmaster's config file:
5626 @example
5627 from buildbot.scheduler import Try_Jobdir
5628 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
5629                jobdir="jobdir")
5630 c['schedulers'] = [s]
5631 @end example
5633 Note that you must create the jobdir before telling the buildmaster to
5634 use this configuration, otherwise you will get an error. Also remember
5635 that the buildmaster must be able to read and write to the jobdir as
5636 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
5637 as you start using the jobdir, to make sure the buildmaster is happy
5638 with it.
5640 To use the username/password form of authentication, create a
5641 @code{Try_Userpass} instance instead. It takes the same
5642 @code{builderNames} argument as the @code{Try_Jobdir} form, but
5643 accepts an addtional @code{port} argument (to specify the TCP port to
5644 listen on) and a @code{userpass} list of username/password pairs to
5645 accept. Remember to use good passwords for this: the security of the
5646 buildslave accounts depends upon it:
5648 @example
5649 from buildbot.scheduler import Try_Userpass
5650 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
5651                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
5652 c['schedulers'] = [s]
5653 @end example
5655 Like most places in the buildbot, the @code{port} argument takes a
5656 strports specification. See @code{twisted.application.strports} for
5657 details.
5660 @heading locating the master
5662 The @command{try} command needs to be told how to connect to the
5663 @code{TryScheduler}, and must know which of the authentication
5664 approaches described above is in use by the buildmaster. You specify
5665 the approach by using @option{--connect=ssh} or @option{--connect=pb}
5666 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
5667 @file{.buildbot/options}).
5669 For the PB approach, the command must be given a @option{--master}
5670 argument (in the form HOST:PORT) that points to TCP port that you
5671 picked in the @code{Try_Userpass} scheduler. It also takes a
5672 @option{--username} and @option{--passwd} pair of arguments that match
5673 one of the entries in the buildmaster's @code{userpass} list. These
5674 arguments can also be provided as @code{try_master},
5675 @code{try_username}, and @code{try_password} entries in the
5676 @file{.buildbot/options} file.
5678 For the SSH approach, the command must be given @option{--tryhost},
5679 @option{--username}, and optionally @option{--password} (TODO:
5680 really?) to get to the buildmaster host. It must also be given
5681 @option{--trydir}, which points to the inlet directory configured
5682 above. The trydir can be relative to the user's home directory, but
5683 most of the time you will use an explicit path like
5684 @file{~buildbot/project/trydir}. These arguments can be provided in
5685 @file{.buildbot/options} as @code{try_host}, @code{try_username},
5686 @code{try_password}, and @code{try_dir}.
5688 In addition, the SSH approach needs to connect to a PBListener status
5689 port, so it can retrieve and report the results of the build (the PB
5690 approach uses the existing connection to retrieve status information,
5691 so this step is not necessary). This requires a @option{--master}
5692 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
5693 in the form of a HOSTNAME:PORT string.
5696 @heading choosing the Builders
5698 A trial build is performed on multiple Builders at the same time, and
5699 the developer gets to choose which Builders are used (limited to a set
5700 selected by the buildmaster admin with the TryScheduler's
5701 @code{builderNames=} argument). The set you choose will depend upon
5702 what your goals are: if you are concerned about cross-platform
5703 compatibility, you should use multiple Builders, one from each
5704 platform of interest. You might use just one builder if that platform
5705 has libraries or other facilities that allow better test coverage than
5706 what you can accomplish on your own machine, or faster test runs.
5708 The set of Builders to use can be specified with multiple
5709 @option{--builder} arguments on the command line. It can also be
5710 specified with a single @code{try_builders} option in
5711 @file{.buildbot/options} that uses a list of strings to specify all
5712 the Builder names:
5714 @example
5715 try_builders = ["full-OSX", "full-win32", "full-linux"]
5716 @end example
5718 @heading specifying the VC system
5720 The @command{try} command also needs to know how to take the
5721 developer's current tree and extract the (revision, patch)
5722 source-stamp pair. Each VC system uses a different process, so you
5723 start by telling the @command{try} command which VC system you are
5724 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
5725 This can also be provided as @code{try_vc} in
5726 @file{.buildbot/options}.
5728 The following names are recognized: @code{cvs} @code{svn} @code{baz}
5729 @code{tla} @code{hg} @code{darcs}
5732 @heading finding the top of the tree
5734 Some VC systems (notably CVS and SVN) track each directory
5735 more-or-less independently, which means the @command{try} command
5736 needs to move up to the top of the project tree before it will be able
5737 to construct a proper full-tree patch. To accomplish this, the
5738 @command{try} command will crawl up through the parent directories
5739 until it finds a marker file. The default name for this marker file is
5740 @file{.buildbot-top}, so when you are using CVS or SVN you should
5741 @code{touch .buildbot-top} from the top of your tree before running
5742 @command{buildbot try}. Alternatively, you can use a filename like
5743 @file{ChangeLog} or @file{README}, since many projects put one of
5744 these files in their top-most directory (and nowhere else). To set
5745 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
5746 options file with @code{try_topfile = 'ChangeLog'}.
5748 You can also manually set the top of the tree with
5749 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
5750 '~/trees/mytree'}. If you use @code{try_topdir}, in a
5751 @file{.buildbot/options} file, you will need a separate options file
5752 for each tree you use, so it may be more convenient to use the
5753 @code{try_topfile} approach instead.
5755 Other VC systems which work on full projects instead of individual
5756 directories (tla, baz, darcs, monotone, mercurial) do not require
5757 @command{try} to know the top directory, so the @option{--try-topfile}
5758 and @option{--try-topdir} arguments will be ignored.
5759 @c is this true? I think I currently require topdirs all the time.
5761 If the @command{try} command cannot find the top directory, it will
5762 abort with an error message.
5764 @heading determining the branch name
5766 Some VC systems record the branch information in a way that ``try''
5767 can locate it, in particular Arch (both @command{tla} and
5768 @command{baz}). For the others, if you are using something other than
5769 the default branch, you will have to tell the buildbot which branch
5770 your tree is using. You can do this with either the @option{--branch}
5771 argument, or a @option{try_branch} entry in the
5772 @file{.buildbot/options} file.
5774 @heading determining the revision and patch
5776 Each VC system has a separate approach for determining the tree's base
5777 revision and computing a patch.
5779 @table @code
5781 @item CVS
5783 @command{try} pretends that the tree is up to date. It converts the
5784 current time into a @code{-D} time specification, uses it as the base
5785 revision, and computes the diff between the upstream tree as of that
5786 point in time versus the current contents. This works, more or less,
5787 but requires that the local clock be in reasonably good sync with the
5788 repository.
5790 @item SVN
5791 @command{try} does a @code{svn status -u} to find the latest
5792 repository revision number (emitted on the last line in the ``Status
5793 against revision: NN'' message). It then performs an @code{svn diff
5794 -rNN} to find out how your tree differs from the repository version,
5795 and sends the resulting patch to the buildmaster. If your tree is not
5796 up to date, this will result in the ``try'' tree being created with
5797 the latest revision, then @emph{backwards} patches applied to bring it
5798 ``back'' to the version you actually checked out (plus your actual
5799 code changes), but this will still result in the correct tree being
5800 used for the build.
5802 @item baz
5803 @command{try} does a @code{baz tree-id} to determine the
5804 fully-qualified version and patch identifier for the tree
5805 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
5806 as the base revision. It then does a @code{baz diff} to obtain the
5807 patch.
5809 @item tla
5810 @command{try} does a @code{tla tree-version} to get the
5811 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
5812 first line of @code{tla logs --reverse} to figure out the base
5813 revision. Then it does @code{tla changes --diffs} to obtain the patch.
5815 @item Darcs
5816 @code{darcs changes --context} emits a text file that contains a list
5817 of all patches back to and including the last tag was made. This text
5818 file (plus the location of a repository that contains all these
5819 patches) is sufficient to re-create the tree. Therefore the contents
5820 of this ``context'' file @emph{are} the revision stamp for a
5821 Darcs-controlled source tree.
5823 So @command{try} does a @code{darcs changes --context} to determine
5824 what your tree's base revision is, and then does a @code{darcs diff
5825 -u} to compute the patch relative to that revision.
5827 @item Mercurial
5828 @code{hg identify} emits a short revision ID (basically a truncated
5829 SHA1 hash of the current revision's contents), which is used as the
5830 base revision. @code{hg diff} then provides the patch relative to that
5831 revision. For @command{try} to work, your working directory must only
5832 have patches that are available from the same remotely-available
5833 repository that the build process' @code{step.Mercurial} will use.
5835 @c TODO: monotone, git
5836 @end table
5838 @heading waiting for results
5840 If you provide the @option{--wait} option (or @code{try_wait = True}
5841 in @file{.buildbot/options}), the @command{buildbot try} command will
5842 wait until your changes have either been proven good or bad before
5843 exiting. Unless you use the @option{--quiet} option (or
5844 @code{try_quiet=True}), it will emit a progress message every 60
5845 seconds until the builds have completed.
5848 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
5849 @section Other Tools
5851 These tools are generally used by buildmaster administrators.
5853 @menu
5854 * sendchange::                  
5855 * debugclient::                 
5856 @end menu
5858 @node sendchange, debugclient, Other Tools, Other Tools
5859 @subsection sendchange
5861 This command is used to tell the buildmaster about source changes. It
5862 is intended to be used from within a commit script, installed on the
5863 VC server. It requires that you have a PBChangeSource
5864 (@pxref{PBChangeSource}) running in the buildmaster (by being included
5865 in the @code{c['sources']} list).
5868 @example
5869 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
5870 @end example
5872 There are other (optional) arguments which can influence the
5873 @code{Change} that gets submitted:
5875 @table @code
5876 @item --branch
5877 This provides the (string) branch specifier. If omitted, it defaults
5878 to None, indicating the ``default branch''. All files included in this
5879 Change must be on the same branch.
5881 @item --revision_number
5882 This provides a (numeric) revision number for the change, used for VC systems
5883 that use numeric transaction numbers (like Subversion).
5885 @item --revision
5886 This provides a (string) revision specifier, for VC systems that use
5887 strings (Arch would use something like patch-42 etc).
5889 @item --revision_file
5890 This provides a filename which will be opened and the contents used as
5891 the revision specifier. This is specifically for Darcs, which uses the
5892 output of @command{darcs changes --context} as a revision specifier.
5893 This context file can be a couple of kilobytes long, spanning a couple
5894 lines per patch, and would be a hassle to pass as a command-line
5895 argument.
5897 @item --comments
5898 This provides the change comments as a single argument. You may want
5899 to use @option{--logfile} instead.
5901 @item --logfile
5902 This instructs the tool to read the change comments from the given
5903 file. If you use @code{-} as the filename, the tool will read the
5904 change comments from stdin.
5905 @end table
5908 @node debugclient,  , sendchange, Other Tools
5909 @subsection debugclient
5911 @example
5912 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
5913 @end example
5915 This launches a small Gtk+/Glade-based debug tool, connecting to the
5916 buildmaster's ``debug port''. This debug port shares the same port
5917 number as the slaveport (@pxref{Setting the slaveport}), but the
5918 @code{debugPort} is only enabled if you set a debug password in the
5919 buildmaster's config file (@pxref{Debug options}). The
5920 @option{--passwd} option must match the @code{c['debugPassword']}
5921 value.
5923 @option{--master} can also be provided in @file{.debug/options} by the
5924 @code{master} key. @option{--passwd} can be provided by the
5925 @code{debugPassword} key.
5927 The @code{Connect} button must be pressed before any of the other
5928 buttons will be active. This establishes the connection to the
5929 buildmaster. The other sections of the tool are as follows:
5931 @table @code
5932 @item Reload .cfg
5933 Forces the buildmaster to reload its @file{master.cfg} file. This is
5934 equivalent to sending a SIGHUP to the buildmaster, but can be done
5935 remotely through the debug port. Note that it is a good idea to be
5936 watching the buildmaster's @file{twistd.log} as you reload the config
5937 file, as any errors which are detected in the config file will be
5938 announced there.
5940 @item Rebuild .py
5941 (not yet implemented). The idea here is to use Twisted's ``rebuild''
5942 facilities to replace the buildmaster's running code with a new
5943 version. Even if this worked, it would only be used by buildbot
5944 developers.
5946 @item poke IRC
5947 This locates a @code{words.IRC} status target and causes it to emit a
5948 message on all the channels to which it is currently connected. This
5949 was used to debug a problem in which the buildmaster lost the
5950 connection to the IRC server and did not attempt to reconnect.
5952 @item Commit
5953 This allows you to inject a Change, just as if a real one had been
5954 delivered by whatever VC hook you are using. You can set the name of
5955 the committed file and the name of the user who is doing the commit.
5956 Optionally, you can also set a revision for the change. If the
5957 revision you provide looks like a number, it will be sent as an
5958 integer, otherwise it will be sent as a string.
5960 @item Force Build
5961 This lets you force a Builder (selected by name) to start a build of
5962 the current source tree.
5964 @item Currently
5965 (obsolete). This was used to manually set the status of the given
5966 Builder, but the status-assignment code was changed in an incompatible
5967 way and these buttons are no longer meaningful.
5969 @end table
5972 @node .buildbot config directory,  , Other Tools, Command-line tool
5973 @section .buildbot config directory
5975 Many of the @command{buildbot} tools must be told how to contact the
5976 buildmaster that they interact with. This specification can be
5977 provided as a command-line argument, but most of the time it will be
5978 easier to set them in an ``options'' file. The @command{buildbot}
5979 command will look for a special directory named @file{.buildbot},
5980 starting from the current directory (where the command was run) and
5981 crawling upwards, eventually looking in the user's home directory. It
5982 will look for a file named @file{options} in this directory, and will
5983 evaluate it as a python script, looking for certain names to be set.
5984 You can just put simple @code{name = 'value'} pairs in this file to
5985 set the options.
5987 For a description of the names used in this file, please see the
5988 documentation for the individual @command{buildbot} sub-commands. The
5989 following is a brief sample of what this file's contents could be.
5991 @example
5992 # for status-reading tools
5993 masterstatus = 'buildbot.example.org:12345'
5994 # for 'sendchange' or the debug port
5995 master = 'buildbot.example.org:18990'
5996 debugPassword = 'eiv7Po'
5997 @end example
5999 @table @code
6000 @item masterstatus
6001 Location of the @code{client.PBListener} status port, used by
6002 @command{statuslog} and @command{statusgui}.
6004 @item master
6005 Location of the @code{debugPort} (for @command{debugclient}). Also the
6006 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
6007 Usually shares the slaveport, but a future version may make it
6008 possible to have these listen on a separate port number.
6010 @item debugPassword
6011 Must match the value of @code{c['debugPassword']}, used to protect the
6012 debug port, for the @command{debugclient} command.
6014 @item username
6015 Provides a default username for the @command{sendchange} command.
6017 @end table
6020 The following options are used by the @code{buildbot try} command
6021 (@pxref{try}):
6023 @table @code
6024 @item try_connect
6025 This specifies how the ``try'' command should deliver its request to
6026 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
6027 @item try_builders
6028 Which builders should be used for the ``try'' build.
6029 @item try_vc
6030 This specifies the version control system being used.
6031 @item try_branch
6032 This indicates that the current tree is on a non-trunk branch.
6033 @item try_topdir
6034 @item try_topfile
6035 Use @code{try_topdir} to explicitly indicate the top of your working
6036 tree, or @code{try_topfile} to name a file that will only be found in
6037 that top-most directory.
6039 @item try_host
6040 @item try_username
6041 @item try_dir
6042 When try_connect is ``ssh'', the command will pay attention to
6043 @code{try_host}, @code{try_username}, and @code{try_dir}.
6045 @item try_username
6046 @item try_password
6047 @item try_master
6048 Instead, when @code{try_connect} is ``pb'', the command will pay
6049 attention to @code{try_username}, @code{try_password}, and
6050 @code{try_master}.
6052 @item try_wait
6053 @item masterstatus
6054 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
6055 command to wait for the requested build to complete.
6057 @end table
6061 @node Resources, Developer's Appendix, Command-line tool, Top
6062 @chapter Resources
6064 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
6066 For configuration questions and general discussion, please use the
6067 @code{buildbot-devel} mailing list. The subscription instructions and
6068 archives are available at
6069 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
6071 @node Developer's Appendix, Index of Useful Classes, Resources, Top
6072 @unnumbered Developer's Appendix
6074 This appendix contains random notes about the implementation of the
6075 Buildbot, and is likely to only be of use to people intending to
6076 extend the Buildbot's internals.
6078 The buildmaster consists of a tree of Service objects, which is shaped
6079 as follows:
6081 @example
6082 BuildMaster
6083  ChangeMaster  (in .change_svc)
6084   [IChangeSource instances]
6085  [IScheduler instances]  (in .schedulers)
6086  BotMaster  (in .botmaster)
6087  [IStatusTarget instances]  (in .statusTargets)
6088 @end example
6090 The BotMaster has a collection of Builder objects as values of its
6091 @code{.builders} dictionary.
6094 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
6095 @unnumbered Index of Useful Classes
6097 This is a list of all user-visible classes. There are the ones that
6098 are useful in @file{master.cfg}, the buildmaster's configuration file.
6099 Classes that are not listed here are generally internal things that
6100 admins are unlikely to have much use for.
6103 @heading Change Sources
6104 @printindex cs
6106 @heading Schedulers and Locks
6107 @printindex sl
6109 @heading Build Factories
6110 @printindex bf
6112 @heading Build Steps
6113 @printindex bs
6115 @c undocumented steps
6116 @bsindex buildbot.steps.source.Git
6117 @bsindex buildbot.steps.maxq.MaxQ
6120 @heading Status Targets
6121 @printindex st
6123 @c TODO: undocumented targets
6124 @stindex buildbot.status.mail.MailNotifier
6126 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
6127 @unnumbered Index of master.cfg keys
6129 This is a list of all of the significant keys in master.cfg . Recall
6130 that master.cfg is effectively a small python program one
6131 responsibility: create a dictionary named @code{BuildmasterConfig}.
6132 The keys of this dictionary are listed here. The beginning of the
6133 master.cfg file typically starts with something like:
6135 @example
6136 BuildmasterConfig = c = @{@}
6137 @end example
6139 Therefore a config key of @code{sources} will usually appear in
6140 master.cfg as @code{c['sources']}.
6142 @printindex bc
6145 @node Index,  , Index of master.cfg keys, Top
6146 @unnumbered Index
6148 @printindex cp
6151 @bye