Merge branch 'bug415' of git://github.com/Pike/buildbot into bug415
[buildbot.git] / docs / buildbot.texinfo
bloba54f56946eb25ff5b9cff0ed0c8f648b5b6c4374
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.9
5 @defcodeindex cs
6 @defcodeindex sl
7 @defcodeindex bf
8 @defcodeindex bs
9 @defcodeindex st
10 @defcodeindex bc
11 @c %**end of header
13 @c these indices are for classes useful in a master.cfg config file
14 @c @csindex : Change Sources
15 @c @slindex : Schedulers and Locks
16 @c @bfindex : Build Factories
17 @c @bsindex : Build Steps
18 @c @stindex : Status Targets
20 @c @bcindex : keys that make up BuildmasterConfig
22 @copying
23 This is the BuildBot manual.
25 Copyright (C) 2005,2006 Brian Warner
27 Copying and distribution of this file, with or without
28 modification, are permitted in any medium without royalty
29 provided the copyright notice and this notice are preserved.
31 @end copying
33 @titlepage
34 @title BuildBot
35 @page
36 @vskip 0pt plus 1filll
37 @insertcopying
38 @end titlepage
40 @c Output the table of the contents at the beginning.
41 @contents
43 @ifnottex
44 @node Top, Introduction, (dir), (dir)
45 @top BuildBot
47 @insertcopying
48 @end ifnottex
50 @menu
51 * Introduction::                What the BuildBot does.
52 * Installation::                Creating a buildmaster and buildslaves,
53                                 running them.
54 * Concepts::                    What goes on in the buildbot's little mind.
55 * Configuration::               Controlling the buildbot.
56 * Getting Source Code Changes::  Discovering when to run a build.
57 * Build Process::               Controlling how each build is run.
58 * Status Delivery::             Telling the world about the build's results.
59 * Command-line tool::
60 * Resources::                   Getting help.
61 * Developer's Appendix::
62 * Index of Useful Classes::
63 * Index of master.cfg keys::
64 * Index::                       Complete index.
66 @detailmenu
67  --- The Detailed Node Listing ---
69 Introduction
71 * History and Philosophy::
72 * System Architecture::
73 * Control Flow::
75 System Architecture
77 * BuildSlave Connections::
78 * Buildmaster Architecture::
79 * Status Delivery Architecture::
81 Installation
83 * Requirements::
84 * Installing the code::
85 * Creating a buildmaster::
86 * Upgrading an Existing Buildmaster::
87 * Creating a buildslave::
88 * Launching the daemons::
89 * Logfiles::
90 * Shutdown::
91 * Maintenance::
92 * Troubleshooting::
94 Creating a buildslave
96 * Buildslave Options::
98 Troubleshooting
100 * Starting the buildslave::
101 * Connecting to the buildmaster::
102 * Forcing Builds::
104 Concepts
106 * Version Control Systems::
107 * Schedulers::
108 * BuildSet::
109 * BuildRequest::
110 * Builder::
111 * Users::
112 * Build Properties::
114 Version Control Systems
116 * Generalizing VC Systems::
117 * Source Tree Specifications::
118 * How Different VC Systems Specify Sources::
119 * Attributes of Changes::
121 Users
123 * Doing Things With Users::
124 * Email Addresses::
125 * IRC Nicknames::
126 * Live Status Clients::
128 Configuration
130 * Config File Format::
131 * Loading the Config File::
132 * Testing the Config File::
133 * Defining the Project::
134 * Change Sources and Schedulers::
135 * Setting the slaveport::
136 * Buildslave Specifiers::
137 * On-Demand ("Latent") Buildslaves::
138 * Defining Global Properties::
139 * Defining Builders::
140 * Defining Status Targets::
141 * Debug options::
143 Change Sources and Schedulers
145 * Scheduler Scheduler::
146 * AnyBranchScheduler::
147 * Dependent Scheduler::
148 * Periodic Scheduler::
149 * Nightly Scheduler::
150 * Try Schedulers::
151 * Triggerable Scheduler::
153 Buildslave Specifiers
154 * When Buildslaves Go Missing::
156 On-Demand ("Latent") Buildslaves
157 * Amazon Web Services Elastic Compute Cloud ("AWS EC2")::
158 * Dangers with Latent Buildslaves::
159 * Writing New Latent Buildslaves::
161 Getting Source Code Changes
163 * Change Sources::
164 * Choosing ChangeSources::
165 * CVSToys - PBService::
166 * Mail-parsing ChangeSources::
167 * PBChangeSource::
168 * P4Source::
169 * BonsaiPoller::
170 * SVNPoller::
171 * MercurialHook::
172 * Bzr Hook::
173 * Bzr Poller::
175 Mail-parsing ChangeSources
177 * Subscribing the Buildmaster::
178 * Using Maildirs::
179 * Parsing Email Change Messages::
181 Parsing Email Change Messages
183 * FCMaildirSource::
184 * SyncmailMaildirSource::
185 * BonsaiMaildirSource::
186 * SVNCommitEmailMaildirSource::
188 Build Process
190 * Build Steps::
191 * Interlocks::
192 * Build Factories::
194 Build Steps
196 * Common Parameters::
197 * Using Build Properties::
198 * Source Checkout::
199 * ShellCommand::
200 * Simple ShellCommand Subclasses::
201 * Python BuildSteps::
202 * Transferring Files::
203 * Triggering Schedulers::
204 * Writing New BuildSteps::
206 Source Checkout
208 * CVS::
209 * SVN::
210 * Darcs::
211 * Mercurial::
212 * Arch::
213 * Bazaar::
214 * Bzr::
215 * P4::
216 * Git::
218 Simple ShellCommand Subclasses
220 * Configure::
221 * Compile::
222 * Test::
223 * TreeSize::
224 * PerlModuleTest::
225 * SetProperty::
227 Python BuildSteps
229 * BuildEPYDoc::
230 * PyFlakes::
232 Writing New BuildSteps
234 * BuildStep LogFiles::
235 * Reading Logfiles::
236 * Adding LogObservers::
237 * BuildStep URLs::
239 Build Factories
241 * BuildStep Objects::
242 * BuildFactory::
243 * Process-Specific build factories::
245 BuildStep Objects
247 * BuildFactory Attributes::
248 * Quick builds::
250 BuildFactory
252 * BuildFactory Attributes::
253 * Quick builds::
255 Process-Specific build factories
257 * GNUAutoconf::
258 * CPAN::
259 * Python distutils::
260 * Python/Twisted/trial projects::
262 Status Delivery
264 * WebStatus::
265 * MailNotifier::
266 * IRC Bot::
267 * PBListener::
268 * Writing New Status Plugins::
270 WebStatus
272 * WebStatus Configuration Parameters::
273 * Buildbot Web Resources::
274 * XMLRPC server::
275 * HTML Waterfall::
277 Command-line tool
279 * Administrator Tools::
280 * Developer Tools::
281 * Other Tools::
282 * .buildbot config directory::
284 Developer Tools
286 * statuslog::
287 * statusgui::
288 * try::
290 waiting for results
292 * try --diff::
294 Other Tools
296 * sendchange::
297 * debugclient::
299 @end detailmenu
300 @end menu
302 @node Introduction, Installation, Top, Top
303 @chapter Introduction
305 @cindex introduction
307 The BuildBot is a system to automate the compile/test cycle required by most
308 software projects to validate code changes. By automatically rebuilding and
309 testing the tree each time something has changed, build problems are
310 pinpointed quickly, before other developers are inconvenienced by the
311 failure. The guilty developer can be identified and harassed without human
312 intervention. By running the builds on a variety of platforms, developers
313 who do not have the facilities to test their changes everywhere before
314 checkin will at least know shortly afterwards whether they have broken the
315 build or not. Warning counts, lint checks, image size, compile time, and
316 other build parameters can be tracked over time, are more visible, and
317 are therefore easier to improve.
319 The overall goal is to reduce tree breakage and provide a platform to
320 run tests or code-quality checks that are too annoying or pedantic for
321 any human to waste their time with. Developers get immediate (and
322 potentially public) feedback about their changes, encouraging them to
323 be more careful about testing before checkin.
325 Features:
327 @itemize @bullet
328 @item
329 run builds on a variety of slave platforms
330 @item
331 arbitrary build process: handles projects using C, Python, whatever
332 @item
333 minimal host requirements: python and Twisted
334 @item
335 slaves can be behind a firewall if they can still do checkout
336 @item
337 status delivery through web page, email, IRC, other protocols
338 @item
339 track builds in progress, provide estimated completion time
340 @item
341 flexible configuration by subclassing generic build process classes
342 @item
343 debug tools to force a new build, submit fake Changes, query slave status
344 @item
345 released under the GPL
346 @end itemize
348 @menu
349 * History and Philosophy::
350 * System Architecture::
351 * Control Flow::
352 @end menu
355 @node History and Philosophy, System Architecture, Introduction, Introduction
356 @section History and Philosophy
358 @cindex Philosophy of operation
360 The Buildbot was inspired by a similar project built for a development
361 team writing a cross-platform embedded system. The various components
362 of the project were supposed to compile and run on several flavors of
363 unix (linux, solaris, BSD), but individual developers had their own
364 preferences and tended to stick to a single platform. From time to
365 time, incompatibilities would sneak in (some unix platforms want to
366 use @code{string.h}, some prefer @code{strings.h}), and then the tree
367 would compile for some developers but not others. The buildbot was
368 written to automate the human process of walking into the office,
369 updating a tree, compiling (and discovering the breakage), finding the
370 developer at fault, and complaining to them about the problem they had
371 introduced. With multiple platforms it was difficult for developers to
372 do the right thing (compile their potential change on all platforms);
373 the buildbot offered a way to help.
375 Another problem was when programmers would change the behavior of a
376 library without warning its users, or change internal aspects that
377 other code was (unfortunately) depending upon. Adding unit tests to
378 the codebase helps here: if an application's unit tests pass despite
379 changes in the libraries it uses, you can have more confidence that
380 the library changes haven't broken anything. Many developers
381 complained that the unit tests were inconvenient or took too long to
382 run: having the buildbot run them reduces the developer's workload to
383 a minimum.
385 In general, having more visibility into the project is always good,
386 and automation makes it easier for developers to do the right thing.
387 When everyone can see the status of the project, developers are
388 encouraged to keep the tree in good working order. Unit tests that
389 aren't run on a regular basis tend to suffer from bitrot just like
390 code does: exercising them on a regular basis helps to keep them
391 functioning and useful.
393 The current version of the Buildbot is additionally targeted at
394 distributed free-software projects, where resources and platforms are
395 only available when provided by interested volunteers. The buildslaves
396 are designed to require an absolute minimum of configuration, reducing
397 the effort a potential volunteer needs to expend to be able to
398 contribute a new test environment to the project. The goal is for
399 anyone who wishes that a given project would run on their favorite
400 platform should be able to offer that project a buildslave, running on
401 that platform, where they can verify that their portability code
402 works, and keeps working.
404 @node System Architecture, Control Flow, History and Philosophy, Introduction
405 @comment  node-name,  next,  previous,  up
406 @section System Architecture
408 The Buildbot consists of a single @code{buildmaster} and one or more
409 @code{buildslaves}, connected in a star topology. The buildmaster
410 makes all decisions about what, when, and how to build. It sends
411 commands to be run on the build slaves, which simply execute the
412 commands and return the results. (certain steps involve more local
413 decision making, where the overhead of sending a lot of commands back
414 and forth would be inappropriate, but in general the buildmaster is
415 responsible for everything).
417 The buildmaster is usually fed @code{Changes} by some sort of version
418 control system (@pxref{Change Sources}), which may cause builds to be
419 run. As the builds are performed, various status messages are
420 produced, which are then sent to any registered Status Targets
421 (@pxref{Status Delivery}).
423 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
424 @image{images/overview,,,Overview Diagram,}
426 The buildmaster is configured and maintained by the ``buildmaster
427 admin'', who is generally the project team member responsible for
428 build process issues. Each buildslave is maintained by a ``buildslave
429 admin'', who do not need to be quite as involved. Generally slaves are
430 run by anyone who has an interest in seeing the project work well on
431 their favorite platform.
433 @menu
434 * BuildSlave Connections::
435 * Buildmaster Architecture::
436 * Status Delivery Architecture::
437 @end menu
439 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
440 @subsection BuildSlave Connections
442 The buildslaves are typically run on a variety of separate machines,
443 at least one per platform of interest. These machines connect to the
444 buildmaster over a TCP connection to a publically-visible port. As a
445 result, the buildslaves can live behind a NAT box or similar
446 firewalls, as long as they can get to buildmaster. The TCP connections
447 are initiated by the buildslave and accepted by the buildmaster, but
448 commands and results travel both ways within this connection. The
449 buildmaster is always in charge, so all commands travel exclusively
450 from the buildmaster to the buildslave.
452 To perform builds, the buildslaves must typically obtain source code
453 from a CVS/SVN/etc repository. Therefore they must also be able to
454 reach the repository. The buildmaster provides instructions for
455 performing builds, but does not provide the source code itself.
457 @image{images/slaves,,,BuildSlave Connections,}
459 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
460 @subsection Buildmaster Architecture
462 The Buildmaster consists of several pieces:
464 @image{images/master,,,BuildMaster Architecture,}
466 @itemize @bullet
468 @item
469 Change Sources, which create a Change object each time something is
470 modified in the VC repository. Most ChangeSources listen for messages
471 from a hook script of some sort. Some sources actively poll the
472 repository on a regular basis. All Changes are fed to the Schedulers.
474 @item
475 Schedulers, which decide when builds should be performed. They collect
476 Changes into BuildRequests, which are then queued for delivery to
477 Builders until a buildslave is available.
479 @item
480 Builders, which control exactly @emph{how} each build is performed
481 (with a series of BuildSteps, configured in a BuildFactory). Each
482 Build is run on a single buildslave.
484 @item
485 Status plugins, which deliver information about the build results
486 through protocols like HTTP, mail, and IRC.
488 @end itemize
490 @image{images/slavebuilder,,,SlaveBuilders,}
492 Each Builder is configured with a list of BuildSlaves that it will use
493 for its builds. These buildslaves are expected to behave identically:
494 the only reason to use multiple BuildSlaves for a single Builder is to
495 provide a measure of load-balancing.
497 Within a single BuildSlave, each Builder creates its own SlaveBuilder
498 instance. These SlaveBuilders operate independently from each other.
499 Each gets its own base directory to work in. It is quite common to
500 have many Builders sharing the same buildslave. For example, there
501 might be two buildslaves: one for i386, and a second for PowerPC.
502 There may then be a pair of Builders that do a full compile/test run,
503 one for each architecture, and a lone Builder that creates snapshot
504 source tarballs if the full builders complete successfully. The full
505 builders would each run on a single buildslave, whereas the tarball
506 creation step might run on either buildslave (since the platform
507 doesn't matter when creating source tarballs). In this case, the
508 mapping would look like:
510 @example
511 Builder(full-i386)  ->  BuildSlaves(slave-i386)
512 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
513 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
514 @end example
516 and each BuildSlave would have two SlaveBuilders inside it, one for a
517 full builder, and a second for the source-tarball builder.
519 Once a SlaveBuilder is available, the Builder pulls one or more
520 BuildRequests off its incoming queue. (It may pull more than one if it
521 determines that it can merge the requests together; for example, there
522 may be multiple requests to build the current HEAD revision). These
523 requests are merged into a single Build instance, which includes the
524 SourceStamp that describes what exact version of the source code
525 should be used for the build. The Build is then randomly assigned to a
526 free SlaveBuilder and the build begins.
528 Beginning with version 0.7.10, the behaviour when BuildRequests are
529 merged can be customized, @pxref{Merging BuildRequests}.
531 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
532 @subsection Status Delivery Architecture
534 The buildmaster maintains a central Status object, to which various
535 status plugins are connected. Through this Status object, a full
536 hierarchy of build status objects can be obtained.
538 @image{images/status,,,Status Delivery,}
540 The configuration file controls which status plugins are active. Each
541 status plugin gets a reference to the top-level Status object. From
542 there they can request information on each Builder, Build, Step, and
543 LogFile. This query-on-demand interface is used by the html.Waterfall
544 plugin to create the main status page each time a web browser hits the
545 main URL.
547 The status plugins can also subscribe to hear about new Builds as they
548 occur: this is used by the MailNotifier to create new email messages
549 for each recently-completed Build.
551 The Status object records the status of old builds on disk in the
552 buildmaster's base directory. This allows it to return information
553 about historical builds.
555 There are also status objects that correspond to Schedulers and
556 BuildSlaves. These allow status plugins to report information about
557 upcoming builds, and the online/offline status of each buildslave.
560 @node Control Flow,  , System Architecture, Introduction
561 @comment  node-name,  next,  previous,  up
562 @section Control Flow
564 A day in the life of the buildbot:
566 @itemize @bullet
568 @item
569 A developer commits some source code changes to the repository. A hook
570 script or commit trigger of some sort sends information about this
571 change to the buildmaster through one of its configured Change
572 Sources. This notification might arrive via email, or over a network
573 connection (either initiated by the buildmaster as it ``subscribes''
574 to changes, or by the commit trigger as it pushes Changes towards the
575 buildmaster). The Change contains information about who made the
576 change, what files were modified, which revision contains the change,
577 and any checkin comments.
579 @item
580 The buildmaster distributes this change to all of its configured
581 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
582 to be started, and the Change is added to a list of those that will go
583 into a new Build. When the timer expires, a Build is started on each
584 of a set of configured Builders, all compiling/testing the same source
585 code. Unless configured otherwise, all Builds run in parallel on the
586 various buildslaves.
588 @item
589 The Build consists of a series of Steps. Each Step causes some number
590 of commands to be invoked on the remote buildslave associated with
591 that Builder. The first step is almost always to perform a checkout of
592 the appropriate revision from the same VC system that produced the
593 Change. The rest generally perform a compile and run unit tests. As
594 each Step runs, the buildslave reports back command output and return
595 status to the buildmaster.
597 @item
598 As the Build runs, status messages like ``Build Started'', ``Step
599 Started'', ``Build Finished'', etc, are published to a collection of
600 Status Targets. One of these targets is usually the HTML ``Waterfall''
601 display, which shows a chronological list of events, and summarizes
602 the results of the most recent build at the top of each column.
603 Developers can periodically check this page to see how their changes
604 have fared. If they see red, they know that they've made a mistake and
605 need to fix it. If they see green, they know that they've done their
606 duty and don't need to worry about their change breaking anything.
608 @item
609 If a MailNotifier status target is active, the completion of a build
610 will cause email to be sent to any developers whose Changes were
611 incorporated into this Build. The MailNotifier can be configured to
612 only send mail upon failing builds, or for builds which have just
613 transitioned from passing to failing. Other status targets can provide
614 similar real-time notification via different communication channels,
615 like IRC.
617 @end itemize
620 @node Installation, Concepts, Introduction, Top
621 @chapter Installation
623 @menu
624 * Requirements::
625 * Installing the code::
626 * Creating a buildmaster::
627 * Upgrading an Existing Buildmaster::
628 * Creating a buildslave::
629 * Launching the daemons::
630 * Logfiles::
631 * Shutdown::
632 * Maintenance::
633 * Troubleshooting::
634 @end menu
636 @node Requirements, Installing the code, Installation, Installation
637 @section Requirements
639 At a bare minimum, you'll need the following (for both the buildmaster
640 and a buildslave):
642 @itemize @bullet
643 @item
644 Python: http://www.python.org
646 Buildbot requires python-2.3 or later, and is primarily developed
647 against python-2.4. It is also tested against python-2.5 .
649 @item
650 Twisted: http://twistedmatrix.com
652 Both the buildmaster and the buildslaves require Twisted-2.0.x or
653 later. It has been tested against all releases of Twisted up to
654 Twisted-2.5.0 (the most recent as of this writing). As always, the
655 most recent version is recommended.
657 Twisted is delivered as a collection of subpackages. You'll need at
658 least "Twisted" (the core package), and you'll also want TwistedMail,
659 TwistedWeb, and TwistedWords (for sending email, serving a web status
660 page, and delivering build status via IRC, respectively). You might
661 also want TwistedConch (for the encrypted Manhole debug port). Note
662 that Twisted requires ZopeInterface to be installed as well.
664 @end itemize
666 Certain other packages may be useful on the system running the
667 buildmaster:
669 @itemize @bullet
670 @item
671 CVSToys: http://purl.net/net/CVSToys
673 If your buildmaster uses FreshCVSSource to receive change notification
674 from a cvstoys daemon, it will require CVSToys be installed (tested
675 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
676 only use a mail-parsing change source, or the SVN notification
677 script), you will not need CVSToys.
679 @end itemize
681 And of course, your project's build process will impose additional
682 requirements on the buildslaves. These hosts must have all the tools
683 necessary to compile and test your project's source code.
686 @node Installing the code, Creating a buildmaster, Requirements, Installation
687 @section Installing the code
689 @cindex installation
691 The Buildbot is installed using the standard python @code{distutils}
692 module. After unpacking the tarball, the process is:
694 @example
695 python setup.py build
696 python setup.py install
697 @end example
699 where the install step may need to be done as root. This will put the
700 bulk of the code in somewhere like
701 /usr/lib/python2.3/site-packages/buildbot . It will also install the
702 @code{buildbot} command-line tool in /usr/bin/buildbot.
704 To test this, shift to a different directory (like /tmp), and run:
706 @example
707 buildbot --version
708 @end example
710 If it shows you the versions of Buildbot and Twisted, the install went
711 ok. If it says @code{no such command} or it gets an @code{ImportError}
712 when it tries to load the libaries, then something went wrong.
713 @code{pydoc buildbot} is another useful diagnostic tool.
715 Windows users will find these files in other places. You will need to
716 make sure that python can find the libraries, and will probably find
717 it convenient to have @code{buildbot} on your PATH.
719 If you wish, you can run the buildbot unit test suite like this:
721 @example
722 PYTHONPATH=. trial buildbot.test
723 @end example
725 This should run up to 192 tests, depending upon what VC tools you have
726 installed. On my desktop machine it takes about five minutes to
727 complete. Nothing should fail, a few might be skipped. If any of the
728 tests fail, you should stop and investigate the cause before
729 continuing the installation process, as it will probably be easier to
730 track down the bug early.
732 If you cannot or do not wish to install the buildbot into a site-wide
733 location like @file{/usr} or @file{/usr/local}, you can also install
734 it into the account's home directory. Do the install command like
735 this:
737 @example
738 python setup.py install --home=~
739 @end example
741 That will populate @file{~/lib/python} and create
742 @file{~/bin/buildbot}. Make sure this lib directory is on your
743 @code{PYTHONPATH}.
746 @node Creating a buildmaster, Upgrading an Existing Buildmaster, Installing the code, Installation
747 @section Creating a buildmaster
749 As you learned earlier (@pxref{System Architecture}), the buildmaster
750 runs on a central host (usually one that is publically visible, so
751 everybody can check on the status of the project), and controls all
752 aspects of the buildbot system. Let us call this host
753 @code{buildbot.example.org}.
755 You may wish to create a separate user account for the buildmaster,
756 perhaps named @code{buildmaster}. This can help keep your personal
757 configuration distinct from that of the buildmaster and is useful if
758 you have to use a mail-based notification system (@pxref{Change
759 Sources}). However, the Buildbot will work just fine with your regular
760 user account.
762 You need to choose a directory for the buildmaster, called the
763 @code{basedir}. This directory will be owned by the buildmaster, which
764 will use configuration files therein, and create status files as it
765 runs. @file{~/Buildbot} is a likely value. If you run multiple
766 buildmasters in the same account, or if you run both masters and
767 slaves, you may want a more distinctive name like
768 @file{~/Buildbot/master/gnomovision} or
769 @file{~/Buildmasters/fooproject}. If you are using a separate user
770 account, this might just be @file{~buildmaster/masters/fooproject}.
772 Once you've picked a directory, use the @command{buildbot
773 create-master} command to create the directory and populate it with
774 startup files:
776 @example
777 buildbot create-master @var{basedir}
778 @end example
780 You will need to create a configuration file (@pxref{Configuration})
781 before starting the buildmaster. Most of the rest of this manual is
782 dedicated to explaining how to do this. A sample configuration file is
783 placed in the working directory, named @file{master.cfg.sample}, which
784 can be copied to @file{master.cfg} and edited to suit your purposes.
786 (Internal details: This command creates a file named
787 @file{buildbot.tac} that contains all the state necessary to create
788 the buildmaster. Twisted has a tool called @code{twistd} which can use
789 this .tac file to create and launch a buildmaster instance. twistd
790 takes care of logging and daemonization (running the program in the
791 background). @file{/usr/bin/buildbot} is a front end which runs twistd
792 for you.)
794 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
795 installed. This can be used as the basis for customized daemon startup,
796 @xref{Launching the daemons}.
798 @node Upgrading an Existing Buildmaster, Creating a buildslave, Creating a buildmaster, Installation
799 @section Upgrading an Existing Buildmaster
801 If you have just installed a new version of the Buildbot code, and you
802 have buildmasters that were created using an older version, you'll
803 need to upgrade these buildmasters before you can use them. The
804 upgrade process adds and modifies files in the buildmaster's base
805 directory to make it compatible with the new code.
807 @example
808 buildbot upgrade-master @var{basedir}
809 @end example
811 This command will also scan your @file{master.cfg} file for
812 incompatbilities (by loading it and printing any errors or deprecation
813 warnings that occur). Each buildbot release tries to be compatible
814 with configurations that worked cleanly (i.e. without deprecation
815 warnings) on the previous release: any functions or classes that are
816 to be removed will first be deprecated in a release, to give users a
817 chance to start using their replacement.
819 The 0.7.6 release introduced the @file{public_html/} directory, which
820 contains @file{index.html} and other files served by the
821 @code{WebStatus} and @code{Waterfall} status displays. The
822 @code{upgrade-master} command will create these files if they do not
823 already exist. It will not modify existing copies, but it will write a
824 new copy in e.g. @file{index.html.new} if the new version differs from
825 the version that already exists.
827 The @code{upgrade-master} command is idempotent. It is safe to run it
828 multiple times. After each upgrade of the buildbot code, you should
829 use @code{upgrade-master} on all your buildmasters.
832 @node Creating a buildslave, Launching the daemons, Upgrading an Existing Buildmaster, Installation
833 @section Creating a buildslave
835 Typically, you will be adding a buildslave to an existing buildmaster,
836 to provide additional architecture coverage. The buildbot
837 administrator will give you several pieces of information necessary to
838 connect to the buildmaster. You should also be somewhat familiar with
839 the project being tested, so you can troubleshoot build problems
840 locally.
842 The buildbot exists to make sure that the project's stated ``how to
843 build it'' process actually works. To this end, the buildslave should
844 run in an environment just like that of your regular developers.
845 Typically the project build process is documented somewhere
846 (@file{README}, @file{INSTALL}, etc), in a document that should
847 mention all library dependencies and contain a basic set of build
848 instructions. This document will be useful as you configure the host
849 and account in which the buildslave runs.
851 Here's a good checklist for setting up a buildslave:
853 @enumerate
854 @item
855 Set up the account
857 It is recommended (although not mandatory) to set up a separate user
858 account for the buildslave. This account is frequently named
859 @code{buildbot} or @code{buildslave}. This serves to isolate your
860 personal working environment from that of the slave's, and helps to
861 minimize the security threat posed by letting possibly-unknown
862 contributors run arbitrary code on your system. The account should
863 have a minimum of fancy init scripts.
865 @item
866 Install the buildbot code
868 Follow the instructions given earlier (@pxref{Installing the code}).
869 If you use a separate buildslave account, and you didn't install the
870 buildbot code to a shared location, then you will need to install it
871 with @code{--home=~} for each account that needs it.
873 @item
874 Set up the host
876 Make sure the host can actually reach the buildmaster. Usually the
877 buildmaster is running a status webserver on the same machine, so
878 simply point your web browser at it and see if you can get there.
879 Install whatever additional packages or libraries the project's
880 INSTALL document advises. (or not: if your buildslave is supposed to
881 make sure that building without optional libraries still works, then
882 don't install those libraries).
884 Again, these libraries don't necessarily have to be installed to a
885 site-wide shared location, but they must be available to your build
886 process. Accomplishing this is usually very specific to the build
887 process, so installing them to @file{/usr} or @file{/usr/local} is
888 usually the best approach.
890 @item
891 Test the build process
893 Follow the instructions in the INSTALL document, in the buildslave's
894 account. Perform a full CVS (or whatever) checkout, configure, make,
895 run tests, etc. Confirm that the build works without manual fussing.
896 If it doesn't work when you do it by hand, it will be unlikely to work
897 when the buildbot attempts to do it in an automated fashion.
899 @item
900 Choose a base directory
902 This should be somewhere in the buildslave's account, typically named
903 after the project which is being tested. The buildslave will not touch
904 any file outside of this directory. Something like @file{~/Buildbot}
905 or @file{~/Buildslaves/fooproject} is appropriate.
907 @item
908 Get the buildmaster host/port, botname, and password
910 When the buildbot admin configures the buildmaster to accept and use
911 your buildslave, they will provide you with the following pieces of
912 information:
914 @itemize @bullet
915 @item
916 your buildslave's name
917 @item
918 the password assigned to your buildslave
919 @item
920 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
921 @end itemize
923 @item
924 Create the buildslave
926 Now run the 'buildbot' command as follows:
928 @example
929 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
930 @end example
932 This will create the base directory and a collection of files inside,
933 including the @file{buildbot.tac} file that contains all the
934 information you passed to the @code{buildbot} command.
936 @item
937 Fill in the hostinfo files
939 When it first connects, the buildslave will send a few files up to the
940 buildmaster which describe the host that it is running on. These files
941 are presented on the web status display so that developers have more
942 information to reproduce any test failures that are witnessed by the
943 buildbot. There are sample files in the @file{info} subdirectory of
944 the buildbot's base directory. You should edit these to correctly
945 describe you and your host.
947 @file{BASEDIR/info/admin} should contain your name and email address.
948 This is the ``buildslave admin address'', and will be visible from the
949 build status page (so you may wish to munge it a bit if
950 address-harvesting spambots are a concern).
952 @file{BASEDIR/info/host} should be filled with a brief description of
953 the host: OS, version, memory size, CPU speed, versions of relevant
954 libraries installed, and finally the version of the buildbot code
955 which is running the buildslave.
957 If you run many buildslaves, you may want to create a single
958 @file{~buildslave/info} file and share it among all the buildslaves
959 with symlinks.
961 @end enumerate
963 @menu
964 * Buildslave Options::
965 @end menu
967 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
968 @subsection Buildslave Options
970 There are a handful of options you might want to use when creating the
971 buildslave with the @command{buildbot create-slave <options> DIR <params>}
972 command. You can type @command{buildbot create-slave --help} for a summary.
973 To use these, just include them on the @command{buildbot create-slave}
974 command line, like this:
976 @example
977 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
978 @end example
980 @table @code
981 @item --usepty
982 This is a boolean flag that tells the buildslave whether to launch
983 child processes in a PTY (the default) or with regular pipes. The
984 advantage of using a PTY is that ``grandchild'' processes are more
985 likely to be cleaned up if the build is interrupted or times out
986 (since it enables the use of a ``process group'' in which all child
987 processes will be placed). The disadvantages: some forms of Unix have
988 problems with PTYs, some of your unit tests may behave differently
989 when run under a PTY (generally those which check to see if they are
990 being run interactively), and PTYs will merge the stdout and stderr
991 streams into a single output stream (which means the red-vs-black
992 coloring in the logfiles will be lost). If you encounter problems, you
993 can add @code{--usepty=0} to disable the use of PTYs. Note that
994 windows buildslaves never use PTYs.
996 @item --umask
997 This is a string (generally an octal representation of an integer)
998 which will cause the buildslave process' ``umask'' value to be set
999 shortly after initialization. The ``twistd'' daemonization utility
1000 forces the umask to 077 at startup (which means that all files created
1001 by the buildslave or its child processes will be unreadable by any
1002 user other than the buildslave account). If you want build products to
1003 be readable by other accounts, you can add @code{--umask=022} to tell
1004 the buildslave to fix the umask after twistd clobbers it. If you want
1005 build products to be @emph{writable} by other accounts too, use
1006 @code{--umask=000}, but this is likely to be a security problem.
1008 @item --keepalive
1009 This is a number that indicates how frequently ``keepalive'' messages
1010 should be sent from the buildslave to the buildmaster, expressed in
1011 seconds. The default (600) causes a message to be sent to the
1012 buildmaster at least once every 10 minutes. To set this to a lower
1013 value, use e.g. @code{--keepalive=120}.
1015 If the buildslave is behind a NAT box or stateful firewall, these
1016 messages may help to keep the connection alive: some NAT boxes tend to
1017 forget about a connection if it has not been used in a while. When
1018 this happens, the buildmaster will think that the buildslave has
1019 disappeared, and builds will time out. Meanwhile the buildslave will
1020 not realize than anything is wrong.
1022 @item --maxdelay
1023 This is a number that indicates the maximum amount of time the
1024 buildslave will wait between connection attempts, expressed in
1025 seconds. The default (300) causes the buildslave to wait at most 5
1026 minutes before trying to connect to the buildmaster again.
1028 @item --log-size
1029 This is the size in bytes when to rotate the Twisted log files.
1031 @item --log-count
1032 This is the number of log rotations to keep around. You can either
1033 specify a number or @code{None} (the default) to keep all
1034 @file{twistd.log} files around.
1036 @end table
1039 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
1040 @section Launching the daemons
1042 Both the buildmaster and the buildslave run as daemon programs. To
1043 launch them, pass the working directory to the @code{buildbot}
1044 command:
1046 @example
1047 buildbot start @var{BASEDIR}
1048 @end example
1050 This command will start the daemon and then return, so normally it
1051 will not produce any output. To verify that the programs are indeed
1052 running, look for a pair of files named @file{twistd.log} and
1053 @file{twistd.pid} that should be created in the working directory.
1054 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
1056 When the buildslave connects to the buildmaster, new directories will
1057 start appearing in its base directory. The buildmaster tells the slave
1058 to create a directory for each Builder which will be using that slave.
1059 All build operations are performed within these directories: CVS
1060 checkouts, compiles, and tests.
1062 Once you get everything running, you will want to arrange for the
1063 buildbot daemons to be started at boot time. One way is to use
1064 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
1065 @@reboot syntax is understood by Vixie cron, which is the flavor
1066 usually provided with linux systems. Other unices may have a cron that
1067 doesn't understand @@reboot}:
1069 @example
1070 @@reboot buildbot start @var{BASEDIR}
1071 @end example
1073 When you run @command{crontab} to set this up, remember to do it as
1074 the buildmaster or buildslave account! If you add this to your crontab
1075 when running as your regular account (or worse yet, root), then the
1076 daemon will run as the wrong user, quite possibly as one with more
1077 authority than you intended to provide.
1079 It is important to remember that the environment provided to cron jobs
1080 and init scripts can be quite different that your normal runtime.
1081 There may be fewer environment variables specified, and the PATH may
1082 be shorter than usual. It is a good idea to test out this method of
1083 launching the buildslave by using a cron job with a time in the near
1084 future, with the same command, and then check @file{twistd.log} to
1085 make sure the slave actually started correctly. Common problems here
1086 are for @file{/usr/local} or @file{~/bin} to not be on your
1087 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
1088 Sometimes @code{HOME} is messed up too.
1090 To modify the way the daemons are started (perhaps you want to set
1091 some environment variables first, or perform some cleanup each time),
1092 you can create a file named @file{Makefile.buildbot} in the base
1093 directory. When the @file{buildbot} front-end tool is told to
1094 @command{start} the daemon, and it sees this file (and
1095 @file{/usr/bin/make} exists), it will do @command{make -f
1096 Makefile.buildbot start} instead of its usual action (which involves
1097 running @command{twistd}). When the buildmaster or buildslave is
1098 installed, a @file{Makefile.sample} is created which implements the
1099 same behavior as the the @file{buildbot} tool uses, so if you want to
1100 customize the process, just copy @file{Makefile.sample} to
1101 @file{Makefile.buildbot} and edit it as necessary.
1103 Some distributions may include conveniences to make starting buildbot
1104 at boot time easy.  For instance, with the default buildbot package in
1105 Debian-based distributions, you may only need to modify
1106 @code{/etc/default/buildbot} (see also @code{/etc/init.d/buildbot}, which
1107 reads the configuration in @code{/etc/default/buildbot}).
1109 @node Logfiles, Shutdown, Launching the daemons, Installation
1110 @section Logfiles
1112 @cindex logfiles
1114 While a buildbot daemon runs, it emits text to a logfile, named
1115 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1116 to watch the command output as it runs.
1118 The buildmaster will announce any errors with its configuration file
1119 in the logfile, so it is a good idea to look at the log at startup
1120 time to check for any problems. Most buildmaster activities will cause
1121 lines to be added to the log.
1123 @node Shutdown, Maintenance, Logfiles, Installation
1124 @section Shutdown
1126 To stop a buildmaster or buildslave manually, use:
1128 @example
1129 buildbot stop @var{BASEDIR}
1130 @end example
1132 This simply looks for the @file{twistd.pid} file and kills whatever
1133 process is identified within.
1135 At system shutdown, all processes are sent a @code{SIGKILL}. The
1136 buildmaster and buildslave will respond to this by shutting down
1137 normally.
1139 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1140 config file. Of course, this only works on unix-like systems with
1141 signal support, and won't work on Windows. The following shortcut is
1142 available:
1144 @example
1145 buildbot reconfig @var{BASEDIR}
1146 @end example
1148 When you update the Buildbot code to a new release, you will need to
1149 restart the buildmaster and/or buildslave before it can take advantage
1150 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1151 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1152 use the @code{restart} shortcut, which does both steps for you:
1154 @example
1155 buildbot restart @var{BASEDIR}
1156 @end example
1158 There are certain configuration changes that are not handled cleanly
1159 by @code{buildbot reconfig}. If this occurs, @code{buildbot restart}
1160 is a more robust tool to fully switch over to the new configuration.
1162 @code{buildbot restart} may also be used to start a stopped Buildbot
1163 instance. This behaviour is useful when writing scripts that stop, start
1164 and restart Buildbot.
1167 @node Maintenance, Troubleshooting, Shutdown, Installation
1168 @section Maintenance
1170 It is a good idea to check the buildmaster's status page every once in
1171 a while, to see if your buildslave is still online. Eventually the
1172 buildbot will probably be enhanced to send you email (via the
1173 @file{info/admin} email address) when the slave has been offline for
1174 more than a few hours.
1176 If you find you can no longer provide a buildslave to the project, please
1177 let the project admins know, so they can put out a call for a
1178 replacement.
1180 The Buildbot records status and logs output continually, each time a
1181 build is performed. The status tends to be small, but the build logs
1182 can become quite large. Each build and log are recorded in a separate
1183 file, arranged hierarchically under the buildmaster's base directory.
1184 To prevent these files from growing without bound, you should
1185 periodically delete old build logs. A simple cron job to delete
1186 anything older than, say, two weeks should do the job. The only trick
1187 is to leave the @file{buildbot.tac} and other support files alone, for
1188 which find's @code{-mindepth} argument helps skip everything in the
1189 top directory. You can use something like the following:
1191 @example
1192 @@weekly cd BASEDIR && find . -mindepth 2 i-path './public_html/*' -prune -o -type f -mtime +14 -exec rm @{@} \;
1193 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1194 @end example
1196 @node Troubleshooting,  , Maintenance, Installation
1197 @section Troubleshooting
1199 Here are a few hints on diagnosing common problems.
1201 @menu
1202 * Starting the buildslave::
1203 * Connecting to the buildmaster::
1204 * Forcing Builds::
1205 @end menu
1207 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1208 @subsection Starting the buildslave
1210 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1211 @file{/bin/bash}), and tilde expansion is not always performed in such
1212 commands. You may want to use explicit paths, because the @code{PATH}
1213 is usually quite short and doesn't include anything set by your
1214 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1215 you've installed buildbot (or other python libraries) to an unusual
1216 location, you may need to add a @code{PYTHONPATH} specification (note
1217 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1218 itself). Sometimes it is safer to fully-specify everything:
1220 @example
1221 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1222 @end example
1224 Take the time to get the @@reboot job set up. Otherwise, things will work
1225 fine for a while, but the first power outage or system reboot you have will
1226 stop the buildslave with nothing but the cries of sorrowful developers to
1227 remind you that it has gone away.
1229 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1230 @subsection Connecting to the buildmaster
1232 If the buildslave cannot connect to the buildmaster, the reason should
1233 be described in the @file{twistd.log} logfile. Some common problems
1234 are an incorrect master hostname or port number, or a mistyped bot
1235 name or password. If the buildslave loses the connection to the
1236 master, it is supposed to attempt to reconnect with an
1237 exponentially-increasing backoff. Each attempt (and the time of the
1238 next attempt) will be logged. If you get impatient, just manually stop
1239 and re-start the buildslave.
1241 When the buildmaster is restarted, all slaves will be disconnected,
1242 and will attempt to reconnect as usual. The reconnect time will depend
1243 upon how long the buildmaster is offline (i.e. how far up the
1244 exponential backoff curve the slaves have travelled). Again,
1245 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1246 speed up the process.
1248 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1249 @subsection Forcing Builds
1251 From the buildmaster's main status web page, you can force a build to
1252 be run on your build slave. Figure out which column is for a builder
1253 that runs on your slave, click on that builder's name, and the page
1254 that comes up will have a ``Force Build'' button. Fill in the form,
1255 hit the button, and a moment later you should see your slave's
1256 @file{twistd.log} filling with commands being run. Using @code{pstree}
1257 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1258 run by the buildslave. Note that the same web page should also show
1259 the @file{admin} and @file{host} information files that you configured
1260 earlier.
1262 @node Concepts, Configuration, Installation, Top
1263 @chapter Concepts
1265 This chapter defines some of the basic concepts that the Buildbot
1266 uses. You'll need to understand how the Buildbot sees the world to
1267 configure it properly.
1269 @menu
1270 * Version Control Systems::
1271 * Schedulers::
1272 * BuildSet::
1273 * BuildRequest::
1274 * Builder::
1275 * Users::
1276 * Build Properties::
1277 @end menu
1279 @node Version Control Systems, Schedulers, Concepts, Concepts
1280 @section Version Control Systems
1282 @cindex Version Control
1284 These source trees come from a Version Control System of some kind.
1285 CVS and Subversion are two popular ones, but the Buildbot supports
1286 others. All VC systems have some notion of an upstream
1287 @code{repository} which acts as a server@footnote{except Darcs, but
1288 since the Buildbot never modifies its local source tree we can ignore
1289 the fact that Darcs uses a less centralized model}, from which clients
1290 can obtain source trees according to various parameters. The VC
1291 repository provides source trees of various projects, for different
1292 branches, and from various points in time. The first thing we have to
1293 do is to specify which source tree we want to get.
1295 @menu
1296 * Generalizing VC Systems::
1297 * Source Tree Specifications::
1298 * How Different VC Systems Specify Sources::
1299 * Attributes of Changes::
1300 @end menu
1302 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1303 @subsection Generalizing VC Systems
1305 For the purposes of the Buildbot, we will try to generalize all VC
1306 systems as having repositories that each provide sources for a variety
1307 of projects. Each project is defined as a directory tree with source
1308 files. The individual files may each have revisions, but we ignore
1309 that and treat the project as a whole as having a set of revisions
1310 (CVS is really the only VC system still in widespread use that has
1311 per-file revisions.. everything modern has moved to atomic tree-wide
1312 changesets). Each time someone commits a change to the project, a new
1313 revision becomes available. These revisions can be described by a
1314 tuple with two items: the first is a branch tag, and the second is
1315 some kind of revision stamp or timestamp. Complex projects may have
1316 multiple branch tags, but there is always a default branch. The
1317 timestamp may be an actual timestamp (such as the -D option to CVS),
1318 or it may be a monotonically-increasing transaction number (such as
1319 the change number used by SVN and P4, or the revision number used by
1320 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1321 systems provide more complexity than this: in particular the local
1322 views that P4 and ClearCase can assemble out of various source
1323 directories are more complex than we're prepared to take advantage of
1324 here}. The SHA1 revision ID used by Monotone, Mercurial, and Git is
1325 also a kind of revision stamp, in that it specifies a unique copy of
1326 the source tree, as does a Darcs ``context'' file.
1328 When we aren't intending to make any changes to the sources we check out
1329 (at least not any that need to be committed back upstream), there are two
1330 basic ways to use a VC system:
1332 @itemize @bullet
1333 @item
1334 Retrieve a specific set of source revisions: some tag or key is used
1335 to index this set, which is fixed and cannot be changed by subsequent
1336 developers committing new changes to the tree. Releases are built from
1337 tagged revisions like this, so that they can be rebuilt again later
1338 (probably with controlled modifications).
1339 @item
1340 Retrieve the latest sources along a specific branch: some tag is used
1341 to indicate which branch is to be used, but within that constraint we want
1342 to get the latest revisions.
1343 @end itemize
1345 Build personnel or CM staff typically use the first approach: the
1346 build that results is (ideally) completely specified by the two
1347 parameters given to the VC system: repository and revision tag. This
1348 gives QA and end-users something concrete to point at when reporting
1349 bugs. Release engineers are also reportedly fond of shipping code that
1350 can be traced back to a concise revision tag of some sort.
1352 Developers are more likely to use the second approach: each morning
1353 the developer does an update to pull in the changes committed by the
1354 team over the last day. These builds are not easy to fully specify: it
1355 depends upon exactly when you did a checkout, and upon what local
1356 changes the developer has in their tree. Developers do not normally
1357 tag each build they produce, because there is usually significant
1358 overhead involved in creating these tags. Recreating the trees used by
1359 one of these builds can be a challenge. Some VC systems may provide
1360 implicit tags (like a revision number), while others may allow the use
1361 of timestamps to mean ``the state of the tree at time X'' as opposed
1362 to a tree-state that has been explicitly marked.
1364 The Buildbot is designed to help developers, so it usually works in
1365 terms of @emph{the latest} sources as opposed to specific tagged
1366 revisions. However, it would really prefer to build from reproducible
1367 source trees, so implicit revisions are used whenever possible.
1369 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1370 @subsection Source Tree Specifications
1372 So for the Buildbot's purposes we treat each VC system as a server
1373 which can take a list of specifications as input and produce a source
1374 tree as output. Some of these specifications are static: they are
1375 attributes of the builder and do not change over time. Others are more
1376 variable: each build will have a different value. The repository is
1377 changed over time by a sequence of Changes, each of which represents a
1378 single developer making changes to some set of files. These Changes
1379 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1380 violates this assumption of cumulative Changes, but in most situations
1381 the changes don't occur frequently enough for this to be a significant
1382 problem}.
1384 For normal builds, the Buildbot wants to get well-defined source trees
1385 that contain specific Changes, and exclude other Changes that may have
1386 occurred after the desired ones. We assume that the Changes arrive at
1387 the buildbot (through one of the mechanisms described in @pxref{Change
1388 Sources}) in the same order in which they are committed to the
1389 repository. The Buildbot waits for the tree to become ``stable''
1390 before initiating a build, for two reasons. The first is that
1391 developers frequently make multiple related commits in quick
1392 succession, even when the VC system provides ways to make atomic
1393 transactions involving multiple files at the same time. Running a
1394 build in the middle of these sets of changes would use an inconsistent
1395 set of source files, and is likely to fail (and is certain to be less
1396 useful than a build which uses the full set of changes). The
1397 tree-stable-timer is intended to avoid these useless builds that
1398 include some of the developer's changes but not all. The second reason
1399 is that some VC systems (i.e. CVS) do not provide repository-wide
1400 transaction numbers, so that timestamps are the only way to refer to
1401 a specific repository state. These timestamps may be somewhat
1402 ambiguous, due to processing and notification delays. By waiting until
1403 the tree has been stable for, say, 10 minutes, we can choose a
1404 timestamp from the middle of that period to use for our source
1405 checkout, and then be reasonably sure that any clock-skew errors will
1406 not cause the build to be performed on an inconsistent set of source
1407 files.
1409 The Schedulers always use the tree-stable-timer, with a timeout that
1410 is configured to reflect a reasonable tradeoff between build latency
1411 and change frequency. When the VC system provides coherent
1412 repository-wide revision markers (such as Subversion's revision
1413 numbers, or in fact anything other than CVS's timestamps), the
1414 resulting Build is simply performed against a source tree defined by
1415 that revision marker. When the VC system does not provide this, a
1416 timestamp from the middle of the tree-stable period is used to
1417 generate the source tree@footnote{this @code{checkoutDelay} defaults
1418 to half the tree-stable timer, but it can be overridden with an
1419 argument to the Source Step}.
1421 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1422 @subsection How Different VC Systems Specify Sources
1424 For CVS, the static specifications are @code{repository} and
1425 @code{module}. In addition to those, each build uses a timestamp (or
1426 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1427 (which defaults to HEAD). These parameters collectively specify a set
1428 of sources from which a build may be performed.
1430 @uref{http://subversion.tigris.org, Subversion} combines the
1431 repository, module, and branch into a single @code{Subversion URL}
1432 parameter. Within that scope, source checkouts can be specified by a
1433 numeric @code{revision number} (a repository-wide
1434 monotonically-increasing marker, such that each transaction that
1435 changes the repository is indexed by a different revision number), or
1436 a revision timestamp. When branches are used, the repository and
1437 module form a static @code{baseURL}, while each build has a
1438 @code{revision number} and a @code{branch} (which defaults to a
1439 statically-specified @code{defaultBranch}). The @code{baseURL} and
1440 @code{branch} are simply concatenated together to derive the
1441 @code{svnurl} to use for the checkout.
1443 @uref{http://www.perforce.com/, Perforce} is similar. The server
1444 is specified through a @code{P4PORT} parameter. Module and branch
1445 are specified in a single depot path, and revisions are
1446 depot-wide. When branches are used, the @code{p4base} and
1447 @code{defaultBranch} are concatenated together to produce the depot
1448 path.
1450 @uref{http://wiki.gnuarch.org/, Arch} and
1451 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1452 URL, as well as a @code{version} which is kind of like a branch name.
1453 Arch uses the word @code{archive} to represent the repository. Arch
1454 lets you push changes from one archive to another, removing the strict
1455 centralization required by CVS and SVN. It retains the distinction
1456 between repository and working directory that most other VC systems
1457 use. For complex multi-module directory structures, Arch has a
1458 built-in @code{build config} layer with which the checkout process has
1459 two steps. First, an initial bootstrap checkout is performed to
1460 retrieve a set of build-config files. Second, one of these files is
1461 used to figure out which archives/modules should be used to populate
1462 subdirectories of the initial checkout.
1464 Builders which use Arch and Bazaar therefore have a static archive
1465 @code{url}, and a default ``branch'' (which is a string that specifies
1466 a complete category--branch--version triple). Each build can have its
1467 own branch (the category--branch--version string) to override the
1468 default, as well as a revision number (which is turned into a
1469 --patch-NN suffix when performing the checkout).
1472 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1473 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1474 sort of repository-vs-workspace model as Arch, but the repository data
1475 can either be stored inside the working directory or kept elsewhere
1476 (either on the same machine or on an entirely different machine). For
1477 the purposes of Buildbot (which never commits changes), the repository
1478 is specified with a URL and a revision number.
1480 The most common way to obtain read-only access to a bzr tree is via
1481 HTTP, simply by making the repository visible through a web server
1482 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1483 process has sufficient privileges to access them. Higher performance
1484 can be obtained by running a special Bazaar-specific server. None of
1485 these matter to the buildbot: the repository URL just has to match the
1486 kind of server being used. The @code{repoURL} argument provides the
1487 location of the repository.
1489 Branches are expressed as subdirectories of the main central
1490 repository, which means that if branches are being used, the BZR step
1491 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1492 the @code{repoURL} argument.
1495 @uref{http://darcs.net/, Darcs} doesn't really have the
1496 notion of a single master repository. Nor does it really have
1497 branches. In Darcs, each working directory is also a repository, and
1498 there are operations to push and pull patches from one of these
1499 @code{repositories} to another. For the Buildbot's purposes, all you
1500 need to do is specify the URL of a repository that you want to build
1501 from. The build slave will then pull the latest patches from that
1502 repository and build them. Multiple branches are implemented by using
1503 multiple repositories (possibly living on the same server).
1505 Builders which use Darcs therefore have a static @code{repourl} which
1506 specifies the location of the repository. If branches are being used,
1507 the source Step is instead configured with a @code{baseURL} and a
1508 @code{defaultBranch}, and the two strings are simply concatenated
1509 together to obtain the repository's URL. Each build then has a
1510 specific branch which replaces @code{defaultBranch}, or just uses the
1511 default one. Instead of a revision number, each build can have a
1512 ``context'', which is a string that records all the patches that are
1513 present in a given tree (this is the output of @command{darcs changes
1514 --context}, and is considerably less concise than, e.g. Subversion's
1515 revision number, but the patch-reordering flexibility of Darcs makes
1516 it impossible to provide a shorter useful specification).
1518 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1519 each branch is stored in a separate repository. The @code{repourl},
1520 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1521 same way as with Darcs. The ``revision'', however, is the hash
1522 identifier returned by @command{hg identify}.
1524 @uref{http://git.or.cz/, Git} also follows a decentralized model, and
1525 each repository can have several branches and tags. The source Step is
1526 configured with a static @code{repourl} which specifies the location
1527 of the repository. In addition, an optional @code{branch} parameter
1528 can be specified to check out code from a specific branch instead of
1529 the default ``master'' branch. The ``revision'' is specified as a SHA1
1530 hash as returned by e.g. @command{git rev-parse}. No attempt is made
1531 to ensure that the specified revision is actually a subset of the
1532 specified branch.
1535 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1536 @subsection Attributes of Changes
1538 @heading Who
1540 Each Change has a @code{who} attribute, which specifies which
1541 developer is responsible for the change. This is a string which comes
1542 from a namespace controlled by the VC repository. Frequently this
1543 means it is a username on the host which runs the repository, but not
1544 all VC systems require this (Arch, for example, uses a fully-qualified
1545 @code{Arch ID}, which looks like an email address, as does Darcs).
1546 Each StatusNotifier will map the @code{who} attribute into something
1547 appropriate for their particular means of communication: an email
1548 address, an IRC handle, etc.
1550 @heading Files
1552 It also has a list of @code{files}, which are just the tree-relative
1553 filenames of any files that were added, deleted, or modified for this
1554 Change. These filenames are used by the @code{isFileImportant}
1555 function (in the Scheduler) to decide whether it is worth triggering a
1556 new build or not, e.g. the function could use
1557 @code{filename.endswith(".c")} to only run a build if a C file were
1558 checked in. Certain BuildSteps can also use the list of changed files
1559 to run a more targeted series of tests, e.g. the
1560 @code{python_twisted.Trial} step can run just the unit tests that
1561 provide coverage for the modified .py files instead of running the
1562 full test suite.
1564 @heading Comments
1566 The Change also has a @code{comments} attribute, which is a string
1567 containing any checkin comments.
1569 @heading Revision
1571 Each Change can have a @code{revision} attribute, which describes how
1572 to get a tree with a specific state: a tree which includes this Change
1573 (and all that came before it) but none that come after it. If this
1574 information is unavailable, the @code{.revision} attribute will be
1575 @code{None}. These revisions are provided by the ChangeSource, and
1576 consumed by the @code{computeSourceRevision} method in the appropriate
1577 @code{step.Source} class.
1579 @table @samp
1580 @item CVS
1581 @code{revision} is an int, seconds since the epoch
1582 @item SVN
1583 @code{revision} is an int, a transation number (r%d)
1584 @item Darcs
1585 @code{revision} is a large string, the output of @code{darcs changes --context}
1586 @item Mercurial
1587 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1588 @item Arch/Bazaar
1589 @code{revision} is the full revision ID (ending in --patch-%d)
1590 @item P4
1591 @code{revision} is an int, the transaction number
1592 @item Git
1593 @code{revision} is a short string (a SHA1 hash), the output of e.g.
1594 @code{git rev-parse}
1595 @end table
1597 @heading Branches
1599 The Change might also have a @code{branch} attribute. This indicates
1600 that all of the Change's files are in the same named branch. The
1601 Schedulers get to decide whether the branch should be built or not.
1603 For VC systems like CVS, Arch, Monotone, and Git, the @code{branch}
1604 name is unrelated to the filename. (that is, the branch name and the
1605 filename inhabit unrelated namespaces). For SVN, branches are
1606 expressed as subdirectories of the repository, so the file's
1607 ``svnurl'' is a combination of some base URL, the branch name, and the
1608 filename within the branch. (In a sense, the branch name and the
1609 filename inhabit the same namespace). Darcs branches are
1610 subdirectories of a base URL just like SVN. Mercurial branches are the
1611 same as Darcs.
1613 @table @samp
1614 @item CVS
1615 branch='warner-newfeature', files=['src/foo.c']
1616 @item SVN
1617 branch='branches/warner-newfeature', files=['src/foo.c']
1618 @item Darcs
1619 branch='warner-newfeature', files=['src/foo.c']
1620 @item Mercurial
1621 branch='warner-newfeature', files=['src/foo.c']
1622 @item Arch/Bazaar
1623 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1624 @item Git
1625 branch='warner-newfeature', files=['src/foo.c']
1626 @end table
1628 @heading Links
1630 @c TODO: who is using 'links'? how is it being used?
1632 Finally, the Change might have a @code{links} list, which is intended
1633 to provide a list of URLs to a @emph{viewcvs}-style web page that
1634 provides more detail for this Change, perhaps including the full file
1635 diffs.
1638 @node Schedulers, BuildSet, Version Control Systems, Concepts
1639 @section Schedulers
1641 @cindex Scheduler
1643 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1644 gets a copy of every incoming Change. The Schedulers are responsible
1645 for deciding when Builds should be run. Some Buildbot installations
1646 might have a single Scheduler, while others may have several, each for
1647 a different purpose.
1649 For example, a ``quick'' scheduler might exist to give immediate
1650 feedback to developers, hoping to catch obvious problems in the code
1651 that can be detected quickly. These typically do not run the full test
1652 suite, nor do they run on a wide variety of platforms. They also
1653 usually do a VC update rather than performing a brand-new checkout
1654 each time. You could have a ``quick'' scheduler which used a 30 second
1655 timeout, and feeds a single ``quick'' Builder that uses a VC
1656 @code{mode='update'} setting.
1658 A separate ``full'' scheduler would run more comprehensive tests a
1659 little while later, to catch more subtle problems. This scheduler
1660 would have a longer tree-stable-timer, maybe 30 minutes, and would
1661 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1662 @code{'clobber'}, or @code{'export'}).
1664 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1665 made by the Scheduler. Dependencies are also implemented here.
1666 Periodic builds (those which are run every N seconds rather than after
1667 new Changes arrive) are triggered by a special @code{Periodic}
1668 Scheduler subclass. The default Scheduler class can also be told to
1669 watch for specific branches, ignoring Changes on other branches. This
1670 may be useful if you have a trunk and a few release branches which
1671 should be tracked, but when you don't want to have the Buildbot pay
1672 attention to several dozen private user branches.
1674 Some Schedulers may trigger builds for other reasons, other than
1675 recent Changes. For example, a Scheduler subclass could connect to a
1676 remote buildmaster and watch for builds of a library to succeed before
1677 triggering a local build that uses that library.
1679 Each Scheduler creates and submits @code{BuildSet} objects to the
1680 @code{BuildMaster}, which is then responsible for making sure the
1681 individual @code{BuildRequests} are delivered to the target
1682 @code{Builders}.
1684 @code{Scheduler} instances are activated by placing them in the
1685 @code{c['schedulers']} list in the buildmaster config file. Each
1686 Scheduler has a unique name.
1689 @node BuildSet, BuildRequest, Schedulers, Concepts
1690 @section BuildSet
1692 @cindex BuildSet
1694 A @code{BuildSet} is the name given to a set of Builds that all
1695 compile/test the same version of the tree on multiple Builders. In
1696 general, all these component Builds will perform the same sequence of
1697 Steps, using the same source code, but on different platforms or
1698 against a different set of libraries.
1700 The @code{BuildSet} is tracked as a single unit, which fails if any of
1701 the component Builds have failed, and therefore can succeed only if
1702 @emph{all} of the component Builds have succeeded. There are two kinds
1703 of status notification messages that can be emitted for a BuildSet:
1704 the @code{firstFailure} type (which fires as soon as we know the
1705 BuildSet will fail), and the @code{Finished} type (which fires once
1706 the BuildSet has completely finished, regardless of whether the
1707 overall set passed or failed).
1709 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1710 (branch, revision, changes, patch), some of which may be None, and a
1711 list of Builders on which it is to be run. They are then given to the
1712 BuildMaster, which is responsible for creating a separate
1713 @code{BuildRequest} for each Builder.
1715 There are a couple of different likely values for the
1716 @code{SourceStamp}:
1718 @table @code
1719 @item (revision=None, changes=[CHANGES], patch=None)
1720 This is a @code{SourceStamp} used when a series of Changes have
1721 triggered a build. The VC step will attempt to check out a tree that
1722 contains CHANGES (and any changes that occurred before CHANGES, but
1723 not any that occurred after them).
1725 @item (revision=None, changes=None, patch=None)
1726 This builds the most recent code on the default branch. This is the
1727 sort of @code{SourceStamp} that would be used on a Build that was
1728 triggered by a user request, or a Periodic scheduler. It is also
1729 possible to configure the VC Source Step to always check out the
1730 latest sources rather than paying attention to the Changes in the
1731 SourceStamp, which will result in same behavior as this.
1733 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1734 This builds the most recent code on the given BRANCH. Again, this is
1735 generally triggered by a user request or Periodic build.
1737 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1738 This checks out the tree at the given revision REV, then applies a
1739 patch (using @code{patch -pLEVEL <DIFF}). The @ref{try} feature uses
1740 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1741 step is bypassed.
1743 @end table
1745 The buildmaster is responsible for turning the @code{BuildSet} into a
1746 set of @code{BuildRequest} objects and queueing them on the
1747 appropriate Builders.
1750 @node BuildRequest, Builder, BuildSet, Concepts
1751 @section BuildRequest
1753 @cindex BuildRequest
1755 A @code{BuildRequest} is a request to build a specific set of sources
1756 on a single specific @code{Builder}. Each @code{Builder} runs the
1757 @code{BuildRequest} as soon as it can (i.e. when an associated
1758 buildslave becomes free). @code{BuildRequest}s are prioritized from
1759 oldest to newest, so when a buildslave becomes free, the
1760 @code{Builder} with the oldest @code{BuildRequest} is run.
1762 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1763 The actual process of running the build (the series of Steps that will
1764 be executed) is implemented by the @code{Build} object. In this future
1765 this might be changed, to have the @code{Build} define @emph{what}
1766 gets built, and a separate @code{BuildProcess} (provided by the
1767 Builder) to define @emph{how} it gets built.
1769 @code{BuildRequest} is created with optional @code{Properties}.  One
1770 of these, @code{owner}, is collected by the resultant @code{Build} and
1771 added to the set of @emph{interested users} to which status
1772 notifications will be sent, depending on the configuration for each
1773 status object.
1775 The @code{BuildRequest} may be mergeable with other compatible
1776 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1777 will generally be mergeable. Builds that are triggered by user
1778 requests are generally not, unless they are multiple requests to build
1779 the @emph{latest sources} of the same branch.
1781 @node Builder, Users, BuildRequest, Concepts
1782 @section Builder
1784 @cindex Builder
1786 The @code{Builder} is a long-lived object which controls all Builds of
1787 a given type. Each one is created when the config file is first
1788 parsed, and lives forever (or rather until it is removed from the
1789 config file). It mediates the connections to the buildslaves that do
1790 all the work, and is responsible for creating the @code{Build} objects
1791 that decide @emph{how} a build is performed (i.e., which steps are
1792 executed in what order).
1794 Each @code{Builder} gets a unique name, and the path name of a
1795 directory where it gets to do all its work (there is a
1796 buildmaster-side directory for keeping status information, as well as
1797 a buildslave-side directory where the actual checkout/compile/test
1798 commands are executed). It also gets a @code{BuildFactory}, which is
1799 responsible for creating new @code{Build} instances: because the
1800 @code{Build} instance is what actually performs each build, choosing
1801 the @code{BuildFactory} is the way to specify what happens each time a
1802 build is done.
1804 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1805 A @code{Builder} which is used to perform OS-X builds (as opposed to
1806 Linux or Solaris builds) should naturally be associated with an
1807 OS-X-based buildslave.
1809 A @code{Builder} may be given a set of environment variables to be used
1810 in its @pxref{ShellCommand}s. These variables will override anything in the
1811 buildslave's environment. Variables passed directly to a ShellCommand will
1812 override variables of the same name passed to the Builder.
1814 For example, if you a pool of identical slaves it is often easier to manage
1815 variables like PATH from Buildbot rather than manually editing it inside of
1816 the slaves' environment.
1818 @example
1819 f = factory.BuildFactory
1820 f.addStep(ShellCommand(
1821               command=['bash', './configure']))
1822 f.addStep(Compile())
1824 c['builders'] = [
1825   @{'name': 'test', 'slavenames': ['slave1', 'slave2', 'slave3', 'slave4',
1826                                    'slave5', 'slave6'],
1827     'builddir': 'test', 'factory': f',
1828     'env': @{'PATH': '/opt/local/bin:/opt/app/bin:/usr/local/bin:/usr/bin'@}@}
1830 @end example
1832 @node Users, Build Properties, Builder, Concepts
1833 @section Users
1835 @cindex Users
1837 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1838 the world consists of a set of developers, each of whom can be
1839 described by a couple of simple attributes. These developers make
1840 changes to the source code, causing builds which may succeed or fail.
1842 Each developer is primarily known through the source control system. Each
1843 Change object that arrives is tagged with a @code{who} field that
1844 typically gives the account name (on the repository machine) of the user
1845 responsible for that change. This string is the primary key by which the
1846 User is known, and is displayed on the HTML status pages and in each Build's
1847 ``blamelist''.
1849 To do more with the User than just refer to them, this username needs to
1850 be mapped into an address of some sort. The responsibility for this mapping
1851 is left up to the status module which needs the address. The core code knows
1852 nothing about email addresses or IRC nicknames, just user names.
1854 @menu
1855 * Doing Things With Users::
1856 * Email Addresses::
1857 * IRC Nicknames::
1858 * Live Status Clients::
1859 @end menu
1861 @node Doing Things With Users, Email Addresses, Users, Users
1862 @subsection Doing Things With Users
1864 Each Change has a single User who is responsible for that Change. Most
1865 Builds have a set of Changes: the Build represents the first time these
1866 Changes have been built and tested by the Buildbot. The build has a
1867 ``blamelist'' that consists of a simple union of the Users responsible
1868 for all the Build's Changes.
1870 The Build provides (through the IBuildStatus interface) a list of Users
1871 who are ``involved'' in the build. For now this is equal to the
1872 blamelist, but in the future it will be expanded to include a ``build
1873 sheriff'' (a person who is ``on duty'' at that time and responsible for
1874 watching over all builds that occur during their shift), as well as
1875 per-module owners who simply want to keep watch over their domain (chosen by
1876 subdirectory or a regexp matched against the filenames pulled out of the
1877 Changes). The Involved Users are those who probably have an interest in the
1878 results of any given build.
1880 In the future, Buildbot will acquire the concept of ``Problems'',
1881 which last longer than builds and have beginnings and ends. For example, a
1882 test case which passed in one build and then failed in the next is a
1883 Problem. The Problem lasts until the test case starts passing again, at
1884 which point the Problem is said to be ``resolved''.
1886 If there appears to be a code change that went into the tree at the
1887 same time as the test started failing, that Change is marked as being
1888 resposible for the Problem, and the user who made the change is added
1889 to the Problem's ``Guilty'' list. In addition to this user, there may
1890 be others who share responsibility for the Problem (module owners,
1891 sponsoring developers). In addition to the Responsible Users, there
1892 may be a set of Interested Users, who take an interest in the fate of
1893 the Problem.
1895 Problems therefore have sets of Users who may want to be kept aware of
1896 the condition of the problem as it changes over time. If configured, the
1897 Buildbot can pester everyone on the Responsible list with increasing
1898 harshness until the problem is resolved, with the most harshness reserved
1899 for the Guilty parties themselves. The Interested Users may merely be told
1900 when the problem starts and stops, as they are not actually responsible for
1901 fixing anything.
1903 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1904 @subsection Email Addresses
1906 The @code{buildbot.status.mail.MailNotifier} class
1907 (@pxref{MailNotifier}) provides a status target which can send email
1908 about the results of each build. It accepts a static list of email
1909 addresses to which each message should be delivered, but it can also
1910 be configured to send mail to the Build's Interested Users. To do
1911 this, it needs a way to convert User names into email addresses.
1913 For many VC systems, the User Name is actually an account name on the
1914 system which hosts the repository. As such, turning the name into an
1915 email address is a simple matter of appending
1916 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1917 (for example the preferred email address may be at ``project.org''
1918 despite the repository host being named ``cvs.project.org''), and some
1919 VC systems have full separation between the concept of a user and that
1920 of an account on the repository host (like Perforce). Some systems
1921 (like Arch) put a full contact email address in every change.
1923 To convert these names to addresses, the MailNotifier uses an EmailLookup
1924 object. This provides a .getAddress method which accepts a name and
1925 (eventually) returns an address. The default @code{MailNotifier}
1926 module provides an EmailLookup which simply appends a static string,
1927 configurable when the notifier is created. To create more complex behaviors
1928 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1929 determine a preferred address for the developer), provide a different object
1930 as the @code{lookup} argument.
1932 In the future, when the Problem mechanism has been set up, the Buildbot
1933 will need to send mail to arbitrary Users. It will do this by locating a
1934 MailNotifier-like object among all the buildmaster's status targets, and
1935 asking it to send messages to various Users. This means the User-to-address
1936 mapping only has to be set up once, in your MailNotifier, and every email
1937 message the buildbot emits will take advantage of it.
1939 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1940 @subsection IRC Nicknames
1942 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1943 provides a status target which can announce the results of each build. It
1944 also provides an interactive interface by responding to online queries
1945 posted in the channel or sent as private messages.
1947 In the future, the buildbot can be configured map User names to IRC
1948 nicknames, to watch for the recent presence of these nicknames, and to
1949 deliver build status messages to the interested parties. Like
1950 @code{MailNotifier} does for email addresses, the @code{IRC} object
1951 will have an @code{IRCLookup} which is responsible for nicknames. The
1952 mapping can be set up statically, or it can be updated by online users
1953 themselves (by claiming a username with some kind of ``buildbot: i am
1954 user warner'' commands).
1956 Once the mapping is established, the rest of the buildbot can ask the
1957 @code{IRC} object to send messages to various users. It can report on
1958 the likelihood that the user saw the given message (based upon how long the
1959 user has been inactive on the channel), which might prompt the Problem
1960 Hassler logic to send them an email message instead.
1962 @node Live Status Clients,  , IRC Nicknames, Users
1963 @subsection Live Status Clients
1965 The Buildbot also offers a PB-based status client interface which can
1966 display real-time build status in a GUI panel on the developer's desktop.
1967 This interface is normally anonymous, but it could be configured to let the
1968 buildmaster know @emph{which} developer is using the status client. The
1969 status client could then be used as a message-delivery service, providing an
1970 alternative way to deliver low-latency high-interruption messages to the
1971 developer (like ``hey, you broke the build'').
1973 @node Build Properties,  , Users, Concepts
1974 @section Build Properties
1975 @cindex Properties
1977 Each build has a set of ``Build Properties'', which can be used by its
1978 BuildStep to modify their actions.  These properties, in the form of
1979 key-value pairs, provide a general framework for dynamically altering
1980 the behavior of a build based on its circumstances.
1982 Properties come from a number of places:
1983 @itemize
1984 @item global configuration --
1985 These properties apply to all builds.
1986 @item schedulers --
1987 A scheduler can specify properties available to all the builds it
1988 starts.
1989 @item buildslaves --
1990 A buildslave can pass properties on to the builds it performs.
1991 @item builds --
1992 A build automatically sets a number of properties on itself.
1993 @item steps --
1994 Steps of a build can set properties that are available to subsequent
1995 steps.  In particular, source steps set a number of properties.
1996 @end itemize
1998 Properties are very flexible, and can be used to implement all manner
1999 of functionality.  Here are some examples:
2001 Most Source steps record the revision that they checked out in
2002 the @code{got_revision} property.  A later step could use this
2003 property to specify the name of a fully-built tarball, dropped in an
2004 easily-acessible directory for later testing.
2006 Some projects want to perform nightly builds as well as in response
2007 to committed changes.  Such a project would run two schedulers,
2008 both pointing to the same set of builders, but could provide an
2009 @code{is_nightly} property so that steps can distinguish the nightly
2010 builds, perhaps to run more resource-intensive tests.
2012 Some projects have different build processes on different systems.
2013 Rather than create a build factory for each slave, the steps can use
2014 buildslave properties to identify the unique aspects of each slave
2015 and adapt the build process dynamically.
2017 @node Configuration, Getting Source Code Changes, Concepts, Top
2018 @chapter Configuration
2020 @cindex Configuration
2022 The buildbot's behavior is defined by the ``config file'', which
2023 normally lives in the @file{master.cfg} file in the buildmaster's base
2024 directory (but this can be changed with an option to the
2025 @code{buildbot create-master} command). This file completely specifies
2026 which Builders are to be run, which slaves they should use, how
2027 Changes should be tracked, and where the status information is to be
2028 sent. The buildmaster's @file{buildbot.tac} file names the base
2029 directory; everything else comes from the config file.
2031 A sample config file was installed for you when you created the
2032 buildmaster, but you will need to edit it before your buildbot will do
2033 anything useful.
2035 This chapter gives an overview of the format of this file and the
2036 various sections in it. You will need to read the later chapters to
2037 understand how to fill in each section properly.
2039 @menu
2040 * Config File Format::
2041 * Loading the Config File::
2042 * Testing the Config File::
2043 * Defining the Project::
2044 * Change Sources and Schedulers::
2045 * Merging BuildRequests::
2046 * Setting the slaveport::
2047 * Buildslave Specifiers::
2048 * On-Demand ("Latent") Buildslaves::
2049 * Defining Global Properties::
2050 * Defining Builders::
2051 * Defining Status Targets::
2052 * Debug options::
2053 @end menu
2055 @node Config File Format, Loading the Config File, Configuration, Configuration
2056 @section Config File Format
2058 The config file is, fundamentally, just a piece of Python code which
2059 defines a dictionary named @code{BuildmasterConfig}, with a number of
2060 keys that are treated specially. You don't need to know Python to do
2061 basic configuration, though, you can just copy the syntax of the
2062 sample file. If you @emph{are} comfortable writing Python code,
2063 however, you can use all the power of a full programming language to
2064 achieve more complicated configurations.
2066 The @code{BuildmasterConfig} name is the only one which matters: all
2067 other names defined during the execution of the file are discarded.
2068 When parsing the config file, the Buildmaster generally compares the
2069 old configuration with the new one and performs the minimum set of
2070 actions necessary to bring the buildbot up to date: Builders which are
2071 not changed are left untouched, and Builders which are modified get to
2072 keep their old event history.
2074 Basic Python syntax: comments start with a hash character (``#''),
2075 tuples are defined with @code{(parenthesis, pairs)}, arrays are
2076 defined with @code{[square, brackets]}, tuples and arrays are mostly
2077 interchangeable. Dictionaries (data structures which map ``keys'' to
2078 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
2079 'key2': 'value2'@} }. Function calls (and object instantiation) can use
2080 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
2082 The config file starts with a series of @code{import} statements,
2083 which make various kinds of Steps and Status targets available for
2084 later use. The main @code{BuildmasterConfig} dictionary is created,
2085 then it is populated with a variety of keys. These keys are broken
2086 roughly into the following sections, each of which is documented in
2087 the rest of this chapter:
2089 @itemize @bullet
2090 @item
2091 Project Definitions
2092 @item
2093 Change Sources / Schedulers
2094 @item
2095 Slaveport
2096 @item
2097 Buildslave Configuration
2098 @item
2099 Builders / Interlocks
2100 @item
2101 Status Targets
2102 @item
2103 Debug options
2104 @end itemize
2106 The config file can use a few names which are placed into its namespace:
2108 @table @code
2109 @item basedir
2110 the base directory for the buildmaster. This string has not been
2111 expanded, so it may start with a tilde. It needs to be expanded before
2112 use. The config file is located in
2113 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
2115 @end table
2118 @node Loading the Config File, Testing the Config File, Config File Format, Configuration
2119 @section Loading the Config File
2121 The config file is only read at specific points in time. It is first
2122 read when the buildmaster is launched. Once it is running, there are
2123 various ways to ask it to reload the config file. If you are on the
2124 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
2125 it: the @command{buildbot} tool has a shortcut for this:
2127 @example
2128 buildbot reconfig @var{BASEDIR}
2129 @end example
2131 This command will show you all of the lines from @file{twistd.log}
2132 that relate to the reconfiguration. If there are any problems during
2133 the config-file reload, they will be displayed in these lines.
2135 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
2136 ``Reload .cfg'' button which will also trigger a reload. In the
2137 future, there will be other ways to accomplish this step (probably a
2138 password-protected button on the web page, as well as a privileged IRC
2139 command).
2141 When reloading the config file, the buildmaster will endeavor to
2142 change as little as possible about the running system. For example,
2143 although old status targets may be shut down and new ones started up,
2144 any status targets that were not changed since the last time the
2145 config file was read will be left running and untouched. Likewise any
2146 Builders which have not been changed will be left running. If a
2147 Builder is modified (say, the build process is changed) while a Build
2148 is currently running, that Build will keep running with the old
2149 process until it completes. Any previously queued Builds (or Builds
2150 which get queued after the reconfig) will use the new process.
2152 @node Testing the Config File, Defining the Project, Loading the Config File, Configuration
2153 @section Testing the Config File
2155 To verify that the config file is well-formed and contains no
2156 deprecated or invalid elements, use the ``checkconfig'' command:
2158 @example
2159 % buildbot checkconfig master.cfg
2160 Config file is good!
2161 @end example
2163 If the config file has deprecated features (perhaps because you've
2164 upgraded the buildmaster and need to update the config file to match),
2165 they will be announced by checkconfig. In this case, the config file
2166 will work, but you should really remove the deprecated items and use
2167 the recommended replacements instead:
2169 @example
2170 % buildbot checkconfig master.cfg
2171 /usr/lib/python2.4/site-packages/buildbot/master.py:559: DeprecationWarning: c['sources'] is
2172 deprecated as of 0.7.6 and will be removed by 0.8.0 . Please use c['change_source'] instead.
2173   warnings.warn(m, DeprecationWarning)
2174 Config file is good!
2175 @end example
2177 If the config file is simply broken, that will be caught too:
2179 @example
2180 % buildbot checkconfig master.cfg
2181 Traceback (most recent call last):
2182   File "/usr/lib/python2.4/site-packages/buildbot/scripts/runner.py", line 834, in doCheckConfig
2183     ConfigLoader(configFile)
2184   File "/usr/lib/python2.4/site-packages/buildbot/scripts/checkconfig.py", line 31, in __init__
2185     self.loadConfig(configFile)
2186   File "/usr/lib/python2.4/site-packages/buildbot/master.py", line 480, in loadConfig
2187     exec f in localDict
2188   File "/home/warner/BuildBot/master/foolscap/master.cfg", line 90, in ?
2189     c[bogus] = "stuff"
2190 NameError: name 'bogus' is not defined
2191 @end example
2194 @node Defining the Project, Change Sources and Schedulers, Testing the Config File, Configuration
2195 @section Defining the Project
2197 There are a couple of basic settings that you use to tell the buildbot
2198 what project it is working on. This information is used by status
2199 reporters to let users find out more about the codebase being
2200 exercised by this particular Buildbot installation.
2202 @example
2203 c['projectName'] = "Buildbot"
2204 c['projectURL'] = "http://buildbot.sourceforge.net/"
2205 c['buildbotURL'] = "http://localhost:8010/"
2206 @end example
2208 @bcindex c['projectName']
2209 @code{projectName} is a short string will be used to describe the
2210 project that this buildbot is working on. For example, it is used as
2211 the title of the waterfall HTML page.
2213 @bcindex c['projectURL']
2214 @code{projectURL} is a string that gives a URL for the project as a
2215 whole. HTML status displays will show @code{projectName} as a link to
2216 @code{projectURL}, to provide a link from buildbot HTML pages to your
2217 project's home page.
2219 @bcindex c['buildbotURL']
2220 The @code{buildbotURL} string should point to the location where the
2221 buildbot's internal web server (usually the @code{html.Waterfall}
2222 page) is visible. This typically uses the port number set when you
2223 create the @code{Waterfall} object: the buildbot needs your help to
2224 figure out a suitable externally-visible host name.
2226 When status notices are sent to users (either by email or over IRC),
2227 @code{buildbotURL} will be used to create a URL to the specific build
2228 or problem that they are being notified about. It will also be made
2229 available to queriers (over IRC) who want to find out where to get
2230 more information about this buildbot.
2232 @bcindex c['logCompressionLimit']
2233 The @code{logCompressionLimit} enables bz2-compression of build logs on
2234 disk for logs that are bigger than the given size, or disables that
2235 completely if given @code{False}. The default value is 4k, which should
2236 be a reasonable default on most file systems. This setting has no impact
2237 on status plugins, and merely affects the required disk space on the
2238 master for build logs.
2241 @node Change Sources and Schedulers, Merging BuildRequests, Defining the Project, Configuration
2242 @section Change Sources and Schedulers
2244 @bcindex c['sources']
2245 @bcindex c['change_source']
2247 The @code{c['change_source']} key is the ChangeSource
2248 instance@footnote{To be precise, it is an object or a list of objects
2249 which all implement the @code{buildbot.interfaces.IChangeSource}
2250 Interface. It is unusual to have multiple ChangeSources, so this key
2251 accepts either a single ChangeSource or a sequence of them.} that
2252 defines how the buildmaster learns about source code changes. More
2253 information about what goes here is available in @xref{Getting Source
2254 Code Changes}.
2256 @example
2257 from buildbot.changes.pb import PBChangeSource
2258 c['change_source'] = PBChangeSource()
2259 @end example
2260 @bcindex c['schedulers']
2262 (note: in buildbot-0.7.5 and earlier, this key was named
2263 @code{c['sources']}, and required a list. @code{c['sources']} is
2264 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2265 future release).
2267 @code{c['schedulers']} is a list of Scheduler instances, each
2268 of which causes builds to be started on a particular set of
2269 Builders. The two basic Scheduler classes you are likely to start
2270 with are @code{Scheduler} and @code{Periodic}, but you can write a
2271 customized subclass to implement more complicated build scheduling.
2273 Scheduler arguments
2274 should always be specified by name (as keyword arguments), to allow
2275 for future expansion:
2277 @example
2278 sched = Scheduler(name="quick", builderNames=['lin', 'win'])
2279 @end example
2281 All schedulers have several arguments in common:
2283 @table @code
2284 @item name
2286 Each Scheduler must have a unique name. This is used in status
2287 displays, and is also available in the build property @code{scheduler}.
2289 @item builderNames
2291 This is the set of builders which this scheduler should trigger, specified
2292 as a list of names (strings).
2294 @item properties
2295 @cindex Properties
2297 This is a dictionary specifying properties that will be transmitted
2298 to all builds started by this scheduler.
2300 @end table
2302 Here is a brief catalog of the available Scheduler types. All these
2303 Schedulers are classes in @code{buildbot.scheduler}, and the
2304 docstrings there are the best source of documentation on the arguments
2305 taken by each one.
2307 @menu
2308 * Scheduler Scheduler::
2309 * AnyBranchScheduler::
2310 * Dependent Scheduler::
2311 * Periodic Scheduler::
2312 * Nightly Scheduler::
2313 * Try Schedulers::
2314 * Triggerable Scheduler::
2315 @end menu
2317 @node Scheduler Scheduler, AnyBranchScheduler, Change Sources and Schedulers, Change Sources and Schedulers
2318 @subsection Scheduler Scheduler
2319 @slindex buildbot.scheduler.Scheduler
2321 This is the original and still most popular Scheduler class. It follows
2322 exactly one branch, and starts a configurable tree-stable-timer after
2323 each change on that branch. When the timer expires, it starts a build
2324 on some set of Builders. The Scheduler accepts a @code{fileIsImportant}
2325 function which can be used to ignore some Changes if they do not
2326 affect any ``important'' files.
2328 The arguments to this scheduler are:
2330 @table @code
2331 @item name
2333 @item builderNames
2335 @item properties
2337 @item branch
2338 This Scheduler will pay attention to a single branch, ignoring Changes
2339 that occur on other branches. Setting @code{branch} equal to the
2340 special value of @code{None} means it should only pay attention to
2341 the default branch. Note that @code{None} is a keyword, not a string,
2342 so you want to use @code{None} and not @code{"None"}.
2344 @item treeStableTimer
2345 The Scheduler will wait for this many seconds before starting the
2346 build. If new changes are made during this interval, the timer will be
2347 restarted, so really the build will be started after a change and then
2348 after this many seconds of inactivity.
2350 @item fileIsImportant
2351 A callable which takes one argument, a Change instance, and returns
2352 @code{True} if the change is worth building, and @code{False} if
2353 it is not.  Unimportant Changes are accumulated until the build is
2354 triggered by an important change.  The default value of None means
2355 that all Changes are important.
2356 @end table
2358 Example:
2360 @example
2361 from buildbot import scheduler
2362 quick = scheduler.Scheduler(name="quick",
2363                     branch=None,
2364                     treeStableTimer=60,
2365                     builderNames=["quick-linux", "quick-netbsd"])
2366 full = scheduler.Scheduler(name="full",
2367                     branch=None,
2368                     treeStableTimer=5*60,
2369                     builderNames=["full-linux", "full-netbsd", "full-OSX"])
2370 c['schedulers'] = [quick, full]
2371 @end example
2373 In this example, the two ``quick'' builders are triggered 60 seconds
2374 after the tree has been changed. The ``full'' builds do not run quite
2375 so quickly (they wait 5 minutes), so hopefully if the quick builds
2376 fail due to a missing file or really simple typo, the developer can
2377 discover and fix the problem before the full builds are started. Both
2378 Schedulers only pay attention to the default branch: any changes
2379 on other branches are ignored by these Schedulers. Each Scheduler
2380 triggers a different set of Builders, referenced by name.
2382 @node AnyBranchScheduler, Dependent Scheduler, Scheduler Scheduler, Change Sources and Schedulers
2383 @subsection AnyBranchScheduler
2384 @slindex buildbot.scheduler.AnyBranchScheduler
2386 This scheduler uses a tree-stable-timer like the default one, but
2387 follows multiple branches at once. Each branch gets a separate timer.
2389 The arguments to this scheduler are:
2391 @table @code
2392 @item name
2394 @item builderNames
2396 @item properties
2398 @item branches
2399 This Scheduler will pay attention to any number of branches, ignoring
2400 Changes that occur on other branches. Branches are specified just as
2401 for the @code{Scheduler} class.
2403 @item treeStableTimer
2404 The Scheduler will wait for this many seconds before starting the
2405 build. If new changes are made during this interval, the timer will be
2406 restarted, so really the build will be started after a change and then
2407 after this many seconds of inactivity.
2409 @item fileIsImportant
2410 A callable which takes one argument, a Change instance, and returns
2411 @code{True} if the change is worth building, and @code{False} if
2412 it is not.  Unimportant Changes are accumulated until the build is
2413 triggered by an important change.  The default value of None means
2414 that all Changes are important.
2415 @end table
2417 @node Dependent Scheduler, Periodic Scheduler, AnyBranchScheduler, Change Sources and Schedulers
2418 @subsection Dependent Scheduler
2419 @cindex Dependent
2420 @cindex Dependencies
2421 @slindex buildbot.scheduler.Dependent
2423 It is common to wind up with one kind of build which should only be
2424 performed if the same source code was successfully handled by some
2425 other kind of build first. An example might be a packaging step: you
2426 might only want to produce .deb or RPM packages from a tree that was
2427 known to compile successfully and pass all unit tests. You could put
2428 the packaging step in the same Build as the compile and testing steps,
2429 but there might be other reasons to not do this (in particular you
2430 might have several Builders worth of compiles/tests, but only wish to
2431 do the packaging once). Another example is if you want to skip the
2432 ``full'' builds after a failing ``quick'' build of the same source
2433 code. Or, if one Build creates a product (like a compiled library)
2434 that is used by some other Builder, you'd want to make sure the
2435 consuming Build is run @emph{after} the producing one.
2437 You can use ``Dependencies'' to express this relationship
2438 to the Buildbot. There is a special kind of Scheduler named
2439 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2440 for builds to complete successfully (on all of its Builders). Each time
2441 that happens, the same source code (i.e. the same @code{SourceStamp})
2442 will be used to start a new set of builds, on a different set of
2443 Builders. This ``downstream'' scheduler doesn't pay attention to
2444 Changes at all. It only pays attention to the upstream scheduler.
2446 If the build fails on any of the Builders in the upstream set,
2447 the downstream builds will not fire.  Note that, for SourceStamps
2448 generated by a ChangeSource, the @code{revision} is None, meaning HEAD.
2449 If any changes are committed between the time the upstream scheduler
2450 begins its build and the time the dependent scheduler begins its
2451 build, then those changes will be included in the downstream build.
2452 See the @pxref{Triggerable Scheduler} for a more flexible dependency
2453 mechanism that can avoid this problem.
2455 The arguments to this scheduler are:
2457 @table @code
2458 @item name
2460 @item builderNames
2462 @item properties
2464 @item upstream
2465 The upstream scheduler to watch.  Note that this is an ``instance'',
2466 not the name of the scheduler.
2467 @end table
2469 Example:
2471 @example
2472 from buildbot import scheduler
2473 tests = scheduler.Scheduler("just-tests", None, 5*60,
2474                             ["full-linux", "full-netbsd", "full-OSX"])
2475 package = scheduler.Dependent("build-package",
2476                               tests, # upstream scheduler -- no quotes!
2477                               ["make-tarball", "make-deb", "make-rpm"])
2478 c['schedulers'] = [tests, package]
2479 @end example
2481 @node Periodic Scheduler, Nightly Scheduler, Dependent Scheduler, Change Sources and Schedulers
2482 @subsection Periodic Scheduler
2483 @slindex buildbot.scheduler.Periodic
2485 This simple scheduler just triggers a build every N seconds.
2487 The arguments to this scheduler are:
2489 @table @code
2490 @item name
2492 @item builderNames
2494 @item properties
2496 @item periodicBuildTimer
2497 The time, in seconds, after which to start a build.
2498 @end table
2500 Example:
2502 @example
2503 from buildbot import scheduler
2504 nightly = scheduler.Periodic(name="nightly",
2505                 builderNames=["full-solaris"],
2506                 periodicBuildTimer=24*60*60)
2507 c['schedulers'] = [nightly]
2508 @end example
2510 The Scheduler in this example just runs the full solaris build once
2511 per day. Note that this Scheduler only lets you control the time
2512 between builds, not the absolute time-of-day of each Build, so this
2513 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2514 depending upon when it was first activated.
2516 @node Nightly Scheduler, Try Schedulers, Periodic Scheduler, Change Sources and Schedulers
2517 @subsection Nightly Scheduler
2518 @slindex buildbot.scheduler.Nightly
2520 This is highly configurable periodic build scheduler, which triggers
2521 a build at particular times of day, week, month, or year. The
2522 configuration syntax is very similar to the well-known @code{crontab}
2523 format, in which you provide values for minute, hour, day, and month
2524 (some of which can be wildcards), and a build is triggered whenever
2525 the current time matches the given constraints. This can run a build
2526 every night, every morning, every weekend, alternate Thursdays,
2527 on your boss's birthday, etc.
2529 Pass some subset of @code{minute}, @code{hour}, @code{dayOfMonth},
2530 @code{month}, and @code{dayOfWeek}; each may be a single number or
2531 a list of valid values. The builds will be triggered whenever the
2532 current time matches these values. Wildcards are represented by a
2533 '*' string. All fields default to a wildcard except 'minute', so
2534 with no fields this defaults to a build every hour, on the hour.
2535 The full list of parameters is:
2537 @table @code
2538 @item name
2540 @item builderNames
2542 @item properties
2544 @item branch
2545 The branch to build, just as for @code{Scheduler}.
2547 @item minute
2548 The minute of the hour on which to start the build.  This defaults
2549 to 0, meaning an hourly build.
2551 @item hour
2552 The hour of the day on which to start the build, in 24-hour notation.
2553 This defaults to *, meaning every hour.
2555 @item month
2556 The month in which to start the build, with January = 1.  This defaults
2557 to *, meaning every month.
2559 @item dayOfWeek
2560 The day of the week to start a build, with Monday = 0.  This defauls
2561 to *, meaning every day of the week.
2563 @item onlyIfChanged
2564 If this is true, then builds will not be scheduled at the designated time
2565 unless the source has changed since the previous build.
2566 @end table
2568 For example, the following master.cfg clause will cause a build to be
2569 started every night at 3:00am:
2571 @example
2572 s = scheduler.Nightly(name='nightly',
2573         builderNames=['builder1', 'builder2'],
2574         hour=3,
2575         minute=0)
2576 @end example
2578 This scheduler will perform a build each monday morning at 6:23am and
2579 again at 8:23am, but only if someone has committed code in the interim:
2581 @example
2582 s = scheduler.Nightly(name='BeforeWork',
2583          builderNames=['builder1'],
2584          dayOfWeek=0,
2585          hour=[6,8],
2586          minute=23,
2587          onlyIfChanged=True)
2588 @end example
2590 The following runs a build every two hours, using Python's @code{range}
2591 function:
2593 @example
2594 s = Nightly(name='every2hours',
2595         builderNames=['builder1'],
2596         hour=range(0, 24, 2))
2597 @end example
2599 Finally, this example will run only on December 24th:
2601 @example
2602 s = Nightly(name='SleighPreflightCheck',
2603         builderNames=['flying_circuits', 'radar'],
2604         month=12,
2605         dayOfMonth=24,
2606         hour=12,
2607         minute=0)
2608 @end example
2610 @node Try Schedulers, Triggerable Scheduler, Nightly Scheduler, Change Sources and Schedulers
2611 @subsection Try Schedulers
2612 @slindex buildbot.scheduler.Try_Jobdir
2613 @slindex buildbot.scheduler.Try_Userpass
2615 This scheduler allows developers to use the @code{buildbot try}
2616 command to trigger builds of code they have not yet committed. See
2617 @ref{try} for complete details.
2619 Two implementations are available: @code{Try_Jobdir} and
2620 @code{Try_Userpass}.  The former monitors a job directory, specified
2621 by the @code{jobdir} parameter, while the latter listens for PB
2622 connections on a specific @code{port}, and authenticates against
2623 @code{userport}.
2625 @node Triggerable Scheduler,  , Try Schedulers, Change Sources and Schedulers
2626 @subsection Triggerable Scheduler
2627 @cindex Triggers
2628 @slindex buildbot.scheduler.Triggerable
2630 The @code{Triggerable} scheduler waits to be triggered by a Trigger
2631 step (see @ref{Triggering Schedulers}) in another build. That step
2632 can optionally wait for the scheduler's builds to complete. This
2633 provides two advantages over Dependent schedulers. First, the same
2634 scheduler can be triggered from multiple builds. Second, the ability
2635 to wait for a Triggerable's builds to complete provides a form of
2636 "subroutine call", where one or more builds can "call" a scheduler
2637 to perform some work for them, perhaps on other buildslaves.
2639 The parameters are just the basics:
2641 @table @code
2642 @item name
2643 @item builderNames
2644 @item properties
2645 @end table
2647 This class is only useful in conjunction with the @code{Trigger} step.
2648 Here is a fully-worked example:
2650 @example
2651 from buildbot import scheduler
2652 from buildbot.steps import trigger
2654 checkin = scheduler.Scheduler(name="checkin",
2655             branch=None,
2656             treeStableTimer=5*60,
2657             builderNames=["checkin"])
2658 nightly = scheduler.Nightly(name='nightly',
2659             builderNames=['nightly'],
2660             hour=3,
2661             minute=0)
2663 mktarball = scheduler.Triggerable(name="mktarball",
2664                 builderNames=["mktarball"])
2665 build = scheduler.Triggerable(name="build-all-platforms",
2666                 builderNames=["build-all-platforms"])
2667 test = scheduler.Triggerable(name="distributed-test",
2668                 builderNames=["distributed-test"])
2669 package = scheduler.Triggerable(name="package-all-platforms",
2670                 builderNames=["package-all-platforms"])
2672 c['schedulers'] = [checkin, nightly, build, test, package]
2674 # on checkin, make a tarball, build it, and test it
2675 checkin_factory = factory.BuildFactory()
2676 f.addStep(trigger.Trigger('mktarball', schedulers=['mktarball'],
2677                                        waitForFinish=True)
2678 f.addStep(trigger.Trigger('build', schedulers=['build-all-platforms'],
2679                                    waitForFinish=True)
2680 f.addStep(trigger.Trigger('test', schedulers=['distributed-test'],
2681                                   waitForFinish=True)
2683 # and every night, make a tarball, build it, and package it
2684 nightly_factory = factory.BuildFactory()
2685 f.addStep(trigger.Trigger('mktarball', schedulers=['mktarball'],
2686                                        waitForFinish=True)
2687 f.addStep(trigger.Trigger('build', schedulers=['build-all-platforms'],
2688                                    waitForFinish=True)
2689 f.addStep(trigger.Trigger('package', schedulers=['package-all-platforms'],
2690                                      waitForFinish=True)
2691 @end example
2693 @node Merging BuildRequests, Setting the slaveport, Change Sources and Schedulers, Configuration
2694 @section Merging BuildRequests
2696 @bcindex c['mergeRequests']
2698 By default, buildbot merges BuildRequests that have the compatible
2699 SourceStamps. Starting with 0.7.10, this behaviour can be customized.
2701 @quotation Note
2702 This feature is experimental, please provide feedback in the mailing
2703 list on this. Future versions of buildbot might change the way this
2704 functionality is exposed, too.
2705 @end quotation
2707 The default behaviour to merge BuildRequests with matching SourceStamps
2708 can be overwritten by:
2710 @example
2711 def mergeRequests(builder, req1, req2):
2712     """Don't merge buildrequest at all, for example"""
2713     return False
2714 c['mergeRequests'] = mergeRequests
2715 @end example
2717 @node Setting the slaveport, Buildslave Specifiers, Merging BuildRequests, Configuration
2718 @section Setting the slaveport
2720 @bcindex c['slavePortnum']
2722 The buildmaster will listen on a TCP port of your choosing for
2723 connections from buildslaves. It can also use this port for
2724 connections from remote Change Sources, status clients, and debug
2725 tools. This port should be visible to the outside world, and you'll
2726 need to tell your buildslave admins about your choice.
2728 It does not matter which port you pick, as long it is externally
2729 visible, however you should probably use something larger than 1024,
2730 since most operating systems don't allow non-root processes to bind to
2731 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2732 box of some sort, you may have to configure your firewall to permit
2733 inbound connections to this port.
2735 @example
2736 c['slavePortnum'] = 10000
2737 @end example
2739 @code{c['slavePortnum']} is a @emph{strports} specification string,
2740 defined in the @code{twisted.application.strports} module (try
2741 @command{pydoc twisted.application.strports} to get documentation on
2742 the format). This means that you can have the buildmaster listen on a
2743 localhost-only port by doing:
2745 @example
2746 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2747 @end example
2749 This might be useful if you only run buildslaves on the same machine,
2750 and they are all configured to contact the buildmaster at
2751 @code{localhost:10000}.
2754 @node Buildslave Specifiers, On-Demand ("Latent") Buildslaves, Setting the slaveport, Configuration
2755 @section Buildslave Specifiers
2756 @bcindex c['slaves']
2758 The @code{c['slaves']} key is a list of known buildslaves. In the common case,
2759 each buildslave is defined by an instance of the BuildSlave class.  It
2760 represents a standard, manually started machine that will try to connect to
2761 the buildbot master as a slave.  Contrast these with the "on-demand" latent
2762 buildslaves, such as the Amazon Web Service Elastic Compute Cloud latent
2763 buildslave discussed below.
2765 The BuildSlave class is instantiated with two values: (slavename,
2766 slavepassword). These are the same two values that need to be provided to the
2767 buildslave administrator when they create the buildslave.
2769 The slavenames must be unique, of course. The password exists to
2770 prevent evildoers from interfering with the buildbot by inserting
2771 their own (broken) buildslaves into the system and thus displacing the
2772 real ones.
2774 Buildslaves with an unrecognized slavename or a non-matching password
2775 will be rejected when they attempt to connect, and a message
2776 describing the problem will be put in the log file (see @ref{Logfiles}).
2778 @example
2779 from buildbot.buildslave import BuildSlave
2780 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd')
2781                BuildSlave('bot-bsd', 'bsdpasswd')
2782               ]
2783 @end example
2785 @cindex Properties
2786 @code{BuildSlave} objects can also be created with an optional
2787 @code{properties} argument, a dictionary specifying properties that
2788 will be available to any builds performed on this slave.  For example:
2790 @example
2791 from buildbot.buildslave import BuildSlave
2792 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2793                     properties=@{'os':'solaris'@}),
2794               ]
2795 @end example
2797 The @code{BuildSlave} constructor can also take an optional
2798 @code{max_builds} parameter to limit the number of builds that it
2799 will execute simultaneously:
2801 @example
2802 from buildbot.buildslave import BuildSlave
2803 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2804 @end example
2806 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2807 key was used instead, and it took a list of (name, password) tuples.
2808 This key is accepted for backwards compatibility, but is deprecated as
2809 of 0.7.6 and will go away in some future release.
2811 @menu
2812 * When Buildslaves Go Missing::
2813 @end menu
2815 @node When Buildslaves Go Missing, , , Buildslave Specifiers
2816 @subsection When Buildslaves Go Missing
2818 Sometimes, the buildslaves go away. One very common reason for this is
2819 when the buildslave process is started once (manually) and left
2820 running, but then later the machine reboots and the process is not
2821 automatically restarted.
2823 If you'd like to have the administrator of the buildslave (or other
2824 people) be notified by email when the buildslave has been missing for
2825 too long, just add the @code{notify_on_missing=} argument to the
2826 @code{BuildSlave} definition:
2828 @example
2829 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2830                           notify_on_missing="bob@@example.com"),
2831               ]
2832 @end example
2834 By default, this will send email when the buildslave has been
2835 disconnected for more than one hour. Only one email per
2836 connection-loss event will be sent. To change the timeout, use
2837 @code{missing_timeout=} and give it a number of seconds (the default
2838 is 3600).
2840 You can have the buildmaster send email to multiple recipients: just
2841 provide a list of addresses instead of a single one:
2843 @example
2844 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2845                           notify_on_missing=["bob@@example.com",
2846                                              "alice@@example.org"],
2847                           missing_timeout=300, # notify after 10 minutes
2848                           ),
2849               ]
2850 @end example
2852 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2853 status target, if one is configured. This provides a way for you to
2854 control the ``from'' address of the email, as well as the relayhost
2855 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2856 configured on this buildmaster, the buildslave-missing emails will be
2857 sent using a default configuration.
2859 Note that if you want to have a MailNotifier for buildslave-missing
2860 emails but not for regular build emails, just create one with
2861 builders=[], as follows:
2863 @example
2864 from buildbot.status import mail
2865 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2866                       relayhost="smtp.example.org")
2867 c['status'].append(m)
2868 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2869                           notify_on_missing="bob@@example.com"),
2870               ]
2871 @end example
2873 @node On-Demand ("Latent") Buildslaves, Defining Global Properties, Buildslave Specifiers, Configuration
2874 @section On-Demand ("Latent") Buildslaves
2876 The standard buildbot model has slaves started manually.  The previous section
2877 described how to configure the master for this approach.
2879 Another approach is to let the buildbot master start slaves when builds are
2880 ready, on-demand.  Thanks to services such as Amazon Web Services' Elastic
2881 Compute Cloud ("AWS EC2"), this is relatively easy to set up, and can be
2882 very useful for some situations.
2884 The buildslaves that are started on-demand are called "latent" buildslaves.
2885 As of this writing, buildbot ships with an abstract base class for building
2886 latent buildslaves, and a concrete implementation for AWS EC2.
2888 @menu
2889 * Amazon Web Services Elastic Compute Cloud ("AWS EC2")::
2890 * Dangers with Latent Buildslaves::
2891 * Writing New Latent Buildslaves::
2892 @end menu
2894 @node Amazon Web Services Elastic Compute Cloud ("AWS EC2"), Dangers with Latent Buildslaves, , On-Demand ("Latent") Buildslaves
2895 @subsection Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2897 @url{http://aws.amazon.com/ec2/,,AWS EC2} is a web service that allows you to
2898 start virtual machines in an Amazon data center. Please see their website for
2899 details, incuding costs. Using the AWS EC2 latent buildslaves involves getting
2900 an EC2 account with AWS and setting up payment; customizing one or more EC2
2901 machine images ("AMIs") on your desired operating system(s) and publishing
2902 them (privately if needed); and configuring the buildbot master to know how to
2903 start your customized images for "substantiating" your latent slaves.
2905 @menu
2906 * Get an AWS EC2 Account::
2907 * Create an AMI::
2908 * Configure the Master with an EC2LatentBuildSlave::
2909 @end menu
2911 @node Get an AWS EC2 Account, Create an AMI, , Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2912 @subsubsection Get an AWS EC2 Account
2914 To start off, to use the AWS EC2 latent buildslave, you need to get an AWS
2915 developer account and sign up for EC2. These instructions may help you get
2916 started:
2918 @itemize @bullet
2919 @item
2920 Go to http://aws.amazon.com/ and click to "Sign Up Now" for an AWS account.
2922 @item
2923 Once you are logged into your account, you need to sign up for EC2.
2924 Instructions for how to do this have changed over time because Amazon changes
2925 their website, so the best advice is to hunt for it. After signing up for EC2,
2926 it may say it wants you to upload an x.509 cert. You will need this to create
2927 images (see below) but it is not technically necessary for the buildbot master
2928 configuration.
2930 @item
2931 You must enter a valid credit card before you will be able to use EC2. Do that
2932 under 'Payment Method'.
2934 @item
2935 Make sure you're signed up for EC2 by going to 'Your Account'->'Account
2936 Activity' and verifying EC2 is listed.
2937 @end itemize
2939 @node Create an AMI, Configure the Master with an EC2LatentBuildSlave, Get an AWS EC2 Account, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2940 @subsubsection Create an AMI
2942 Now you need to create an AMI and configure the master.  You may need to
2943 run through this cycle a few times to get it working, but these instructions
2944 should get you started.
2946 Creating an AMI is out of the scope of this document.  The
2947 @url{http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/,,EC2 Getting Started Guide}
2948 is a good resource for this task.  Here are a few additional hints.
2950 @itemize @bullet
2951 @item
2952 When an instance of the image starts, it needs to automatically start a
2953 buildbot slave that connects to your master (to create a buildbot slave,
2954 @pxref{Creating a buildslave}; to make a daemon,
2955 @pxref{Launching the daemons}).
2957 @item
2958 You may want to make an instance of the buildbot slave, configure it as a
2959 standard buildslave in the master (i.e., not as a latent slave), and test and
2960 debug it that way before you turn it into an AMI and convert to a latent
2961 slave in the master.
2962 @end itemize
2964 @node Configure the Master with an EC2LatentBuildSlave, , Create an AMI, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2965 @subsubsection Configure the Master with an EC2LatentBuildSlave
2967 Now let's assume you have an AMI that should work with the
2968 EC2LatentBuildSlave.  It's now time to set up your buildbot master
2969 configuration.
2971 You will need some information from your AWS account: the "Access Key Id" and
2972 the "Secret Access Key".  If you've built the AMI yourself, you probably
2973 already are familiar with these values.  If you have not, and someone has
2974 given you access to an AMI, these hints may help you find the necessary
2975 values:
2977 @itemize @bullet
2978 @item
2979 While logged into your AWS account, find the "Access Identifiers" link (either
2980 on the left, or via "Your Account" -> "Access Identifiers".
2982 @item
2983 On the page, you'll see alphanumeric values for "Your Access Key Id:" and
2984 "Your Secret Access Key:". Make a note of these. Later on, we'll call the
2985 first one your "identifier" and the second one your "secret_identifier."
2986 @end itemize
2988 When creating an EC2LatentBuildSlave in the buildbot master configuration,
2989 the first three arguments are required.  The name and password are the first
2990 two arguments, and work the same as with normal buildslaves.  The next
2991 argument specifies the type of the EC2 virtual machine (available options as
2992 of this writing include "m1.small", "m1.large", 'm1.xlarge", "c1.medium",
2993 and "c1.xlarge"; see the EC2 documentation for descriptions of these
2994 machines).
2996 Here is the simplest example of configuring an EC2 latent buildslave. It
2997 specifies all necessary remaining values explicitly in the instantiation.
2999 @example
3000 from buildbot.ec2buildslave import EC2LatentBuildSlave
3001 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3002                                    ami='ami-12345',
3003                                    identifier='publickey',
3004                                    secret_identifier='privatekey'
3005                                    )]
3006 @end example
3008 The "ami" argument specifies the AMI that the master should start.  The
3009 "identifier" argument specifies the AWS "Access Key Id," and the
3010 "secret_identifier" specifies the AWS "Secret Access Key." Both the AMI and
3011 the account information can be specified in alternate ways.
3013 Note that whoever has your identifier and secret_identifier values can request
3014 AWS work charged to your account, so these values need to be carefully
3015 protected. Another way to specify these access keys is to put them in a
3016 separate file. You can then make the access privileges stricter for this
3017 separate file, and potentially let more people read your main configuration
3018 file.
3020 By default, you can make an .ec2 directory in the home folder of the user
3021 running the buildbot master. In that directory, create a file called aws_id.
3022 The first line of that file should be your access key id; the second line
3023 should be your secret access key id. Then you can instantiate the build slave
3024 as follows.
3026 @example
3027 from buildbot.ec2buildslave import EC2LatentBuildSlave
3028 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3029                                    ami='ami-12345')]
3030 @end example
3032 If you want to put the key information in another file, use the
3033 "aws_id_file_path" initialization argument.
3035 Previous examples used a particular AMI.  If the Buildbot master will be
3036 deployed in a process-controlled environment, it may be convenient to
3037 specify the AMI more flexibly.  Rather than specifying an individual AMI,
3038 specify one or two AMI filters.
3040 In all cases, the AMI that sorts last by its location (the S3 bucket and
3041 manifest name) will be preferred.
3043 One available filter is to specify the acceptable AMI owners, by AWS account
3044 number (the 12 digit number, usually rendered in AWS with hyphens like
3045 "1234-5678-9012", should be entered as in integer).
3047 @example
3048 from buildbot.ec2buildslave import EC2LatentBuildSlave
3049 bot1 = EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3050                            valid_ami_owners=[11111111111,
3051                                              22222222222],
3052                            identifier='publickey',
3053                            secret_identifier='privatekey'
3054                            )
3055 @end example
3057 The other available filter is to provide a regular expression string that
3058 will be matched against each AMI's location (the S3 bucket and manifest name).
3060 @example
3061 from buildbot.ec2buildslave import EC2LatentBuildSlave
3062 bot1 = EC2LatentBuildSlave(
3063     'bot1', 'sekrit', 'm1.large',
3064     valid_ami_location_regex=r'buildbot\-.*/image.manifest.xml',
3065     identifier='publickey', secret_identifier='privatekey')
3066 @end example
3068 The regular expression can specify a group, which will be preferred for the
3069 sorting.  Only the first group is used; subsequent groups are ignored.
3071 @example
3072 from buildbot.ec2buildslave import EC2LatentBuildSlave
3073 bot1 = EC2LatentBuildSlave(
3074     'bot1', 'sekrit', 'm1.large',
3075     valid_ami_location_regex=r'buildbot\-.*\-(.*)/image.manifest.xml',
3076     identifier='publickey', secret_identifier='privatekey')
3077 @end example
3079 If the group can be cast to an integer, it will be.  This allows 10 to sort
3080 after 1, for instance.
3082 @example
3083 from buildbot.ec2buildslave import EC2LatentBuildSlave
3084 bot1 = EC2LatentBuildSlave(
3085     'bot1', 'sekrit', 'm1.large',
3086     valid_ami_location_regex=r'buildbot\-.*\-(\d+)/image.manifest.xml',
3087     identifier='publickey', secret_identifier='privatekey')
3088 @end example
3090 In addition to using the password as a handshake between the master and the
3091 slave, you may want to use a firewall to assert that only machines from a
3092 specific IP can connect as slaves.  This is possible with AWS EC2 by using
3093 the Elastic IP feature.  To configure, generate a Elastic IP in AWS, and then
3094 specify it in your configuration using the "elastic_ip" argument.
3096 @example
3097 from buildbot.ec2buildslave import EC2LatentBuildSlave
3098 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3099                                    'ami-12345',
3100                                    identifier='publickey',
3101                                    secret_identifier='privatekey',
3102                                    elastic_ip='208.77.188.166'
3103                                    )]
3104 @end example
3106 The EC2LatentBuildSlave supports all other configuration from the standard
3107 BuildSlave.  The "missing_timeout" and "notify_on_missing" specify how long
3108 to wait for an EC2 instance to attach before considering the attempt to have
3109 failed, and email addresses to alert, respectively.  "missing_timeout"
3110 defaults to 20 minutes.
3112 The "build_wait_timeout" allows you to specify how long an EC2LatentBuildSlave
3113 should wait after a build for another build before it shuts down the EC2
3114 instance.  It defaults to 10 minutes.
3116 "keypair_name" and "security_name" allow you to specify different names for
3117 these AWS EC2 values.  They both default to "latent_buildbot_slave".
3119 @node Dangers with Latent Buildslaves, Writing New Latent Buildslaves, Amazon Web Services Elastic Compute Cloud ("AWS EC2"), On-Demand ("Latent") Buildslaves
3120 @subsection Dangers with Latent Buildslaves
3122 Any latent build slave that interacts with a for-fee service, such as the
3123 EC2LatentBuildSlave, brings significant risks. As already identified, the
3124 configuraton will need access to account information that, if obtained by a
3125 criminal, can be used to charge services to your account. Also, bugs in the
3126 buildbot software may lead to unnecessary charges. In particular, if the
3127 master neglects to shut down an instance for some reason, a virtual machine
3128 may be running unnecessarily, charging against your account. Manual and/or
3129 automatic (e.g. nagios with a plugin using a library like boto)
3130 double-checking may be appropriate.
3132 A comparitively trivial note is that currently if two instances try to attach
3133 to the same latent buildslave, it is likely that the system will become
3134 confused.  This should not occur, unless, for instance, you configure a normal
3135 build slave to connect with the authentication of a latent buildbot.  If the
3136 situation occurs, stop all attached instances and restart the master.
3138 @node Writing New Latent Buildslaves, , Dangers with Latent Buildslaves, On-Demand ("Latent") Buildslaves
3139 @subsection Writing New Latent Buildslaves
3141 Writing a new latent buildslave should only require subclassing
3142 @code{buildbot.buildslave.AbstractLatentBuildSlave} and implementing
3143 start_instance and stop_instance.
3145 @example
3146 def start_instance(self):
3147     # responsible for starting instance that will try to connect with this
3148     # master. Should return deferred. Problems should use an errback. The
3149     # callback value can be None, or can be an iterable of short strings to
3150     # include in the "substantiate success" status message, such as
3151     # identifying the instance that started.
3152     raise NotImplementedError
3154 def stop_instance(self, fast=False):
3155     # responsible for shutting down instance. Return a deferred. If `fast`,
3156     # we're trying to shut the master down, so callback as soon as is safe.
3157     # Callback value is ignored.
3158     raise NotImplementedError
3159 @end example
3161 See @code{buildbot.ec2buildslave.EC2LatentBuildSlave} for an example, or see the
3162 test example @code{buildbot.test_slaves.FakeLatentBuildSlave}.
3164 @node Defining Global Properties, Defining Builders, On-Demand ("Latent") Buildslaves, Configuration
3165 @section Defining Global Properties
3166 @bcindex c['properties']
3167 @cindex Properties
3169 The @code{'properties'} configuration key defines a dictionary
3170 of properties that will be available to all builds started by the
3171 buildmaster:
3173 @example
3174 c['properties'] = @{
3175     'Widget-version' : '1.2',
3176     'release-stage' : 'alpha'
3178 @end example
3180 @node Defining Builders, Defining Status Targets, Defining Global Properties, Configuration
3181 @section Defining Builders
3183 @bcindex c['builders']
3185 The @code{c['builders']} key is a list of dictionaries which specify
3186 the Builders. The Buildmaster runs a collection of Builders, each of
3187 which handles a single type of build (e.g. full versus quick), on a
3188 single build slave. A Buildbot which makes sure that the latest code
3189 (``HEAD'') compiles correctly across four separate architecture will
3190 have four Builders, each performing the same build but on different
3191 slaves (one per platform).
3193 Each Builder gets a separate column in the waterfall display. In
3194 general, each Builder runs independently (although various kinds of
3195 interlocks can cause one Builder to have an effect on another).
3197 Each Builder specification dictionary has several required keys:
3199 @table @code
3200 @item name
3201 This specifies the Builder's name, which is used in status
3202 reports.
3204 @item slavename
3205 This specifies which buildslave will be used by this Builder.
3206 @code{slavename} must appear in the @code{c['slaves']} list. Each
3207 buildslave can accomodate multiple Builders.
3209 @item slavenames
3210 If you provide @code{slavenames} instead of @code{slavename}, you can
3211 give a list of buildslaves which are capable of running this Builder.
3212 If multiple buildslaves are available for any given Builder, you will
3213 have some measure of redundancy: in case one slave goes offline, the
3214 others can still keep the Builder working. In addition, multiple
3215 buildslaves will allow multiple simultaneous builds for the same
3216 Builder, which might be useful if you have a lot of forced or ``try''
3217 builds taking place.
3219 If you use this feature, it is important to make sure that the
3220 buildslaves are all, in fact, capable of running the given build. The
3221 slave hosts should be configured similarly, otherwise you will spend a
3222 lot of time trying (unsuccessfully) to reproduce a failure that only
3223 occurs on some of the buildslaves and not the others. Different
3224 platforms, operating systems, versions of major programs or libraries,
3225 all these things mean you should use separate Builders.
3227 @item builddir
3228 This specifies the name of a subdirectory (under the base directory)
3229 in which everything related to this builder will be placed. On the
3230 buildmaster, this holds build status information. On the buildslave,
3231 this is where checkouts, compiles, and tests are run.
3233 @item factory
3234 This is a @code{buildbot.process.factory.BuildFactory} instance which
3235 controls how the build is performed. Full details appear in their own
3236 chapter, @xref{Build Process}. Parameters like the location of the CVS
3237 repository and the compile-time options used for the build are
3238 generally provided as arguments to the factory's constructor.
3240 @end table
3242 Other optional keys may be set on each Builder:
3244 @table @code
3246 @item category
3247 If provided, this is a string that identifies a category for the
3248 builder to be a part of. Status clients can limit themselves to a
3249 subset of the available categories. A common use for this is to add
3250 new builders to your setup (for a new module, or for a new buildslave)
3251 that do not work correctly yet and allow you to integrate them with
3252 the active builders. You can put these new builders in a test
3253 category, make your main status clients ignore them, and have only
3254 private status clients pick them up. As soon as they work, you can
3255 move them over to the active category.
3257 @end table
3260 @node Defining Status Targets, Debug options, Defining Builders, Configuration
3261 @section Defining Status Targets
3263 The Buildmaster has a variety of ways to present build status to
3264 various users. Each such delivery method is a ``Status Target'' object
3265 in the configuration's @code{status} list. To add status targets, you
3266 just append more objects to this list:
3268 @bcindex c['status']
3270 @example
3271 c['status'] = []
3273 from buildbot.status import html
3274 c['status'].append(html.Waterfall(http_port=8010))
3276 from buildbot.status import mail
3277 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
3278                       extraRecipients=["builds@@lists.example.com"],
3279                       sendToInterestedUsers=False)
3280 c['status'].append(m)
3282 from buildbot.status import words
3283 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
3284                              channels=["#example"]))
3285 @end example
3287 Status delivery has its own chapter, @xref{Status Delivery}, in which
3288 all the built-in status targets are documented.
3291 @node Debug options,  , Defining Status Targets, Configuration
3292 @section Debug options
3295 @bcindex c['debugPassword']
3296 If you set @code{c['debugPassword']}, then you can connect to the
3297 buildmaster with the diagnostic tool launched by @code{buildbot
3298 debugclient MASTER:PORT}. From this tool, you can reload the config
3299 file, manually force builds, and inject changes, which may be useful
3300 for testing your buildmaster without actually commiting changes to
3301 your repository (or before you have the Change Sources set up). The
3302 debug tool uses the same port number as the slaves do:
3303 @code{c['slavePortnum']}, and is authenticated with this password.
3305 @example
3306 c['debugPassword'] = "debugpassword"
3307 @end example
3309 @bcindex c['manhole']
3310 If you set @code{c['manhole']} to an instance of one of the classes in
3311 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
3312 and get an interactive Python shell, which may be useful for debugging
3313 buildbot internals. It is probably only useful for buildbot
3314 developers. It exposes full access to the buildmaster's account
3315 (including the ability to modify and delete files), so it should not
3316 be enabled with a weak or easily guessable password.
3318 There are three separate @code{Manhole} classes. Two of them use SSH,
3319 one uses unencrypted telnet. Two of them use a username+password
3320 combination to grant access, one of them uses an SSH-style
3321 @file{authorized_keys} file which contains a list of ssh public keys.
3323 @table @code
3324 @item manhole.AuthorizedKeysManhole
3325 You construct this with the name of a file that contains one SSH
3326 public key per line, just like @file{~/.ssh/authorized_keys}. If you
3327 provide a non-absolute filename, it will be interpreted relative to
3328 the buildmaster's base directory.
3330 @item manhole.PasswordManhole
3331 This one accepts SSH connections but asks for a username and password
3332 when authenticating. It accepts only one such pair.
3335 @item manhole.TelnetManhole
3336 This accepts regular unencrypted telnet connections, and asks for a
3337 username/password pair before providing access. Because this
3338 username/password is transmitted in the clear, and because Manhole
3339 access to the buildmaster is equivalent to granting full shell
3340 privileges to both the buildmaster and all the buildslaves (and to all
3341 accounts which then run code produced by the buildslaves), it is
3342 highly recommended that you use one of the SSH manholes instead.
3344 @end table
3346 @example
3347 # some examples:
3348 from buildbot import manhole
3349 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
3350 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
3351 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
3352 @end example
3354 The @code{Manhole} instance can be configured to listen on a specific
3355 port. You may wish to have this listening port bind to the loopback
3356 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
3357 restrict access to clients which are running on the same host.
3359 @example
3360 from buildbot.manhole import PasswordManhole
3361 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
3362 @end example
3364 To have the @code{Manhole} listen on all interfaces, use
3365 @code{"tcp:9999"} or simply 9999. This port specification uses
3366 @code{twisted.application.strports}, so you can make it listen on SSL
3367 or even UNIX-domain sockets if you want.
3369 Note that using any Manhole requires that the TwistedConch package be
3370 installed, and that you be using Twisted version 2.0 or later.
3372 The buildmaster's SSH server will use a different host key than the
3373 normal sshd running on a typical unix host. This will cause the ssh
3374 client to complain about a ``host key mismatch'', because it does not
3375 realize there are two separate servers running on the same host. To
3376 avoid this, use a clause like the following in your @file{.ssh/config}
3377 file:
3379 @example
3380 Host remotehost-buildbot
3381  HostName remotehost
3382  HostKeyAlias remotehost-buildbot
3383  Port 9999
3384  # use 'user' if you use PasswordManhole and your name is not 'admin'.
3385  # if you use AuthorizedKeysManhole, this probably doesn't matter.
3386  User admin
3387 @end example
3390 @node Getting Source Code Changes, Build Process, Configuration, Top
3391 @chapter Getting Source Code Changes
3393 The most common way to use the Buildbot is centered around the idea of
3394 @code{Source Trees}: a directory tree filled with source code of some form
3395 which can be compiled and/or tested. Some projects use languages that don't
3396 involve any compilation step: nevertheless there may be a @code{build} phase
3397 where files are copied or rearranged into a form that is suitable for
3398 installation. Some projects do not have unit tests, and the Buildbot is
3399 merely helping to make sure that the sources can compile correctly. But in
3400 all of these cases, the thing-being-tested is a single source tree.
3402 A Version Control System mantains a source tree, and tells the
3403 buildmaster when it changes. The first step of each Build is typically
3404 to acquire a copy of some version of this tree.
3406 This chapter describes how the Buildbot learns about what Changes have
3407 occurred. For more information on VC systems and Changes, see
3408 @ref{Version Control Systems}.
3411 @menu
3412 * Change Sources::
3413 * Choosing ChangeSources::
3414 * CVSToys - PBService::
3415 * Mail-parsing ChangeSources::
3416 * PBChangeSource::
3417 * P4Source::
3418 * BonsaiPoller::
3419 * SVNPoller::
3420 * MercurialHook::
3421 * Bzr Hook::
3422 * Bzr Poller::
3423 @end menu
3427 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
3428 @section Change Sources
3430 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
3431 @c so narrow-minded anymore
3433 Each Buildmaster watches a single source tree. Changes can be provided
3434 by a variety of ChangeSource types, however any given project will
3435 typically have only a single ChangeSource active. This section
3436 provides a description of all available ChangeSource types and
3437 explains how to set up each of them.
3439 There are a variety of ChangeSources available, some of which are
3440 meant to be used in conjunction with other tools to deliver Change
3441 events from the VC repository to the buildmaster.
3443 @itemize @bullet
3445 @item CVSToys
3446 This ChangeSource opens a TCP connection from the buildmaster to a
3447 waiting FreshCVS daemon that lives on the repository machine, and
3448 subscribes to hear about Changes.
3450 @item MaildirSource
3451 This one watches a local maildir-format inbox for email sent out by
3452 the repository when a change is made. When a message arrives, it is
3453 parsed to create the Change object. A variety of parsing functions are
3454 available to accomodate different email-sending tools.
3456 @item PBChangeSource
3457 This ChangeSource listens on a local TCP socket for inbound
3458 connections from a separate tool. Usually, this tool would be run on
3459 the VC repository machine in a commit hook. It is expected to connect
3460 to the TCP socket and send a Change message over the network
3461 connection. The @command{buildbot sendchange} command is one example
3462 of a tool that knows how to send these messages, so you can write a
3463 commit script for your VC system that calls it to deliver the Change.
3464 There are other tools in the contrib/ directory that use the same
3465 protocol.
3467 @end itemize
3469 As a quick guide, here is a list of VC systems and the ChangeSources
3470 that might be useful with them. All of these ChangeSources are in the
3471 @code{buildbot.changes} module.
3473 @table @code
3474 @item CVS
3476 @itemize @bullet
3477 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
3478 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
3479 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
3480 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
3481 @item pb.PBChangeSource (listening for connections from @code{buildbot
3482 sendchange} run in a loginfo script)
3483 @item pb.PBChangeSource (listening for connections from a long-running
3484 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
3485 database directly
3486 @end itemize
3488 @item SVN
3489 @itemize @bullet
3490 @item pb.PBChangeSource (listening for connections from
3491 @code{contrib/svn_buildbot.py} run in a postcommit script)
3492 @item pb.PBChangeSource (listening for connections from a long-running
3493 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
3494 process
3495 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
3496 @item svnpoller.SVNPoller (polling the SVN repository)
3497 @end itemize
3499 @item Darcs
3500 @itemize @bullet
3501 @item pb.PBChangeSource (listening for connections from
3502 @code{contrib/darcs_buildbot.py} in a commit script
3503 @end itemize
3505 @item Mercurial
3506 @itemize @bullet
3507 @item pb.PBChangeSource (listening for connections from
3508 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
3509 @item pb.PBChangeSource (listening for connections from
3510 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
3511 hook)
3512 @end itemize
3514 @item Arch/Bazaar
3515 @itemize @bullet
3516 @item pb.PBChangeSource (listening for connections from
3517 @code{contrib/arch_buildbot.py} run in a commit hook)
3518 @end itemize
3520 @item Bzr (the newer Bazaar)
3521 @itemize @bullet
3522 @item pb.PBChangeSource (listening for connections from
3523 @code{contrib/bzr_buildbot.py} run in a post-change-branch-tip or commit hook)
3524 @item @code{contrib/bzr_buildbot.py}'s BzrPoller (polling the Bzr repository)
3525 @end itemize
3527 @item Git
3528 @itemize @bullet
3529 @item pb.PBChangeSource (listening for connections from
3530 @code{contrib/git_buildbot.py} run in the post-receive hook)
3531 @end itemize
3533 @end table
3535 All VC systems can be driven by a PBChangeSource and the
3536 @code{buildbot sendchange} tool run from some form of commit script.
3537 If you write an email parsing function, they can also all be driven by
3538 a suitable @code{MaildirSource}.
3541 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
3542 @section Choosing ChangeSources
3544 The @code{master.cfg} configuration file has a dictionary key named
3545 @code{BuildmasterConfig['change_source']}, which holds the active
3546 @code{IChangeSource} object. The config file will typically create an
3547 object from one of the classes described below and stuff it into this
3548 key.
3550 Each buildmaster typically has just a single ChangeSource, since it is
3551 only watching a single source tree. But if, for some reason, you need
3552 multiple sources, just set @code{c['change_source']} to a list of
3553 ChangeSources.. it will accept that too.
3555 @example
3556 s = FreshCVSSourceNewcred(host="host", port=4519,
3557                           user="alice", passwd="secret",
3558                           prefix="Twisted")
3559 BuildmasterConfig['change_source'] = [s]
3560 @end example
3562 Each source tree has a nominal @code{top}. Each Change has a list of
3563 filenames, which are all relative to this top location. The
3564 ChangeSource is responsible for doing whatever is necessary to
3565 accomplish this. Most sources have a @code{prefix} argument: a partial
3566 pathname which is stripped from the front of all filenames provided to
3567 that @code{ChangeSource}. Files which are outside this sub-tree are
3568 ignored by the changesource: it does not generate Changes for those
3569 files.
3572 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
3573 @section CVSToys - PBService
3575 @csindex buildbot.changes.freshcvs.FreshCVSSource
3577 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
3578 server which runs on the machine that hosts the CVS repository it
3579 watches. It has a variety of ways to distribute commit notifications,
3580 and offers a flexible regexp-based way to filter out uninteresting
3581 changes. One of the notification options is named @code{PBService} and
3582 works by listening on a TCP port for clients. These clients subscribe
3583 to hear about commit notifications.
3585 The buildmaster has a CVSToys-compatible @code{PBService} client built
3586 in. There are two versions of it, one for old versions of CVSToys
3587 (1.0.9 and earlier) which used the @code{oldcred} authentication
3588 framework, and one for newer versions (1.0.10 and later) which use
3589 @code{newcred}. Both are classes in the
3590 @code{buildbot.changes.freshcvs} package.
3592 @code{FreshCVSSourceNewcred} objects are created with the following
3593 parameters:
3595 @table @samp
3597 @item @code{host} and @code{port}
3598 these specify where the CVSToys server can be reached
3600 @item @code{user} and @code{passwd}
3601 these specify the login information for the CVSToys server
3602 (@code{freshcvs}). These must match the server's values, which are
3603 defined in the @code{freshCfg} configuration file (which lives in the
3604 CVSROOT directory of the repository).
3606 @item @code{prefix}
3607 this is the prefix to be found and stripped from filenames delivered
3608 by the CVSToys server. Most projects live in sub-directories of the
3609 main repository, as siblings of the CVSROOT sub-directory, so
3610 typically this prefix is set to that top sub-directory name.
3612 @end table
3614 @heading Example
3616 To set up the freshCVS server, add a statement like the following to
3617 your @file{freshCfg} file:
3619 @example
3620 pb = ConfigurationSet([
3621     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
3622     ])
3623 @end example
3625 This will announce all changes to a client which connects to port 4519
3626 using a username of 'foo' and a password of 'bar'.
3628 Then add a clause like this to your buildmaster's @file{master.cfg}:
3630 @example
3631 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
3632                                                     "foo", "bar",
3633                                                     prefix="glib/")
3634 @end example
3636 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
3637 "glib" is the top-level directory (relative to the repository's root) where
3638 all your source code lives. Most projects keep one or more projects in the
3639 same repository (along with CVSROOT/ to hold admin files like loginfo and
3640 freshCfg); the prefix= argument tells the buildmaster to ignore everything
3641 outside that directory, and to strip that common prefix from all pathnames
3642 it handles.
3645 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
3646 @section Mail-parsing ChangeSources
3648 Many projects publish information about changes to their source tree
3649 by sending an email message out to a mailing list, frequently named
3650 PROJECT-commits or PROJECT-changes. Each message usually contains a
3651 description of the change (who made the change, which files were
3652 affected) and sometimes a copy of the diff. Humans can subscribe to
3653 this list to stay informed about what's happening to the source tree.
3655 The Buildbot can also be subscribed to a -commits mailing list, and
3656 can trigger builds in response to Changes that it hears about. The
3657 buildmaster admin needs to arrange for these email messages to arrive
3658 in a place where the buildmaster can find them, and configure the
3659 buildmaster to parse the messages correctly. Once that is in place,
3660 the email parser will create Change objects and deliver them to the
3661 Schedulers (see @pxref{Change Sources and Schedulers}) just
3662 like any other ChangeSource.
3664 There are two components to setting up an email-based ChangeSource.
3665 The first is to route the email messages to the buildmaster, which is
3666 done by dropping them into a ``maildir''. The second is to actually
3667 parse the messages, which is highly dependent upon the tool that was
3668 used to create them. Each VC system has a collection of favorite
3669 change-emailing tools, and each has a slightly different format, so
3670 each has a different parsing function. There is a separate
3671 ChangeSource variant for each parsing function.
3673 Once you've chosen a maildir location and a parsing function, create
3674 the change source and put it in @code{c['change_source']}:
3676 @example
3677 from buildbot.changes.mail import SyncmailMaildirSource
3678 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
3679                                            prefix="/trunk/")
3680 @end example
3682 @menu
3683 * Subscribing the Buildmaster::
3684 * Using Maildirs::
3685 * Parsing Email Change Messages::
3686 @end menu
3688 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
3689 @subsection Subscribing the Buildmaster
3691 The recommended way to install the buildbot is to create a dedicated
3692 account for the buildmaster. If you do this, the account will probably
3693 have a distinct email address (perhaps
3694 @email{buildmaster@@example.org}). Then just arrange for this
3695 account's email to be delivered to a suitable maildir (described in
3696 the next section).
3698 If the buildbot does not have its own account, ``extension addresses''
3699 can be used to distinguish between email intended for the buildmaster
3700 and email intended for the rest of the account. In most modern MTAs,
3701 the e.g. @code{foo@@example.org} account has control over every email
3702 address at example.org which begins with "foo", such that email
3703 addressed to @email{account-foo@@example.org} can be delivered to a
3704 different destination than @email{account-bar@@example.org}. qmail
3705 does this by using separate .qmail files for the two destinations
3706 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
3707 controlling the base address and @file{.qmail-default} controlling all
3708 other extensions). Other MTAs have similar mechanisms.
3710 Thus you can assign an extension address like
3711 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
3712 @email{foo@@example.org} for your own use.
3715 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
3716 @subsection Using Maildirs
3718 A ``maildir'' is a simple directory structure originally developed for
3719 qmail that allows safe atomic update without locking. Create a base
3720 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
3721 When messages arrive, they are put into a uniquely-named file (using
3722 pids, timestamps, and random numbers) in ``tmp''. When the file is
3723 complete, it is atomically renamed into ``new''. Eventually the
3724 buildmaster notices the file in ``new'', reads and parses the
3725 contents, then moves it into ``cur''. A cronjob can be used to delete
3726 files in ``cur'' at leisure.
3728 Maildirs are frequently created with the @command{maildirmake} tool,
3729 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
3730 equivalent.
3732 Many modern MTAs can deliver directly to maildirs. The usual .forward
3733 or .procmailrc syntax is to name the base directory with a trailing
3734 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
3735 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
3736 Delivery Agent).
3738 For MTAs which cannot put files into maildirs directly, the
3739 ``safecat'' tool can be executed from a .forward file to accomplish
3740 the same thing.
3742 The Buildmaster uses the linux DNotify facility to receive immediate
3743 notification when the maildir's ``new'' directory has changed. When
3744 this facility is not available, it polls the directory for new
3745 messages, every 10 seconds by default.
3747 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
3748 @subsection Parsing Email Change Messages
3750 The second component to setting up an email-based ChangeSource is to
3751 parse the actual notices. This is highly dependent upon the VC system
3752 and commit script in use.
3754 A couple of common tools used to create these change emails are:
3756 @table @samp
3758 @item CVS
3759 @table @samp
3760 @item CVSToys MailNotifier
3761 @ref{FCMaildirSource}
3762 @item Bonsai notification
3763 @ref{BonsaiMaildirSource}
3764 @item syncmail
3765 @ref{SyncmailMaildirSource}
3766 @end table
3768 @item SVN
3769 @table @samp
3770 @item svnmailer
3771 http://opensource.perlig.de/en/svnmailer/
3772 @item commit-email.pl
3773 @ref{SVNCommitEmailMaildirSource}
3774 @end table
3776 @item Mercurial
3777 @table @samp
3778 @item NotifyExtension
3779 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
3780 @end table
3782 @item Git
3783 @table @samp
3784 @item post-receive-email
3785 http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email;hb=HEAD
3786 @end table
3788 @end table
3791 The following sections describe the parsers available for each of
3792 these tools.
3794 Most of these parsers accept a @code{prefix=} argument, which is used
3795 to limit the set of files that the buildmaster pays attention to. This
3796 is most useful for systems like CVS and SVN which put multiple
3797 projects in a single repository (or use repository names to indicate
3798 branches). Each filename that appears in the email is tested against
3799 the prefix: if the filename does not start with the prefix, the file
3800 is ignored. If the filename @emph{does} start with the prefix, that
3801 prefix is stripped from the filename before any further processing is
3802 done. Thus the prefix usually ends with a slash.
3804 @menu
3805 * FCMaildirSource::
3806 * SyncmailMaildirSource::
3807 * BonsaiMaildirSource::
3808 * SVNCommitEmailMaildirSource::
3809 @end menu
3811 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
3812 @subsubsection FCMaildirSource
3815 @csindex buildbot.changes.mail.FCMaildirSource
3817 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
3819 This parser works with the CVSToys @code{MailNotification} action,
3820 which will send email to a list of recipients for each commit. This
3821 tends to work better than using @code{/bin/mail} from within the
3822 CVSROOT/loginfo file directly, as CVSToys will batch together all
3823 files changed during the same CVS invocation, and can provide more
3824 information (like creating a ViewCVS URL for each file changed).
3826 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3827 messages and turn them into Change objects. It can be given two
3828 parameters: the directory name of the maildir root, and the prefix to
3829 strip.
3831 @example
3832 from buildbot.changes.mail import FCMaildirSource
3833 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3834 @end example
3836 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3837 @subsubsection SyncmailMaildirSource
3839 @csindex buildbot.changes.mail.SyncmailMaildirSource
3841 http://sourceforge.net/projects/cvs-syncmail
3843 @code{SyncmailMaildirSource} knows how to parse the message format used by
3844 the CVS ``syncmail'' script.
3846 @example
3847 from buildbot.changes.mail import SyncmailMaildirSource
3848 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3849 @end example
3851 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3852 @subsubsection BonsaiMaildirSource
3854 @csindex buildbot.changes.mail.BonsaiMaildirSource
3856 http://www.mozilla.org/bonsai.html
3858 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3859 tree-management system built by Mozilla.
3861 @example
3862 from buildbot.changes.mail import BonsaiMaildirSource
3863 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3864 @end example
3866 @node SVNCommitEmailMaildirSource,  , BonsaiMaildirSource, Parsing Email Change Messages
3867 @subsubsection SVNCommitEmailMaildirSource
3869 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3871 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3872 @code{commit-email.pl} script, which is included in the Subversion
3873 distribution.
3875 It does not currently handle branches: all of the Change objects that
3876 it creates will be associated with the default (i.e. trunk) branch.
3878 @example
3879 from buildbot.changes.mail import SVNCommitEmailMaildirSource
3880 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
3881 @end example
3884 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
3885 @section PBChangeSource
3887 @csindex buildbot.changes.pb.PBChangeSource
3889 The last kind of ChangeSource actually listens on a TCP port for
3890 clients to connect and push change notices @emph{into} the
3891 Buildmaster. This is used by the built-in @code{buildbot sendchange}
3892 notification tool, as well as the VC-specific
3893 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
3894 @file{contrib/hg_buildbot.py} tools, and the
3895 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
3896 repository (in a commit hook script), and connect to the buildmaster
3897 directly each time a file is comitted. This is also useful for
3898 creating new kinds of change sources that work on a @code{push} model
3899 instead of some kind of subscription scheme, for example a script
3900 which is run out of an email .forward file.
3902 This ChangeSource can be configured to listen on its own TCP port, or
3903 it can share the port that the buildmaster is already using for the
3904 buildslaves to connect. (This is possible because the
3905 @code{PBChangeSource} uses the same protocol as the buildslaves, and
3906 they can be distinguished by the @code{username} attribute used when
3907 the initial connection is established). It might be useful to have it
3908 listen on a different port if, for example, you wanted to establish
3909 different firewall rules for that port. You could allow only the SVN
3910 repository machine access to the @code{PBChangeSource} port, while
3911 allowing only the buildslave machines access to the slave port. Or you
3912 could just expose one port and run everything over it. @emph{Note:
3913 this feature is not yet implemented, the PBChangeSource will always
3914 share the slave port and will always have a @code{user} name of
3915 @code{change}, and a passwd of @code{changepw}. These limitations will
3916 be removed in the future.}.
3919 The @code{PBChangeSource} is created with the following arguments. All
3920 are optional.
3922 @table @samp
3923 @item @code{port}
3924 which port to listen on. If @code{None} (which is the default), it
3925 shares the port used for buildslave connections. @emph{Not
3926 Implemented, always set to @code{None}}.
3928 @item @code{user} and @code{passwd}
3929 The user/passwd account information that the client program must use
3930 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
3931 Implemented, @code{user} is currently always set to @code{change},
3932 @code{passwd} is always set to @code{changepw}}.
3934 @item @code{prefix}
3935 The prefix to be found and stripped from filenames delivered over the
3936 connection. Any filenames which do not start with this prefix will be
3937 removed. If all the filenames in a given Change are removed, the that
3938 whole Change will be dropped. This string should probably end with a
3939 directory separator.
3941 This is useful for changes coming from version control systems that
3942 represent branches as parent directories within the repository (like
3943 SVN and Perforce). Use a prefix of 'trunk/' or
3944 'project/branches/foobranch/' to only follow one branch and to get
3945 correct tree-relative filenames. Without a prefix, the PBChangeSource
3946 will probably deliver Changes with filenames like @file{trunk/foo.c}
3947 instead of just @file{foo.c}. Of course this also depends upon the
3948 tool sending the Changes in (like @command{buildbot sendchange}) and
3949 what filenames it is delivering: that tool may be filtering and
3950 stripping prefixes at the sending end.
3952 @end table
3954 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
3955 @section P4Source
3957 @csindex buildbot.changes.p4poller.P4Source
3959 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
3960 Perforce} depot for changes. It accepts the following arguments:
3962 @table @samp
3963 @item @code{p4base}
3964 The base depot path to watch, without the trailing '/...'.
3966 @item @code{p4port}
3967 The Perforce server to connect to (as host:port).
3969 @item @code{p4user}
3970 The Perforce user.
3972 @item @code{p4passwd}
3973 The Perforce password.
3975 @item @code{split_file}
3976 A function that maps a pathname, without the leading @code{p4base}, to a
3977 (branch, filename) tuple. The default just returns (None, branchfile),
3978 which effectively disables branch support. You should supply a function
3979 which understands your repository structure.
3981 @item @code{pollinterval}
3982 How often to poll, in seconds. Defaults to 600 (10 minutes).
3984 @item @code{histmax}
3985 The maximum number of changes to inspect at a time. If more than this
3986 number occur since the last poll, older changes will be silently
3987 ignored.
3988 @end table
3990 @heading Example
3992 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
3993 specified in the buildmaster's environment. It watches a project in which the
3994 branch name is simply the next path component, and the file is all path
3995 components after.
3997 @example
3998 import buildbot.changes.p4poller
3999 s = p4poller.P4Source(p4base='//depot/project/',
4000                       split_file=lambda branchfile: branchfile.split('/',1),
4001                      )
4002 c['change_source'] = s
4003 @end example
4005 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
4006 @section BonsaiPoller
4008 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
4010 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
4011 CGI script accessed through a web server that provides information
4012 about a CVS tree, for example the Mozilla bonsai server at
4013 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
4014 humans and machines. In this case, the buildbot's change source forms
4015 a query which asks about any files in the specified branch which have
4016 changed since the last query.
4018 Please take a look at the BonsaiPoller docstring for details about the
4019 arguments it accepts.
4022 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
4023 @section SVNPoller
4025 @csindex buildbot.changes.svnpoller.SVNPoller
4027 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
4028 which periodically polls a @uref{http://subversion.tigris.org/,
4029 Subversion} repository for new revisions, by running the @code{svn
4030 log} command in a subshell. It can watch a single branch or multiple
4031 branches.
4033 @code{SVNPoller} accepts the following arguments:
4035 @table @code
4036 @item svnurl
4037 The base URL path to watch, like
4038 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
4039 @code{http://divmod.org/svn/Divmod/}, or even
4040 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
4041 include the access scheme, the location of the repository (both the
4042 hostname for remote ones, and any additional directory names necessary
4043 to get to the repository), and the sub-path within the repository's
4044 virtual filesystem for the project and branch of interest.
4046 The @code{SVNPoller} will only pay attention to files inside the
4047 subdirectory specified by the complete svnurl.
4049 @item split_file
4050 A function to convert pathnames into (branch, relative_pathname)
4051 tuples. Use this to explain your repository's branch-naming policy to
4052 @code{SVNPoller}. This function must accept a single string and return
4053 a two-entry tuple. There are a few utility functions in
4054 @code{buildbot.changes.svnpoller} that can be used as a
4055 @code{split_file} function, see below for details.
4057 The default value always returns (None, path), which indicates that
4058 all files are on the trunk.
4060 Subclasses of @code{SVNPoller} can override the @code{split_file}
4061 method instead of using the @code{split_file=} argument.
4063 @item svnuser
4064 An optional string parameter. If set, the @code{--user} argument will
4065 be added to all @code{svn} commands. Use this if you have to
4066 authenticate to the svn server before you can do @code{svn info} or
4067 @code{svn log} commands.
4069 @item svnpasswd
4070 Like @code{svnuser}, this will cause a @code{--password} argument to
4071 be passed to all svn commands.
4073 @item pollinterval
4074 How often to poll, in seconds. Defaults to 600 (checking once every 10
4075 minutes). Lower this if you want the buildbot to notice changes
4076 faster, raise it if you want to reduce the network and CPU load on
4077 your svn server. Please be considerate of public SVN repositories by
4078 using a large interval when polling them.
4080 @item histmax
4081 The maximum number of changes to inspect at a time. Every POLLINTERVAL
4082 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
4083 looks through them for any ones it does not already know about. If
4084 more than HISTMAX revisions have been committed since the last poll,
4085 older changes will be silently ignored. Larger values of histmax will
4086 cause more time and memory to be consumed on each poll attempt.
4087 @code{histmax} defaults to 100.
4089 @item svnbin
4090 This controls the @code{svn} executable to use. If subversion is
4091 installed in a weird place on your system (outside of the
4092 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
4093 to find it. The default value of ``svn'' will almost always be
4094 sufficient.
4096 @end table
4098 @heading Branches
4100 Each source file that is tracked by a Subversion repository has a
4101 fully-qualified SVN URL in the following form:
4102 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
4103 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
4104 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
4105 string. The @code{SVNPoller} is responsible for producing Changes that
4106 contain a branch name and a FILEPATH (which is relative to the top of
4107 a checked-out tree). The details of how these strings are split up
4108 depend upon how your repository names its branches.
4110 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
4112 One common layout is to have all the various projects that share a
4113 repository get a single top-level directory each. Then under a given
4114 project's directory, you get two subdirectories, one named ``trunk''
4115 and another named ``branches''. Under ``branches'' you have a bunch of
4116 other directories, one per branch, with names like ``1.5.x'' and
4117 ``testing''. It is also common to see directories like ``tags'' and
4118 ``releases'' next to ``branches'' and ``trunk''.
4120 For example, the Twisted project has a subversion server on
4121 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
4122 repository is available through a SCHEME of ``svn:''. The primary
4123 sub-project is Twisted, of course, with a repository root of
4124 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
4125 Informant, with a root of
4126 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
4127 checked-out Twisted tree, there is a file named bin/trial (which is
4128 used to run unit test suites).
4130 The trunk for Twisted is in
4131 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
4132 fully-qualified SVN URL for the trunk version of @code{trial} would be
4133 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
4134 SVNURL for that file on a branch named ``1.5.x'' would be
4135 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
4137 To set up a @code{SVNPoller} that watches the Twisted trunk (and
4138 nothing else), we would use the following:
4140 @example
4141 from buildbot.changes.svnpoller import SVNPoller
4142 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
4143 @end example
4145 In this case, every Change that our @code{SVNPoller} produces will
4146 have @code{.branch=None}, to indicate that the Change is on the trunk.
4147 No other sub-projects or branches will be tracked.
4149 If we want our ChangeSource to follow multiple branches, we have to do
4150 two things. First we have to change our @code{svnurl=} argument to
4151 watch more than just ``.../Twisted/trunk''. We will set it to
4152 ``.../Twisted'' so that we'll see both the trunk and all the branches.
4153 Second, we have to tell @code{SVNPoller} how to split the
4154 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
4155 out into (BRANCH) and (FILEPATH) pairs.
4157 We do the latter by providing a ``split_file'' function. This function
4158 is responsible for splitting something like
4159 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
4160 @code{filepath}=''bin/trial''. This function is always given a string
4161 that names a file relative to the subdirectory pointed to by the
4162 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
4163 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
4164 branch indicated), or None to indicate that the file is outside any
4165 project of interest.
4167 (note that we want to see ``branches/1.5.x'' rather than just
4168 ``1.5.x'' because when we perform the SVN checkout, we will probably
4169 append the branch name to the baseURL, which requires that we keep the
4170 ``branches'' component in there. Other VC schemes use a different
4171 approach towards branches and may not require this artifact.)
4173 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
4174 scheme, the following function will work:
4176 @example
4177 def split_file_branches(path):
4178     pieces = path.split('/')
4179     if pieces[0] == 'trunk':
4180         return (None, '/'.join(pieces[1:]))
4181     elif pieces[0] == 'branches':
4182         return ('/'.join(pieces[0:2]),
4183                 '/'.join(pieces[2:]))
4184     else:
4185         return None
4186 @end example
4188 This function is provided as
4189 @code{buildbot.changes.svnpoller.split_file_branches} for your
4190 convenience. So to have our Twisted-watching @code{SVNPoller} follow
4191 multiple branches, we would use this:
4193 @example
4194 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
4195 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
4196                                split_file=split_file_branches)
4197 @end example
4199 Changes for all sorts of branches (with names like ``branches/1.5.x'',
4200 and None to indicate the trunk) will be delivered to the Schedulers.
4201 Each Scheduler is then free to use or ignore each branch as it sees
4202 fit.
4204 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
4206 Another common way to organize a Subversion repository is to put the
4207 branch name at the top, and the projects underneath. This is
4208 especially frequent when there are a number of related sub-projects
4209 that all get released in a group.
4211 For example, Divmod.org hosts a project named ``Nevow'' as well as one
4212 named ``Quotient''. In a checked-out Nevow tree there is a directory
4213 named ``formless'' that contains a python source file named
4214 ``webform.py''. This repository is accessible via webdav (and thus
4215 uses an ``http:'' scheme) through the divmod.org hostname. There are
4216 many branches in this repository, and they use a
4217 (BRANCHNAME)/(PROJECT) naming policy.
4219 The fully-qualified SVN URL for the trunk version of webform.py is
4220 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
4221 You can do an @code{svn co} with that URL and get a copy of the latest
4222 version. The 1.5.x branch version of this file would have a URL of
4223 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
4224 The whole Nevow trunk would be checked out with
4225 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
4226 trunk would be checked out using
4227 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
4229 Now suppose we want to have an @code{SVNPoller} that only cares about
4230 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
4231 described earlier:
4233 @example
4234 from buildbot.changes.svnpoller import SVNPoller
4235 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
4236 @end example
4238 But what happens when we want to track multiple Nevow branches? We
4239 have to point our @code{svnurl=} high enough to see all those
4240 branches, but we also don't want to include Quotient changes (since
4241 we're only building Nevow). To accomplish this, we must rely upon the
4242 @code{split_file} function to help us tell the difference between
4243 files that belong to Nevow and those that belong to Quotient, as well
4244 as figuring out which branch each one is on.
4246 @example
4247 from buildbot.changes.svnpoller import SVNPoller
4248 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
4249                                split_file=my_file_splitter)
4250 @end example
4252 The @code{my_file_splitter} function will be called with
4253 repository-relative pathnames like:
4255 @table @code
4256 @item trunk/Nevow/formless/webform.py
4257 This is a Nevow file, on the trunk. We want the Change that includes this
4258 to see a filename of @code{formless/webform.py"}, and a branch of None
4260 @item branches/1.5.x/Nevow/formless/webform.py
4261 This is a Nevow file, on a branch. We want to get
4262 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
4264 @item trunk/Quotient/setup.py
4265 This is a Quotient file, so we want to ignore it by having
4266 @code{my_file_splitter} return None.
4268 @item branches/1.5.x/Quotient/setup.py
4269 This is also a Quotient file, which should be ignored.
4270 @end table
4272 The following definition for @code{my_file_splitter} will do the job:
4274 @example
4275 def my_file_splitter(path):
4276     pieces = path.split('/')
4277     if pieces[0] == 'trunk':
4278         branch = None
4279         pieces.pop(0) # remove 'trunk'
4280     elif pieces[0] == 'branches':
4281         pieces.pop(0) # remove 'branches'
4282         # grab branch name
4283         branch = 'branches/' + pieces.pop(0)
4284     else:
4285         return None # something weird
4286     projectname = pieces.pop(0)
4287     if projectname != 'Nevow':
4288         return None # wrong project
4289     return (branch, '/'.join(pieces))
4290 @end example
4292 @node MercurialHook,  Bzr Hook, SVNPoller, Getting Source Code Changes
4293 @section MercurialHook
4295 Since Mercurial is written in python, the hook script can invoke
4296 Buildbot's @code{sendchange} function directly, rather than having to
4297 spawn an external process. This function delivers the same sort of
4298 changes as @code{buildbot sendchange} and the various hook scripts in
4299 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
4300 buildmaster to receive these changes.
4302 To set this up, first choose a Mercurial repository that represents
4303 your central ``official'' source tree. This will be the same
4304 repository that your buildslaves will eventually pull from. Install
4305 Buildbot on the machine that hosts this repository, using the same
4306 version of python as Mercurial is using (so that the Mercurial hook
4307 can import code from buildbot). Then add the following to the
4308 @code{.hg/hgrc} file in that repository, replacing the buildmaster
4309 hostname/portnumber as appropriate for your buildbot:
4311 @example
4312 [hooks]
4313 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
4315 [hgbuildbot]
4316 master = buildmaster.example.org:9987
4317 @end example
4319 (Note that Mercurial lets you define multiple @code{changegroup} hooks
4320 by giving them distinct names, like @code{changegroup.foo} and
4321 @code{changegroup.bar}, which is why we use
4322 @code{changegroup.buildbot} in this example. There is nothing magical
4323 about the ``buildbot'' suffix in the hook name. The
4324 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
4325 only section that the buildbot hook pays attention to.)
4327 Also note that this runs as a @code{changegroup} hook, rather than as
4328 an @code{incoming} hook. The @code{changegroup} hook is run with
4329 multiple revisions at a time (say, if multiple revisions are being
4330 pushed to this repository in a single @command{hg push} command),
4331 whereas the @code{incoming} hook is run with just one revision at a
4332 time. The @code{hgbuildbot.hook} function will only work with the
4333 @code{changegroup} hook.
4335 The @code{[hgbuildbot]} section has two other parameters that you
4336 might specify, both of which control the name of the branch that is
4337 attached to the changes coming from this hook.
4339 One common branch naming policy for Mercurial repositories is to use
4340 it just like Darcs: each branch goes into a separate repository, and
4341 all the branches for a single project share a common parent directory.
4342 For example, you might have @file{/var/repos/PROJECT/trunk/} and
4343 @file{/var/repos/PROJECT/release}. To use this style, use the
4344 @code{branchtype = dirname} setting, which simply uses the last
4345 component of the repository's enclosing directory as the branch name:
4347 @example
4348 [hgbuildbot]
4349 master = buildmaster.example.org:9987
4350 branchtype = dirname
4351 @end example
4353 Another approach is to use Mercurial's built-in branches (the kind
4354 created with @command{hg branch} and listed with @command{hg
4355 branches}). This feature associates persistent names with particular
4356 lines of descent within a single repository. (note that the buildbot
4357 @code{source.Mercurial} checkout step does not yet support this kind
4358 of branch). To have the commit hook deliver this sort of branch name
4359 with the Change object, use @code{branchtype = inrepo}:
4361 @example
4362 [hgbuildbot]
4363 master = buildmaster.example.org:9987
4364 branchtype = inrepo
4365 @end example
4367 Finally, if you want to simply specify the branchname directly, for
4368 all changes, use @code{branch = BRANCHNAME}. This overrides
4369 @code{branchtype}:
4371 @example
4372 [hgbuildbot]
4373 master = buildmaster.example.org:9987
4374 branch = trunk
4375 @end example
4377 If you use @code{branch=} like this, you'll need to put a separate
4378 .hgrc in each repository. If you use @code{branchtype=}, you may be
4379 able to use the same .hgrc for all your repositories, stored in
4380 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
4383 @node Bzr Hook, Bzr Poller, MercurialHook, Getting Source Code Changes
4384 @section Bzr Hook
4386 Bzr is also written in Python, and the Bzr hook depends on Twisted to send the
4387 changes.
4389 To install, put @code{contrib/bzr_buildbot.py} in one of your plugins
4390 locations a bzr plugins directory (e.g.,
4391 @code{~/.bazaar/plugins}). Then, in one of your bazaar conf files (e.g.,
4392 @code{~/.bazaar/locations.conf}), set the location you want to connect with buildbot
4393 with these keys:
4395 @table @code
4396 @item buildbot_on
4397 one of 'commit', 'push, or 'change'. Turns the plugin on to report changes via
4398 commit, changes via push, or any changes to the trunk. 'change' is
4399 recommended.
4401 @item buildbot_server
4402 (required to send to a buildbot master) the URL of the buildbot master to
4403 which you will connect (as of this writing, the same server and port to which
4404 slaves connect).
4406 @item buildbot_port
4407 (optional, defaults to 9989) the port of the buildbot master to which you will
4408 connect (as of this writing, the same server and port to which slaves connect)
4410 @item buildbot_pqm
4411 (optional, defaults to not pqm) Normally, the user that commits the revision
4412 is the user that is responsible for the change. When run in a pqm (Patch Queue
4413 Manager, see https://launchpad.net/pqm) environment, the user that commits is
4414 the Patch Queue Manager, and the user that committed the *parent* revision is
4415 responsible for the change. To turn on the pqm mode, set this value to any of
4416 (case-insensitive) "Yes", "Y", "True", or "T".
4418 @item buildbot_dry_run
4419 (optional, defaults to not a dry run) Normally, the post-commit hook will
4420 attempt to communicate with the configured buildbot server and port. If this
4421 parameter is included and any of (case-insensitive) "Yes", "Y", "True", or
4422 "T", then the hook will simply print what it would have sent, but not attempt
4423 to contact the buildbot master.
4425 @item buildbot_send_branch_name
4426 (optional, defaults to not sending the branch name) If your buildbot's bzr
4427 source build step uses a repourl, do *not* turn this on. If your buildbot's
4428 bzr build step uses a baseURL, then you may set this value to any of
4429 (case-insensitive) "Yes", "Y", "True", or "T" to have the buildbot master
4430 append the branch name to the baseURL.
4432 @end table
4434 When buildbot no longer has a hardcoded password, it will be a configuration
4435 option here as well.
4437 Here's a simple example that you might have in your
4438 @code{~/.bazaar/locations.conf}.
4440 @example
4441 [chroot-*:///var/local/myrepo/mybranch]
4442 buildbot_on = change
4443 buildbot_server = localhost
4444 @end example
4446 @node Bzr Poller, , Bzr Hook, Getting Source Code Changes
4447 @section Bzr Poller
4449 If you cannot insert a Bzr hook in the server, you can use the Bzr Poller. To
4450 use, put @code{contrib/bzr_buildbot.py} somewhere that your buildbot
4451 configuration can import it. Even putting it in the same directory as the master.cfg
4452 should work. Install the poller in the buildbot configuration as with any
4453 other change source. Minimally, provide a URL that you want to poll (bzr://,
4454 bzr+ssh://, or lp:), though make sure the buildbot user has necessary
4455 privileges. You may also want to specify these optional values.
4457 @table @code
4458 @item poll_interval
4459 The number of seconds to wait between polls.  Defaults to 10 minutes.
4461 @item branch_name
4462 Any value to be used as the branch name. Defaults to None, or specify a
4463 string, or specify the constants from @code{bzr_buildbot.py} SHORT or FULL to
4464 get the short branch name or full branch address.
4466 @item blame_merge_author
4467 normally, the user that commits the revision is the user that is responsible
4468 for the change. When run in a pqm (Patch Queue Manager, see
4469 https://launchpad.net/pqm) environment, the user that commits is the Patch
4470 Queue Manager, and the user that committed the merged, *parent* revision is
4471 responsible for the change. set this value to True if this is pointed against
4472 a PQM-managed branch.
4473 @end table
4475 @node Build Process, Status Delivery, Getting Source Code Changes, Top
4476 @chapter Build Process
4478 A @code{Build} object is responsible for actually performing a build.
4479 It gets access to a remote @code{SlaveBuilder} where it may run
4480 commands, and a @code{BuildStatus} object where it must emit status
4481 events. The @code{Build} is created by the Builder's
4482 @code{BuildFactory}.
4484 The default @code{Build} class is made up of a fixed sequence of
4485 @code{BuildSteps}, executed one after another until all are complete
4486 (or one of them indicates that the build should be halted early). The
4487 default @code{BuildFactory} creates instances of this @code{Build}
4488 class with a list of @code{BuildSteps}, so the basic way to configure
4489 the build is to provide a list of @code{BuildSteps} to your
4490 @code{BuildFactory}.
4492 More complicated @code{Build} subclasses can make other decisions:
4493 execute some steps only if certain files were changed, or if certain
4494 previous steps passed or failed. The base class has been written to
4495 allow users to express basic control flow without writing code, but
4496 you can always subclass and customize to achieve more specialized
4497 behavior.
4499 @menu
4500 * Build Steps::
4501 * Interlocks::
4502 * Build Factories::
4503 @end menu
4505 @node Build Steps, Interlocks, Build Process, Build Process
4506 @section Build Steps
4508 @code{BuildStep}s are usually specified in the buildmaster's
4509 configuration file, in a list that goes into the @code{BuildFactory}.
4510 The @code{BuildStep} instances in this list are used as templates to
4511 construct new independent copies for each build (so that state can be
4512 kept on the @code{BuildStep} in one build without affecting a later
4513 build). Each @code{BuildFactory} can be created with a list of steps,
4514 or the factory can be created empty and then steps added to it using
4515 the @code{addStep} method:
4517 @example
4518 from buildbot.steps import source, shell
4519 from buildbot.process import factory
4521 f = factory.BuildFactory()
4522 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
4523 f.addStep(shell.ShellCommand(command=["make", "all"]))
4524 f.addStep(shell.ShellCommand(command=["make", "test"]))
4525 @end example
4527 In earlier versions (0.7.5 and older), these steps were specified with
4528 a tuple of (step_class, keyword_arguments). Steps can still be
4529 specified this way, but the preferred form is to pass actual
4530 @code{BuildStep} instances to @code{addStep}, because that gives the
4531 @code{BuildStep} class a chance to do some validation on the
4532 arguments.
4534 If you have a common set of steps which are used in several factories, the
4535 @code{addSteps} method may be handy.  It takes an iterable of @code{BuildStep}
4536 instances.
4538 @example
4539 setup_steps = [
4540     source.SVN(svnurl="http://svn.example.org/Trunk/")
4541     shell.ShellCommand(command="./setup")
4543 quick = factory.BuildFactory()
4544 quick.addSteps(setup_steps)
4545 quick.addStep(shell.shellCommand(command="make quick"))
4546 @end example
4548 The rest of this section lists all the standard BuildStep objects
4549 available for use in a Build, and the parameters which can be used to
4550 control each.
4552 @menu
4553 * Common Parameters::
4554 * Using Build Properties::
4555 * Source Checkout::
4556 * ShellCommand::
4557 * Simple ShellCommand Subclasses::
4558 * Python BuildSteps::
4559 * Transferring Files::
4560 * Triggering Schedulers::
4561 * Writing New BuildSteps::
4562 @end menu
4564 @node Common Parameters, Using Build Properties, Build Steps, Build Steps
4565 @subsection Common Parameters
4567 The standard @code{Build} runs a series of @code{BuildStep}s in order,
4568 only stopping when it runs out of steps or if one of them requests
4569 that the build be halted. It collects status information from each one
4570 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
4572 All BuildSteps accept some common parameters. Some of these control
4573 how their individual status affects the overall build. Others are used
4574 to specify which @code{Locks} (see @pxref{Interlocks}) should be
4575 acquired before allowing the step to run.
4577 Arguments common to all @code{BuildStep} subclasses:
4580 @table @code
4581 @item name
4582 the name used to describe the step on the status display. It is also
4583 used to give a name to any LogFiles created by this step.
4585 @item haltOnFailure
4586 if True, a FAILURE of this build step will cause the build to halt
4587 immediately with an overall result of FAILURE. Steps with
4588 @code{alwaysRun=True} are still run.
4590 @item flunkOnWarnings
4591 when True, a WARNINGS or FAILURE of this build step will mark the
4592 overall build as FAILURE. The remaining steps will still be executed.
4594 @item flunkOnFailure
4595 when True, a FAILURE of this build step will mark the overall build as
4596 a FAILURE. The remaining steps will still be executed.
4598 @item warnOnWarnings
4599 when True, a WARNINGS or FAILURE of this build step will mark the
4600 overall build as having WARNINGS. The remaining steps will still be
4601 executed.
4603 @item warnOnFailure
4604 when True, a FAILURE of this build step will mark the overall build as
4605 having WARNINGS. The remaining steps will still be executed.
4607 @item alwaysRun
4608 if True, this build step will always be run, even if a previous buildstep
4609 with @code{haltOnFailure=True} has failed.
4611 @item locks
4612 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
4613 @code{buildbot.locks.MasterLock}) that should be acquired before
4614 starting this Step. The Locks will be released when the step is
4615 complete. Note that this is a list of actual Lock instances, not
4616 names. Also note that all Locks must have unique names.
4618 @end table
4620 @node Using Build Properties, Source Checkout, Common Parameters, Build Steps
4621 @subsection Using Build Properties
4622 @cindex Properties
4624 Build properties are a generalized way to provide configuration
4625 information to build steps; see @ref{Build Properties}.
4627 Some build properties are inherited from external sources -- global
4628 properties, schedulers, or buildslaves.  Some build properties are
4629 set when the build starts, such as the SourceStamp information. Other
4630 properties can be set by BuildSteps as they run, for example the
4631 various Source steps will set the @code{got_revision} property to the
4632 source revision that was actually checked out (which can be useful
4633 when the SourceStamp in use merely requested the ``latest revision'':
4634 @code{got_revision} will tell you what was actually built).
4636 In custom BuildSteps, you can get and set the build properties with
4637 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4638 for the name of the property, and returns or accepts an
4639 arbitrary@footnote{Build properties are serialized along with the
4640 build results, so they must be serializable. For this reason, the
4641 value of any build property should be simple inert data: strings,
4642 numbers, lists, tuples, and dictionaries. They should not contain
4643 class instances.} object. For example:
4645 @example
4646 class MakeTarball(ShellCommand):
4647     def start(self):
4648         if self.getProperty("os") == "win":
4649             self.setCommand([ ... ]) # windows-only command
4650         else:
4651             self.setCommand([ ... ]) # equivalent for other systems
4652         ShellCommand.start(self)
4653 @end example
4655 @heading WithProperties
4656 @cindex WithProperties
4658 You can use build properties in ShellCommands by using the
4659 @code{WithProperties} wrapper when setting the arguments of
4660 the ShellCommand. This interpolates the named build properties
4661 into the generated shell command.  Most step parameters accept
4662 @code{WithProperties}.  Please file bugs for any parameters which
4663 do not.
4665 @example
4666 from buildbot.steps.shell import ShellCommand
4667 from buildbot.process.properties import WithProperties
4669 f.addStep(ShellCommand(
4670           command=["tar", "czf",
4671                    WithProperties("build-%s.tar.gz", "revision"),
4672                    "source"]))
4673 @end example
4675 If this BuildStep were used in a tree obtained from Subversion, it
4676 would create a tarball with a name like @file{build-1234.tar.gz}.
4678 The @code{WithProperties} function does @code{printf}-style string
4679 interpolation, using strings obtained by calling
4680 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4681 @code{%d}, etc), you must have exactly one additional argument to
4682 indicate which build property you want to insert.
4684 You can also use python dictionary-style string interpolation by using
4685 the @code{%(propname)s} syntax. In this form, the property name goes
4686 in the parentheses, and WithProperties takes @emph{no} additional
4687 arguments:
4689 @example
4690 f.addStep(ShellCommand(
4691           command=["tar", "czf",
4692                    WithProperties("build-%(revision)s.tar.gz"),
4693                    "source"]))
4694 @end example
4696 Don't forget the extra ``s'' after the closing parenthesis! This is
4697 the cause of many confusing errors.
4699 The dictionary-style interpolation supports a number of more advanced
4700 syntaxes, too.
4702 @table @code
4704 @item propname:-replacement
4705 If @code{propname} exists, substitute its value; otherwise,
4706 substitute @code{replacement}.  @code{replacement} may be empty
4707 (@code{%(propname:-)s})
4709 @item propname:+replacement
4710 If @code{propname} exists, substitute @code{replacement}; otherwise,
4711 substitute an empty string.
4713 @end table
4715 Although these are similar to shell substitutions, no other
4716 substitutions are currently supported, and @code{replacement} in the
4717 above cannot contain more substitutions.
4719 Note: like python, you can either do positional-argument interpolation
4720 @emph{or} keyword-argument interpolation, not both. Thus you cannot use
4721 a string like @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4723 @heading Common Build Properties
4725 The following build properties are set when the build is started, and
4726 are available to all steps.
4728 @table @code
4729 @item branch
4731 This comes from the build's SourceStamp, and describes which branch is
4732 being checked out. This will be @code{None} (which interpolates into
4733 @code{WithProperties} as an empty string) if the build is on the
4734 default branch, which is generally the trunk. Otherwise it will be a
4735 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4736 system being used.
4738 @item revision
4740 This also comes from the SourceStamp, and is the revision of the
4741 source code tree that was requested from the VC system. When a build
4742 is requested of a specific revision (as is generally the case when
4743 the build is triggered by Changes), this will contain the revision
4744 specification. The syntax depends upon the VC system in use: for SVN
4745 it is an integer, for Mercurial it is a short string, for Darcs it
4746 is a rather large string, etc.
4748 If the ``force build'' button was pressed, the revision will be
4749 @code{None}, which means to use the most recent revision available.
4750 This is a ``trunk build''. This will be interpolated as an empty
4751 string.
4753 @item got_revision
4755 This is set when a Source step checks out the source tree, and
4756 provides the revision that was actually obtained from the VC system.
4757 In general this should be the same as @code{revision}, except for
4758 trunk builds, where @code{got_revision} indicates what revision was
4759 current when the checkout was performed. This can be used to rebuild
4760 the same source code later.
4762 Note that for some VC systems (Darcs in particular), the revision is a
4763 large string containing newlines, and is not suitable for interpolation
4764 into a filename.
4766 @item buildername
4768 This is a string that indicates which Builder the build was a part of.
4769 The combination of buildername and buildnumber uniquely identify a
4770 build.
4772 @item buildnumber
4774 Each build gets a number, scoped to the Builder (so the first build
4775 performed on any given Builder will have a build number of 0). This
4776 integer property contains the build's number.
4778 @item slavename
4780 This is a string which identifies which buildslave the build is
4781 running on.
4783 @item scheduler
4785 If the build was started from a scheduler, then this property will
4786 contain the name of that scheduler.
4788 @end table
4791 @node Source Checkout, ShellCommand, Using Build Properties, Build Steps
4792 @subsection Source Checkout
4794 The first step of any build is typically to acquire the source code
4795 from which the build will be performed. There are several classes to
4796 handle this, one for each of the different source control system that
4797 Buildbot knows about. For a description of how Buildbot treats source
4798 control in general, see @ref{Version Control Systems}.
4800 All source checkout steps accept some common parameters to control how
4801 they get the sources and where they should be placed. The remaining
4802 per-VC-system parameters are mostly to specify where exactly the
4803 sources are coming from.
4805 @table @code
4806 @item mode
4808 a string describing the kind of VC operation that is desired. Defaults
4809 to @code{update}.
4811 @table @code
4812 @item update
4813 specifies that the CVS checkout/update should be performed directly
4814 into the workdir. Each build is performed in the same directory,
4815 allowing for incremental builds. This minimizes disk space, bandwidth,
4816 and CPU time. However, it may encounter problems if the build process
4817 does not handle dependencies properly (sometimes you must do a ``clean
4818 build'' to make sure everything gets compiled), or if source files are
4819 deleted but generated files can influence test behavior (e.g. python's
4820 .pyc files), or when source directories are deleted but generated
4821 files prevent CVS from removing them. Builds ought to be correct
4822 regardless of whether they are done ``from scratch'' or incrementally,
4823 but it is useful to test both kinds: this mode exercises the
4824 incremental-build style.
4826 @item copy
4827 specifies that the CVS workspace should be maintained in a separate
4828 directory (called the 'copydir'), using checkout or update as
4829 necessary. For each build, a new workdir is created with a copy of the
4830 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
4831 disk space required, but keeps the bandwidth low (update instead of a
4832 full checkout). A full 'clean' build is performed each time. This
4833 avoids any generated-file build problems, but is still occasionally
4834 vulnerable to CVS problems such as a repository being manually
4835 rearranged, causing CVS errors on update which are not an issue with a
4836 full checkout.
4838 @c TODO: something is screwy about this, revisit. Is it the source
4839 @c directory or the working directory that is deleted each time?
4841 @item clobber
4842 specifes that the working directory should be deleted each time,
4843 necessitating a full checkout for each build. This insures a clean
4844 build off a complete checkout, avoiding any of the problems described
4845 above. This mode exercises the ``from-scratch'' build style.
4847 @item export
4848 this is like @code{clobber}, except that the 'cvs export' command is
4849 used to create the working directory. This command removes all CVS
4850 metadata files (the CVS/ directories) from the tree, which is
4851 sometimes useful for creating source tarballs (to avoid including the
4852 metadata in the tar file).
4853 @end table
4855 @item workdir
4856 like all Steps, this indicates the directory where the build will take
4857 place. Source Steps are special in that they perform some operations
4858 outside of the workdir (like creating the workdir itself).
4860 @item alwaysUseLatest
4861 if True, bypass the usual ``update to the last Change'' behavior, and
4862 always update to the latest changes instead.
4864 @item retry
4865 If set, this specifies a tuple of @code{(delay, repeats)} which means
4866 that when a full VC checkout fails, it should be retried up to
4867 @var{repeats} times, waiting @var{delay} seconds between attempts. If
4868 you don't provide this, it defaults to @code{None}, which means VC
4869 operations should not be retried. This is provided to make life easier
4870 for buildslaves which are stuck behind poor network connections.
4872 @end table
4875 My habit as a developer is to do a @code{cvs update} and @code{make} each
4876 morning. Problems can occur, either because of bad code being checked in, or
4877 by incomplete dependencies causing a partial rebuild to fail where a
4878 complete from-scratch build might succeed. A quick Builder which emulates
4879 this incremental-build behavior would use the @code{mode='update'}
4880 setting.
4882 On the other hand, other kinds of dependency problems can cause a clean
4883 build to fail where a partial build might succeed. This frequently results
4884 from a link step that depends upon an object file that was removed from a
4885 later version of the tree: in the partial tree, the object file is still
4886 around (even though the Makefiles no longer know how to create it).
4888 ``official'' builds (traceable builds performed from a known set of
4889 source revisions) are always done as clean builds, to make sure it is
4890 not influenced by any uncontrolled factors (like leftover files from a
4891 previous build). A ``full'' Builder which behaves this way would want
4892 to use the @code{mode='clobber'} setting.
4894 Each VC system has a corresponding source checkout class: their
4895 arguments are described on the following pages.
4898 @menu
4899 * CVS::
4900 * SVN::
4901 * Darcs::
4902 * Mercurial::
4903 * Arch::
4904 * Bazaar::
4905 * Bzr::
4906 * P4::
4907 * Git::
4908 @end menu
4910 @node CVS, SVN, Source Checkout, Source Checkout
4911 @subsubsection CVS
4912 @cindex CVS Checkout
4913 @bsindex buildbot.steps.source.CVS
4916 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
4917 CVS} checkout or update. It takes the following arguments:
4919 @table @code
4920 @item cvsroot
4921 (required): specify the CVSROOT value, which points to a CVS
4922 repository, probably on a remote machine. For example, the cvsroot
4923 value you would use to get a copy of the Buildbot source code is
4924 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
4926 @item cvsmodule
4927 (required): specify the cvs @code{module}, which is generally a
4928 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
4929 code is @code{buildbot}.
4931 @item branch
4932 a string which will be used in a @code{-r} argument. This is most
4933 useful for specifying a branch to work on. Defaults to @code{HEAD}.
4935 @item global_options
4936 a list of flags to be put before the verb in the CVS command.
4938 @item checkoutDelay
4939 if set, the number of seconds to put between the timestamp of the last
4940 known Change and the value used for the @code{-D} option. Defaults to
4941 half of the parent Build's treeStableTimer.
4943 @end table
4946 @node SVN, Darcs, CVS, Source Checkout
4947 @subsubsection SVN
4949 @cindex SVN Checkout
4950 @bsindex buildbot.steps.source.SVN
4953 The @code{SVN} build step performs a
4954 @uref{http://subversion.tigris.org, Subversion} checkout or update.
4955 There are two basic ways of setting up the checkout step, depending
4956 upon whether you are using multiple branches or not.
4958 If all of your builds use the same branch, then you should create the
4959 @code{SVN} step with the @code{svnurl} argument:
4961 @table @code
4962 @item svnurl
4963 (required): this specifies the @code{URL} argument that will be given
4964 to the @code{svn checkout} command. It dictates both where the
4965 repository is located and which sub-tree should be extracted. In this
4966 respect, it is like a combination of the CVS @code{cvsroot} and
4967 @code{cvsmodule} arguments. For example, if you are using a remote
4968 Subversion repository which is accessible through HTTP at a URL of
4969 @code{http://svn.example.com/repos}, and you wanted to check out the
4970 @code{trunk/calc} sub-tree, you would use
4971 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
4972 to your @code{SVN} step.
4973 @end table
4975 If, on the other hand, you are building from multiple branches, then
4976 you should create the @code{SVN} step with the @code{baseURL} and
4977 @code{defaultBranch} arguments instead:
4979 @table @code
4980 @item baseURL
4981 (required): this specifies the base repository URL, to which a branch
4982 name will be appended. It should probably end in a slash.
4984 @item defaultBranch
4985 this specifies the name of the branch to use when a Build does not
4986 provide one of its own. This will be appended to @code{baseURL} to
4987 create the string that will be passed to the @code{svn checkout}
4988 command.
4989 @end table
4991 If you are using branches, you must also make sure your
4992 @code{ChangeSource} will report the correct branch names.
4994 @heading branch example
4996 Let's suppose that the ``MyProject'' repository uses branches for the
4997 trunk, for various users' individual development efforts, and for
4998 several new features that will require some amount of work (involving
4999 multiple developers) before they are ready to merge onto the trunk.
5000 Such a repository might be organized as follows:
5002 @example
5003 svn://svn.example.org/MyProject/trunk
5004 svn://svn.example.org/MyProject/branches/User1/foo
5005 svn://svn.example.org/MyProject/branches/User1/bar
5006 svn://svn.example.org/MyProject/branches/User2/baz
5007 svn://svn.example.org/MyProject/features/newthing
5008 svn://svn.example.org/MyProject/features/otherthing
5009 @end example
5011 Further assume that we want the Buildbot to run tests against the
5012 trunk and against all the feature branches (i.e., do a
5013 checkout/compile/build of branch X when a file has been changed on
5014 branch X, when X is in the set [trunk, features/newthing,
5015 features/otherthing]). We do not want the Buildbot to automatically
5016 build any of the user branches, but it should be willing to build a
5017 user branch when explicitly requested (most likely by the user who
5018 owns that branch).
5020 There are three things that need to be set up to accomodate this
5021 system. The first is a ChangeSource that is capable of identifying the
5022 branch which owns any given file. This depends upon a user-supplied
5023 function, in an external program that runs in the SVN commit hook and
5024 connects to the buildmaster's @code{PBChangeSource} over a TCP
5025 connection. (you can use the ``@code{buildbot sendchange}'' utility
5026 for this purpose, but you will still need an external program to
5027 decide what value should be passed to the @code{--branch=} argument).
5028 For example, a change to a file with the SVN url of
5029 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
5030 be broken down into a Change instance with
5031 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
5033 The second piece is an @code{AnyBranchScheduler} which will pay
5034 attention to the desired branches. It will not pay attention to the
5035 user branches, so it will not automatically start builds in response
5036 to changes there. The AnyBranchScheduler class requires you to
5037 explicitly list all the branches you want it to use, but it would not
5038 be difficult to write a subclass which used
5039 @code{branch.startswith('features/'} to remove the need for this
5040 explicit list. Or, if you want to build user branches too, you can use
5041 AnyBranchScheduler with @code{branches=None} to indicate that you want
5042 it to pay attention to all branches.
5044 The third piece is an @code{SVN} checkout step that is configured to
5045 handle the branches correctly, with a @code{baseURL} value that
5046 matches the way the ChangeSource splits each file's URL into base,
5047 branch, and file.
5049 @example
5050 from buildbot.changes.pb import PBChangeSource
5051 from buildbot.scheduler import AnyBranchScheduler
5052 from buildbot.process import source, factory
5053 from buildbot.steps import source, shell
5055 c['change_source'] = PBChangeSource()
5056 s1 = AnyBranchScheduler('main',
5057                         ['trunk', 'features/newthing', 'features/otherthing'],
5058                         10*60, ['test-i386', 'test-ppc'])
5059 c['schedulers'] = [s1]
5061 f = factory.BuildFactory()
5062 f.addStep(source.SVN(mode='update',
5063                      baseURL='svn://svn.example.org/MyProject/',
5064                      defaultBranch='trunk'))
5065 f.addStep(shell.Compile(command="make all"))
5066 f.addStep(shell.Test(command="make test"))
5068 c['builders'] = [
5069   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
5070                        'factory':f @},
5071   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
5072                       'factory':f @},
5074 @end example
5076 In this example, when a change arrives with a @code{branch} attribute
5077 of ``trunk'', the resulting build will have an SVN step that
5078 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
5079 ``trunk'' (the branch name) to get the correct svn command. If the
5080 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
5081 will concatenate ``svn://svn.example.org/MyProject/'' with
5082 ``features/newthing'' to get the svnurl for checkout.
5084 @node Darcs, Mercurial, SVN, Source Checkout
5085 @subsubsection Darcs
5087 @cindex Darcs Checkout
5088 @bsindex buildbot.steps.source.Darcs
5091 The @code{Darcs} build step performs a
5092 @uref{http://darcs.net/, Darcs} checkout or update.
5094 Like @xref{SVN}, this step can either be configured to always check
5095 out a specific tree, or set up to pull from a particular branch that
5096 gets specified separately for each build. Also like SVN, the
5097 repository URL given to Darcs is created by concatenating a
5098 @code{baseURL} with the branch name, and if no particular branch is
5099 requested, it uses a @code{defaultBranch}. The only difference in
5100 usage is that each potential Darcs repository URL must point to a
5101 fully-fledged repository, whereas SVN URLs usually point to sub-trees
5102 of the main Subversion repository. In other words, doing an SVN
5103 checkout of @code{baseURL} is legal, but silly, since you'd probably
5104 wind up with a copy of every single branch in the whole repository.
5105 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
5106 the parent directory of a collection of Darcs repositories is not
5107 itself a valid repository.
5109 The Darcs step takes the following arguments:
5111 @table @code
5112 @item repourl
5113 (required unless @code{baseURL} is provided): the URL at which the
5114 Darcs source repository is available.
5116 @item baseURL
5117 (required unless @code{repourl} is provided): the base repository URL,
5118 to which a branch name will be appended. It should probably end in a
5119 slash.
5121 @item defaultBranch
5122 (allowed if and only if @code{baseURL} is provided): this specifies
5123 the name of the branch to use when a Build does not provide one of its
5124 own. This will be appended to @code{baseURL} to create the string that
5125 will be passed to the @code{darcs get} command.
5126 @end table
5128 @node Mercurial, Arch, Darcs, Source Checkout
5129 @subsubsection Mercurial
5131 @cindex Mercurial Checkout
5132 @bsindex buildbot.steps.source.Mercurial
5135 The @code{Mercurial} build step performs a
5136 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
5137 or update.
5139 Branches are handled just like @xref{Darcs}.
5141 The Mercurial step takes the following arguments:
5143 @table @code
5144 @item repourl
5145 (required unless @code{baseURL} is provided): the URL at which the
5146 Mercurial source repository is available.
5148 @item baseURL
5149 (required unless @code{repourl} is provided): the base repository URL,
5150 to which a branch name will be appended. It should probably end in a
5151 slash.
5153 @item defaultBranch
5154 (allowed if and only if @code{baseURL} is provided): this specifies
5155 the name of the branch to use when a Build does not provide one of its
5156 own. This will be appended to @code{baseURL} to create the string that
5157 will be passed to the @code{hg clone} command.
5158 @end table
5161 @node Arch, Bazaar, Mercurial, Source Checkout
5162 @subsubsection Arch
5164 @cindex Arch Checkout
5165 @bsindex buildbot.steps.source.Arch
5168 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
5169 Arch} checkout or update using the @code{tla} client. It takes the
5170 following arguments:
5172 @table @code
5173 @item url
5174 (required): this specifies the URL at which the Arch source archive is
5175 available.
5177 @item version
5178 (required): this specifies which ``development line'' (like a branch)
5179 should be used. This provides the default branch name, but individual
5180 builds may specify a different one.
5182 @item archive
5183 (optional): Each repository knows its own archive name. If this
5184 parameter is provided, it must match the repository's archive name.
5185 The parameter is accepted for compatibility with the @code{Bazaar}
5186 step, below.
5188 @end table
5190 @node Bazaar, Bzr, Arch, Source Checkout
5191 @subsubsection Bazaar
5193 @cindex Bazaar Checkout
5194 @bsindex buildbot.steps.source.Bazaar
5197 @code{Bazaar} is an alternate implementation of the Arch VC system,
5198 which uses a client named @code{baz}. The checkout semantics are just
5199 different enough from @code{tla} that there is a separate BuildStep for
5202 It takes exactly the same arguments as @code{Arch}, except that the
5203 @code{archive=} parameter is required. (baz does not emit the archive
5204 name when you do @code{baz register-archive}, so we must provide it
5205 ourselves).
5208 @node Bzr, P4, Bazaar, Source Checkout
5209 @subsubsection Bzr
5211 @cindex Bzr Checkout
5212 @bsindex buildbot.steps.source.Bzr
5214 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
5215 as simply ``Bazaar''. The repository-vs-workspace model is similar to
5216 Darcs, but it uses a strictly linear sequence of revisions (one
5217 history per branch) like Arch. Branches are put in subdirectories.
5218 This makes it look very much like Mercurial, so it takes the same
5219 arguments:
5221 @table @code
5223 @item repourl
5224 (required unless @code{baseURL} is provided): the URL at which the
5225 Bzr source repository is available.
5227 @item baseURL
5228 (required unless @code{repourl} is provided): the base repository URL,
5229 to which a branch name will be appended. It should probably end in a
5230 slash.
5232 @item defaultBranch
5233 (allowed if and only if @code{baseURL} is provided): this specifies
5234 the name of the branch to use when a Build does not provide one of its
5235 own. This will be appended to @code{baseURL} to create the string that
5236 will be passed to the @code{bzr checkout} command.
5237 @end table
5241 @node P4, Git, Bzr, Source Checkout
5242 @subsubsection P4
5244 @cindex Perforce Update
5245 @bsindex buildbot.steps.source.P4
5246 @c TODO @bsindex buildbot.steps.source.P4Sync
5249 The @code{P4} build step creates a @uref{http://www.perforce.com/,
5250 Perforce} client specification and performs an update.
5252 @table @code
5253 @item p4base
5254 A view into the Perforce depot without branch name or trailing "...".
5255 Typically "//depot/proj/".
5256 @item defaultBranch
5257 A branch name to append on build requests if none is specified.
5258 Typically "trunk".
5259 @item p4port
5260 (optional): the host:port string describing how to get to the P4 Depot
5261 (repository), used as the -p argument for all p4 commands.
5262 @item p4user
5263 (optional): the Perforce user, used as the -u argument to all p4
5264 commands.
5265 @item p4passwd
5266 (optional): the Perforce password, used as the -p argument to all p4
5267 commands.
5268 @item p4extra_views
5269 (optional): a list of (depotpath, clientpath) tuples containing extra
5270 views to be mapped into the client specification. Both will have
5271 "/..." appended automatically. The client name and source directory
5272 will be prepended to the client path.
5273 @item p4client
5274 (optional): The name of the client to use. In mode='copy' and
5275 mode='update', it's particularly important that a unique name is used
5276 for each checkout directory to avoid incorrect synchronization. For
5277 this reason, Python percent substitution will be performed on this value
5278 to replace %(slave)s with the slave name and %(builder)s with the
5279 builder name. The default is "buildbot_%(slave)s_%(build)s".
5280 @end table
5283 @node Git,  , P4, Source Checkout
5284 @subsubsection Git
5286 @cindex Git Checkout
5287 @bsindex buildbot.steps.source.Git
5289 The @code{Git} build step clones or updates a @uref{http://git.or.cz/,
5290 Git} repository and checks out the specified branch or revision. Note
5291 that the buildbot supports Git version 1.2.0 and later: earlier
5292 versions (such as the one shipped in Ubuntu 'Dapper') do not support
5293 the @command{git init} command that the buildbot uses.
5295 The Git step takes the following arguments:
5297 @table @code
5298 @item repourl
5299 (required): the URL of the upstream Git repository.
5301 @item branch
5302 (optional): this specifies the name of the branch to use when a Build
5303 does not provide one of its own. If this this parameter is not
5304 specified, and the Build does not provide a branch, the ``master''
5305 branch will be used.
5306 @end table
5309 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
5310 @subsection ShellCommand
5312 @bsindex buildbot.steps.shell.ShellCommand
5313 @c TODO @bsindex buildbot.steps.shell.TreeSize
5315 This is a useful base class for just about everything you might want
5316 to do during a build (except for the initial source checkout). It runs
5317 a single command in a child shell on the buildslave. All stdout/stderr
5318 is recorded into a LogFile. The step finishes with a status of FAILURE
5319 if the command's exit code is non-zero, otherwise it has a status of
5320 SUCCESS.
5322 The preferred way to specify the command is with a list of argv strings,
5323 since this allows for spaces in filenames and avoids doing any fragile
5324 shell-escaping. You can also specify the command with a single string, in
5325 which case the string is given to '/bin/sh -c COMMAND' for parsing.
5327 On Windows, commands are run via @code{cmd.exe /c} which works well. However,
5328 if you're running a batch file, the error level does not get propagated
5329 correctly unless you add 'call' before your batch file's name:
5330 @code{cmd=['call', 'myfile.bat', ...]}.
5332 All ShellCommands are run by default in the ``workdir'', which
5333 defaults to the ``@file{build}'' subdirectory of the slave builder's
5334 base directory. The absolute path of the workdir will thus be the
5335 slave's basedir (set as an option to @code{buildbot create-slave},
5336 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
5337 builder's @code{c['builddir']} key in master.cfg) plus the workdir
5338 itself (a class-level attribute of the BuildFactory, defaults to
5339 ``@file{build}'').
5341 @code{ShellCommand} arguments:
5343 @table @code
5344 @item command
5345 a list of strings (preferred) or single string (discouraged) which
5346 specifies the command to be run. A list of strings is preferred
5347 because it can be used directly as an argv array. Using a single
5348 string (with embedded spaces) requires the buildslave to pass the
5349 string to /bin/sh for interpretation, which raises all sorts of
5350 difficult questions about how to escape or interpret shell
5351 metacharacters.
5353 @item env
5354 a dictionary of environment strings which will be added to the child
5355 command's environment. For example, to run tests with a different i18n
5356 language setting, you might use
5358 @example
5359 f.addStep(ShellCommand(command=["make", "test"],
5360                        env=@{'LANG': 'fr_FR'@}))
5361 @end example
5363 These variable settings will override any existing ones in the
5364 buildslave's environment or the environment specified in the
5365 Builder. The exception is PYTHONPATH, which is merged
5366 with (actually prepended to) any existing $PYTHONPATH setting. The
5367 value is treated as a list of directories to prepend, and a single
5368 string is treated like a one-item list. For example, to prepend both
5369 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
5370 to any existing $PYTHONPATH setting, you would do something like the
5371 following:
5373 @example
5374 f.addStep(ShellCommand(
5375               command=["make", "test"],
5376               env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
5377                                    "/home/buildbot/lib/python"] @}))
5378 @end example
5380 @item want_stdout
5381 if False, stdout from the child process is discarded rather than being
5382 sent to the buildmaster for inclusion in the step's LogFile.
5384 @item want_stderr
5385 like @code{want_stdout} but for stderr. Note that commands run through
5386 a PTY do not have separate stdout/stderr streams: both are merged into
5387 stdout.
5389 @item logfiles
5390 Sometimes commands will log interesting data to a local file, rather
5391 than emitting everything to stdout or stderr. For example, Twisted's
5392 ``trial'' command (which runs unit tests) only presents summary
5393 information to stdout, and puts the rest into a file named
5394 @file{_trial_temp/test.log}. It is often useful to watch these files
5395 as the command runs, rather than using @command{/bin/cat} to dump
5396 their contents afterwards.
5398 The @code{logfiles=} argument allows you to collect data from these
5399 secondary logfiles in near-real-time, as the step is running. It
5400 accepts a dictionary which maps from a local Log name (which is how
5401 the log data is presented in the build results) to a remote filename
5402 (interpreted relative to the build's working directory). Each named
5403 file will be polled on a regular basis (every couple of seconds) as
5404 the build runs, and any new text will be sent over to the buildmaster.
5406 @example
5407 f.addStep(ShellCommand(
5408               command=["make", "test"],
5409               logfiles=@{"triallog": "_trial_temp/test.log"@}))
5410 @end example
5413 @item timeout
5414 if the command fails to produce any output for this many seconds, it
5415 is assumed to be locked up and will be killed.
5417 @item description
5418 This will be used to describe the command (on the Waterfall display)
5419 while the command is still running. It should be a single
5420 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
5421 form is a list of short strings, which allows the HTML Waterfall
5422 display to create narrower columns by emitting a <br> tag between each
5423 word. You may also provide a single string.
5425 @item descriptionDone
5426 This will be used to describe the command once it has finished. A
5427 simple noun like ``compile'' or ``tests'' should be used. Like
5428 @code{description}, this may either be a list of short strings or a
5429 single string.
5431 If neither @code{description} nor @code{descriptionDone} are set, the
5432 actual command arguments will be used to construct the description.
5433 This may be a bit too wide to fit comfortably on the Waterfall
5434 display.
5436 @example
5437 f.addStep(ShellCommand(command=["make", "test"],
5438                        description=["testing"],
5439                        descriptionDone=["tests"]))
5440 @end example
5442 @end table
5444 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
5445 @subsection Simple ShellCommand Subclasses
5447 Several subclasses of ShellCommand are provided as starting points for
5448 common build steps. These are all very simple: they just override a few
5449 parameters so you don't have to specify them yourself, making the master.cfg
5450 file less verbose.
5452 @menu
5453 * Configure::
5454 * Compile::
5455 * Test::
5456 * TreeSize::
5457 * PerlModuleTest::
5458 * SetProperty::
5459 @end menu
5461 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
5462 @subsubsection Configure
5464 @bsindex buildbot.steps.shell.Configure
5466 This is intended to handle the @code{./configure} step from
5467 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
5468 MakeMaker.pm-style modules. The default command is @code{./configure}
5469 but you can change this by providing a @code{command=} parameter.
5471 @node Compile, Test, Configure, Simple ShellCommand Subclasses
5472 @subsubsection Compile
5474 @bsindex buildbot.steps.shell.Compile
5476 This is meant to handle compiling or building a project written in C.
5477 The default command is @code{make all}. When the compile is finished,
5478 the log file is scanned for GCC warning messages, a summary log is
5479 created with any problems that were seen, and the step is marked as
5480 WARNINGS if any were discovered. The number of warnings is stored in a
5481 Build Property named ``warnings-count'', which is accumulated over all
5482 Compile steps (so if two warnings are found in one step, and three are
5483 found in another step, the overall build will have a
5484 ``warnings-count'' property of 5.
5486 The default regular expression used to detect a warning is
5487 @code{'.*warning[: ].*'} , which is fairly liberal and may cause
5488 false-positives. To use a different regexp, provide a
5489 @code{warningPattern=} argument, or use a subclass which sets the
5490 @code{warningPattern} attribute:
5492 @example
5493 f.addStep(Compile(command=["make", "test"],
5494                   warningPattern="^Warning: "))
5495 @end example
5497 The @code{warningPattern=} can also be a pre-compiled python regexp
5498 object: this makes it possible to add flags like @code{re.I} (to use
5499 case-insensitive matching).
5501 (TODO: this step needs to be extended to look for GCC error messages
5502 as well, and collect them into a separate logfile, along with the
5503 source code filenames involved).
5506 @node Test, TreeSize, Compile, Simple ShellCommand Subclasses
5507 @subsubsection Test
5509 @bsindex buildbot.steps.shell.Test
5511 This is meant to handle unit tests. The default command is @code{make
5512 test}, and the @code{warnOnFailure} flag is set.
5514 @node TreeSize, PerlModuleTest, Test, Simple ShellCommand Subclasses
5515 @subsubsection TreeSize
5517 @bsindex buildbot.steps.shell.TreeSize
5519 This is a simple command that uses the 'du' tool to measure the size
5520 of the code tree. It puts the size (as a count of 1024-byte blocks,
5521 aka 'KiB' or 'kibibytes') on the step's status text, and sets a build
5522 property named 'tree-size-KiB' with the same value.
5524 @node PerlModuleTest, SetProperty, TreeSize, Simple ShellCommand Subclasses
5525 @subsubsection PerlModuleTest
5527 @bsindex buildbot.steps.shell.PerlModuleTest
5529 This is a simple command that knows how to run tests of perl modules.
5530 It parses the output to determine the number of tests passed and
5531 failed and total number executed, saving the results for later query.
5533 @node SetProperty,  , PerlModuleTest, Simple ShellCommand Subclasses
5534 @subsubsection SetProperty
5536 @bsindex buildbot.steps.shell.SetProperty
5538 This buildstep is similar to ShellCommand, except that it captures the
5539 output of the command into a property.  It is usually used like this:
5541 @example
5542 f.addStep(SetProperty(command="uname -a", property="uname"))
5543 @end example
5545 This runs @code{uname -a} and captures its stdout, stripped of leading
5546 and trailing whitespace, in the property "uname".  To avoid stripping,
5547 add @code{strip=False}.  The @code{property} argument can be specified
5548 as a @code{WithProperties} object.
5550 The more advanced usage allows you to specify a function to extract
5551 properties from the command output.  Here you can use regular
5552 expressions, string interpolation, or whatever you would like.
5553 The function is called with three arguments: the exit status of the
5554 command, its standard output as a string, and its standard error as
5555 a string.  It should return a dictionary containing all new properties.
5557 @example
5558 def glob2list(rc, stdout, stderr):
5559     jpgs = [ l.strip() for l in stdout.split('\n') ]
5560     return @{ 'jpgs' : jpgs @}
5561 f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
5562 @end example
5564 Note that any ordering relationship of the contents of stdout and
5565 stderr is lost.  For example, given
5567 @example
5568 f.addStep(SetProperty(
5569     command="echo output1; echo error >&2; echo output2",
5570     extract_fn=my_extract))
5571 @end example
5573 Then @code{my_extract} will see @code{stdout="output1\noutput2\n"}
5574 and @code{stderr="error\n"}.
5576 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
5577 @subsection Python BuildSteps
5579 Here are some BuildSteps that are specifcally useful for projects
5580 implemented in Python.
5582 @menu
5583 * BuildEPYDoc::
5584 * PyFlakes::
5585 @end menu
5587 @node BuildEPYDoc, PyFlakes, Python BuildSteps, Python BuildSteps
5588 @subsubsection BuildEPYDoc
5590 @bsindex buildbot.steps.python.BuildEPYDoc
5592 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
5593 API documentation for Python modules from their docstrings. It reads
5594 all the .py files from your source tree, processes the docstrings
5595 therein, and creates a large tree of .html files (or a single .pdf
5596 file).
5598 The @code{buildbot.steps.python.BuildEPYDoc} step will run
5599 @command{epydoc} to produce this API documentation, and will count the
5600 errors and warnings from its output.
5602 You must supply the command line to be used. The default is
5603 @command{make epydocs}, which assumes that your project has a Makefile
5604 with an ``epydocs'' target. You might wish to use something like
5605 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
5606 to add @command{--pdf} to generate a PDF file instead of a large tree
5607 of HTML files.
5609 The API docs are generated in-place in the build tree (under the
5610 workdir, in the subdirectory controlled by the ``-o'' argument). To
5611 make them useful, you will probably have to copy them to somewhere
5612 they can be read. A command like @command{rsync -ad apiref/
5613 dev.example.com:~public_html/current-apiref/} might be useful. You
5614 might instead want to bundle them into a tarball and publish it in the
5615 same place where the generated install tarball is placed.
5617 @example
5618 from buildbot.steps.python import BuildEPYDoc
5621 f.addStep(BuildEPYDoc(command=["epydoc", "-o", "apiref", "source/mypkg"]))
5622 @end example
5625 @node PyFlakes,  , BuildEPYDoc, Python BuildSteps
5626 @subsubsection PyFlakes
5628 @bsindex buildbot.steps.python.PyFlakes
5630 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
5631 to perform basic static analysis of Python code to look for simple
5632 errors, like missing imports and references of undefined names. It is
5633 like a fast and simple form of the C ``lint'' program. Other tools
5634 (like pychecker) provide more detailed results but take longer to run.
5636 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
5637 count the various kinds of errors and warnings it detects.
5639 You must supply the command line to be used. The default is
5640 @command{make pyflakes}, which assumes you have a top-level Makefile
5641 with a ``pyflakes'' target. You might want to use something like
5642 @command{pyflakes .} or @command{pyflakes src}.
5644 @example
5645 from buildbot.steps.python import PyFlakes
5648 f.addStep(PyFlakes(command=["pyflakes", "src"]))
5649 @end example
5652 @node Transferring Files, Triggering Schedulers, Python BuildSteps, Build Steps
5653 @subsection Transferring Files
5655 @cindex File Transfer
5656 @bsindex buildbot.steps.transfer.FileUpload
5657 @bsindex buildbot.steps.transfer.FileDownload
5659 Most of the work involved in a build will take place on the
5660 buildslave. But occasionally it is useful to do some work on the
5661 buildmaster side. The most basic way to involve the buildmaster is
5662 simply to move a file from the slave to the master, or vice versa.
5663 There are a pair of BuildSteps named @code{FileUpload} and
5664 @code{FileDownload} to provide this functionality. @code{FileUpload}
5665 moves a file @emph{up to} the master, while @code{FileDownload} moves
5666 a file @emph{down from} the master.
5668 As an example, let's assume that there is a step which produces an
5669 HTML file within the source tree that contains some sort of generated
5670 project documentation. We want to move this file to the buildmaster,
5671 into a @file{~/public_html} directory, so it can be visible to
5672 developers. This file will wind up in the slave-side working directory
5673 under the name @file{docs/reference.html}. We want to put it into the
5674 master-side @file{~/public_html/ref.html}.
5676 @example
5677 from buildbot.steps.shell import ShellCommand
5678 from buildbot.steps.transfer import FileUpload
5680 f.addStep(ShellCommand(command=["make", "docs"]))
5681 f.addStep(FileUpload(slavesrc="docs/reference.html",
5682                      masterdest="~/public_html/ref.html"))
5683 @end example
5685 The @code{masterdest=} argument will be passed to os.path.expanduser,
5686 so things like ``~'' will be expanded properly. Non-absolute paths
5687 will be interpreted relative to the buildmaster's base directory.
5688 Likewise, the @code{slavesrc=} argument will be expanded and
5689 interpreted relative to the builder's working directory.
5692 To move a file from the master to the slave, use the
5693 @code{FileDownload} command. For example, let's assume that some step
5694 requires a configuration file that, for whatever reason, could not be
5695 recorded in the source code repository or generated on the buildslave
5696 side:
5698 @example
5699 from buildbot.steps.shell import ShellCommand
5700 from buildbot.steps.transfer import FileUpload
5702 f.addStep(FileDownload(mastersrc="~/todays_build_config.txt",
5703                        slavedest="build_config.txt"))
5704 f.addStep(ShellCommand(command=["make", "config"]))
5705 @end example
5707 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
5708 relative to the buildmaster's base directory, and the
5709 @code{slavedest=} argument is relative to the builder's working
5710 directory. If the buildslave is running in @file{~buildslave}, and the
5711 builder's ``builddir'' is something like @file{tests-i386}, then the
5712 workdir is going to be @file{~buildslave/tests-i386/build}, and a
5713 @code{slavedest=} of @file{foo/bar.html} will get put in
5714 @file{~buildslave/tests-i386/build/foo/bar.html}. Both of these commands
5715 will create any missing intervening directories.
5717 @subheading Other Parameters
5719 The @code{maxsize=} argument lets you set a maximum size for the file
5720 to be transferred. This may help to avoid surprises: transferring a
5721 100MB coredump when you were expecting to move a 10kB status file
5722 might take an awfully long time. The @code{blocksize=} argument
5723 controls how the file is sent over the network: larger blocksizes are
5724 slightly more efficient but also consume more memory on each end, and
5725 there is a hard-coded limit of about 640kB.
5727 The @code{mode=} argument allows you to control the access permissions
5728 of the target file, traditionally expressed as an octal integer. The
5729 most common value is probably 0755, which sets the ``x'' executable
5730 bit on the file (useful for shell scripts and the like). The default
5731 value for @code{mode=} is None, which means the permission bits will
5732 default to whatever the umask of the writing process is. The default
5733 umask tends to be fairly restrictive, but at least on the buildslave
5734 you can make it less restrictive with a --umask command-line option at
5735 creation time (@pxref{Buildslave Options}).
5738 @node Triggering Schedulers, Writing New BuildSteps, Transferring Files, Build Steps
5739 @subsection Triggering Schedulers
5741 The counterpart to the Triggerable described in section
5742 @pxref{Triggerable Scheduler} is the Trigger BuildStep.
5744 @example
5745 from buildbot.steps.trigger import Trigger
5746 f.addStep(Trigger(schedulerNames=['build-prep'],
5747                   waitForFinish=True,
5748                   updateSourceStamp=True))
5749 @end example
5751 The @code{schedulerNames=} argument lists the Triggerables
5752 that should be triggered when this step is executed.  Note that
5753 it is possible, but not advisable, to create a cycle where a build
5754 continually triggers itself, because the schedulers are specified
5755 by name.
5757 If @code{waitForFinish} is True, then the step will not finish until
5758 all of the builds from the triggered schedulers have finished. If this
5759 argument is False (the default) or not given, then the buildstep
5760 succeeds immediately after triggering the schedulers.
5762 If @code{updateSourceStamp} is True (the default), then step updates
5763 the SourceStamp given to the Triggerables to include
5764 @code{got_revision} (the revision actually used in this build) as
5765 @code{revision} (the revision to use in the triggered builds). This is
5766 useful to ensure that all of the builds use exactly the same
5767 SourceStamp, even if other Changes have occurred while the build was
5768 running.
5770 @node Writing New BuildSteps,  , Triggering Schedulers, Build Steps
5771 @subsection Writing New BuildSteps
5773 While it is a good idea to keep your build process self-contained in
5774 the source code tree, sometimes it is convenient to put more
5775 intelligence into your Buildbot configuration. One was to do this is
5776 to write a custom BuildStep. Once written, this Step can be used in
5777 the @file{master.cfg} file.
5779 The best reason for writing a custom BuildStep is to better parse the
5780 results of the command being run. For example, a BuildStep that knows
5781 about JUnit could look at the logfiles to determine which tests had
5782 been run, how many passed and how many failed, and then report more
5783 detailed information than a simple @code{rc==0} -based ``good/bad''
5784 decision.
5786 TODO: add more description of BuildSteps.
5788 @menu
5789 * BuildStep LogFiles::
5790 * Reading Logfiles::
5791 * Adding LogObservers::
5792 * BuildStep URLs::
5793 @end menu
5795 @node BuildStep LogFiles, Reading Logfiles, Writing New BuildSteps, Writing New BuildSteps
5796 @subsubsection BuildStep LogFiles
5798 Each BuildStep has a collection of ``logfiles''. Each one has a short
5799 name, like ``stdio'' or ``warnings''. Each LogFile contains an
5800 arbitrary amount of text, usually the contents of some output file
5801 generated during a build or test step, or a record of everything that
5802 was printed to stdout/stderr during the execution of some command.
5804 These LogFiles are stored to disk, so they can be retrieved later.
5806 Each can contain multiple ``channels'', generally limited to three
5807 basic ones: stdout, stderr, and ``headers''. For example, when a
5808 ShellCommand runs, it writes a few lines to the ``headers'' channel to
5809 indicate the exact argv strings being run, which directory the command
5810 is being executed in, and the contents of the current environment
5811 variables. Then, as the command runs, it adds a lot of ``stdout'' and
5812 ``stderr'' messages. When the command finishes, a final ``header''
5813 line is added with the exit code of the process.
5815 Status display plugins can format these different channels in
5816 different ways. For example, the web page shows LogFiles as text/html,
5817 with header lines in blue text, stdout in black, and stderr in red. A
5818 different URL is available which provides a text/plain format, in
5819 which stdout and stderr are collapsed together, and header lines are
5820 stripped completely. This latter option makes it easy to save the
5821 results to a file and run @command{grep} or whatever against the
5822 output.
5824 Each BuildStep contains a mapping (implemented in a python dictionary)
5825 from LogFile name to the actual LogFile objects. Status plugins can
5826 get a list of LogFiles to display, for example, a list of HREF links
5827 that, when clicked, provide the full contents of the LogFile.
5829 @heading Using LogFiles in custom BuildSteps
5831 The most common way for a custom BuildStep to use a LogFile is to
5832 summarize the results of a ShellCommand (after the command has
5833 finished running). For example, a compile step with thousands of lines
5834 of output might want to create a summary of just the warning messages.
5835 If you were doing this from a shell, you would use something like:
5837 @example
5838 grep "warning:" output.log >warnings.log
5839 @end example
5841 In a custom BuildStep, you could instead create a ``warnings'' LogFile
5842 that contained the same text. To do this, you would add code to your
5843 @code{createSummary} method that pulls lines from the main output log
5844 and creates a new LogFile with the results:
5846 @example
5847     def createSummary(self, log):
5848         warnings = []
5849         for line in log.readlines():
5850             if "warning:" in line:
5851                 warnings.append()
5852         self.addCompleteLog('warnings', "".join(warnings))
5853 @end example
5855 This example uses the @code{addCompleteLog} method, which creates a
5856 new LogFile, puts some text in it, and then ``closes'' it, meaning
5857 that no further contents will be added. This LogFile will appear in
5858 the HTML display under an HREF with the name ``warnings'', since that
5859 is the name of the LogFile.
5861 You can also use @code{addHTMLLog} to create a complete (closed)
5862 LogFile that contains HTML instead of plain text. The normal LogFile
5863 will be HTML-escaped if presented through a web page, but the HTML
5864 LogFile will not. At the moment this is only used to present a pretty
5865 HTML representation of an otherwise ugly exception traceback when
5866 something goes badly wrong during the BuildStep.
5868 In contrast, you might want to create a new LogFile at the beginning
5869 of the step, and add text to it as the command runs. You can create
5870 the LogFile and attach it to the build by calling @code{addLog}, which
5871 returns the LogFile object. You then add text to this LogFile by
5872 calling methods like @code{addStdout} and @code{addHeader}. When you
5873 are done, you must call the @code{finish} method so the LogFile can be
5874 closed. It may be useful to create and populate a LogFile like this
5875 from a LogObserver method @xref{Adding LogObservers}.
5877 The @code{logfiles=} argument to @code{ShellCommand} (see
5878 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
5879 by asking the buildslave to watch a actual file on disk. The
5880 buildslave will look for additions in the target file and report them
5881 back to the BuildStep. These additions will be added to the LogFile by
5882 calling @code{addStdout}. These secondary LogFiles can be used as the
5883 source of a LogObserver just like the normal ``stdio'' LogFile.
5885 @node Reading Logfiles, Adding LogObservers, BuildStep LogFiles, Writing New BuildSteps
5886 @subsubsection Reading Logfiles
5888 Once a LogFile has been added to a BuildStep with @code{addLog()},
5889 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
5890 your BuildStep can retrieve it by using @code{getLog()}:
5892 @example
5893 class MyBuildStep(ShellCommand):
5894     logfiles = @{ "nodelog": "_test/node.log" @}
5896     def evaluateCommand(self, cmd):
5897         nodelog = self.getLog("nodelog")
5898         if "STARTED" in nodelog.getText():
5899             return SUCCESS
5900         else:
5901             return FAILURE
5902 @end example
5904 For a complete list of the methods you can call on a LogFile, please
5905 see the docstrings on the @code{IStatusLog} class in
5906 @file{buildbot/interfaces.py}.
5909 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
5910 @subsubsection Adding LogObservers
5912 @cindex LogObserver
5913 @cindex LogLineObserver
5915 Most shell commands emit messages to stdout or stderr as they operate,
5916 especially if you ask them nicely with a @code{--verbose} flag of some
5917 sort. They may also write text to a log file while they run. Your
5918 BuildStep can watch this output as it arrives, to keep track of how
5919 much progress the command has made. You can get a better measure of
5920 progress by counting the number of source files compiled or test cases
5921 run than by merely tracking the number of bytes that have been written
5922 to stdout. This improves the accuracy and the smoothness of the ETA
5923 display.
5925 To accomplish this, you will need to attach a @code{LogObserver} to
5926 one of the log channels, most commonly to the ``stdio'' channel but
5927 perhaps to another one which tracks a log file. This observer is given
5928 all text as it is emitted from the command, and has the opportunity to
5929 parse that output incrementally. Once the observer has decided that
5930 some event has occurred (like a source file being compiled), it can
5931 use the @code{setProgress} method to tell the BuildStep about the
5932 progress that this event represents.
5934 There are a number of pre-built @code{LogObserver} classes that you
5935 can choose from (defined in @code{buildbot.process.buildstep}, and of
5936 course you can subclass them to add further customization. The
5937 @code{LogLineObserver} class handles the grunt work of buffering and
5938 scanning for end-of-line delimiters, allowing your parser to operate
5939 on complete stdout/stderr lines. (Lines longer than a set maximum
5940 length are dropped; the maximum defaults to 16384 bytes, but you can
5941 change it by calling @code{setMaxLineLength()} on your
5942 @code{LogLineObserver} instance.  Use @code{sys.maxint} for effective
5943 infinity.)
5945 For example, let's take a look at the @code{TrialTestCaseCounter},
5946 which is used by the Trial step to count test cases as they are run.
5947 As Trial executes, it emits lines like the following:
5949 @example
5950 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
5951 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
5952 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
5953 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
5954 @end example
5956 When the tests are finished, trial emits a long line of ``======'' and
5957 then some lines which summarize the tests that failed. We want to
5958 avoid parsing these trailing lines, because their format is less
5959 well-defined than the ``[OK]'' lines.
5961 The parser class looks like this:
5963 @example
5964 from buildbot.process.buildstep import LogLineObserver
5966 class TrialTestCaseCounter(LogLineObserver):
5967     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
5968     numTests = 0
5969     finished = False
5971     def outLineReceived(self, line):
5972         if self.finished:
5973             return
5974         if line.startswith("=" * 40):
5975             self.finished = True
5976             return
5978         m = self._line_re.search(line.strip())
5979         if m:
5980             testname, result = m.groups()
5981             self.numTests += 1
5982             self.step.setProgress('tests', self.numTests)
5983 @end example
5985 This parser only pays attention to stdout, since that's where trial
5986 writes the progress lines. It has a mode flag named @code{finished} to
5987 ignore everything after the ``===='' marker, and a scary-looking
5988 regular expression to match each line while hopefully ignoring other
5989 messages that might get displayed as the test runs.
5991 Each time it identifies a test has been completed, it increments its
5992 counter and delivers the new progress value to the step with
5993 @code{self.step.setProgress}. This class is specifically measuring
5994 progress along the ``tests'' metric, in units of test cases (as
5995 opposed to other kinds of progress like the ``output'' metric, which
5996 measures in units of bytes). The Progress-tracking code uses each
5997 progress metric separately to come up with an overall completion
5998 percentage and an ETA value.
6000 To connect this parser into the @code{Trial} BuildStep,
6001 @code{Trial.__init__} ends with the following clause:
6003 @example
6004         # this counter will feed Progress along the 'test cases' metric
6005         counter = TrialTestCaseCounter()
6006         self.addLogObserver('stdio', counter)
6007         self.progressMetrics += ('tests',)
6008 @end example
6010 This creates a TrialTestCaseCounter and tells the step that the
6011 counter wants to watch the ``stdio'' log. The observer is
6012 automatically given a reference to the step in its @code{.step}
6013 attribute.
6015 @subheading A Somewhat Whimsical Example
6017 Let's say that we've got some snazzy new unit-test framework called
6018 Framboozle. It's the hottest thing since sliced bread. It slices, it
6019 dices, it runs unit tests like there's no tomorrow. Plus if your unit
6020 tests fail, you can use its name for a Web 2.1 startup company, make
6021 millions of dollars, and hire engineers to fix the bugs for you, while
6022 you spend your afternoons lazily hang-gliding along a scenic pacific
6023 beach, blissfully unconcerned about the state of your
6024 tests.@footnote{framboozle.com is still available. Remember, I get 10%
6025 :).}
6027 To run a Framboozle-enabled test suite, you just run the 'framboozler'
6028 command from the top of your source code tree. The 'framboozler'
6029 command emits a bunch of stuff to stdout, but the most interesting bit
6030 is that it emits the line "FNURRRGH!" every time it finishes running a
6031 test case@footnote{Framboozle gets very excited about running unit
6032 tests.}. You'd like to have a test-case counting LogObserver that
6033 watches for these lines and counts them, because counting them will
6034 help the buildbot more accurately calculate how long the build will
6035 take, and this will let you know exactly how long you can sneak out of
6036 the office for your hang-gliding lessons without anyone noticing that
6037 you're gone.
6039 This will involve writing a new BuildStep (probably named
6040 "Framboozle") which inherits from ShellCommand. The BuildStep class
6041 definition itself will look something like this:
6043 @example
6044 # START
6045 from buildbot.steps.shell import ShellCommand
6046 from buildbot.process.buildstep import LogLineObserver
6048 class FNURRRGHCounter(LogLineObserver):
6049     numTests = 0
6050     def outLineReceived(self, line):
6051         if "FNURRRGH!" in line:
6052             self.numTests += 1
6053             self.step.setProgress('tests', self.numTests)
6055 class Framboozle(ShellCommand):
6056     command = ["framboozler"]
6058     def __init__(self, **kwargs):
6059         ShellCommand.__init__(self, **kwargs)   # always upcall!
6060         counter = FNURRRGHCounter())
6061         self.addLogObserver('stdio', counter)
6062         self.progressMetrics += ('tests',)
6063 # FINISH
6064 @end example
6066 So that's the code that we want to wind up using. How do we actually
6067 deploy it?
6069 You have a couple of different options.
6071 Option 1: The simplest technique is to simply put this text
6072 (everything from START to FINISH) in your master.cfg file, somewhere
6073 before the BuildFactory definition where you actually use it in a
6074 clause like:
6076 @example
6077 f = BuildFactory()
6078 f.addStep(SVN(svnurl="stuff"))
6079 f.addStep(Framboozle())
6080 @end example
6082 Remember that master.cfg is secretly just a python program with one
6083 job: populating the BuildmasterConfig dictionary. And python programs
6084 are allowed to define as many classes as they like. So you can define
6085 classes and use them in the same file, just as long as the class is
6086 defined before some other code tries to use it.
6088 This is easy, and it keeps the point of definition very close to the
6089 point of use, and whoever replaces you after that unfortunate
6090 hang-gliding accident will appreciate being able to easily figure out
6091 what the heck this stupid "Framboozle" step is doing anyways. The
6092 downside is that every time you reload the config file, the Framboozle
6093 class will get redefined, which means that the buildmaster will think
6094 that you've reconfigured all the Builders that use it, even though
6095 nothing changed. Bleh.
6097 Option 2: Instead, we can put this code in a separate file, and import
6098 it into the master.cfg file just like we would the normal buildsteps
6099 like ShellCommand and SVN.
6101 Create a directory named ~/lib/python, put everything from START to
6102 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
6104 @example
6105  PYTHONPATH=~/lib/python buildbot start MASTERDIR
6106 @end example
6108 or use the @file{Makefile.buildbot} to control the way
6109 @command{buildbot start} works. Or add something like this to
6110 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
6112 @example
6113  export PYTHONPATH=~/lib/python
6114 @end example
6116 Once we've done this, our master.cfg can look like:
6118 @example
6119 from framboozle import Framboozle
6120 f = BuildFactory()
6121 f.addStep(SVN(svnurl="stuff"))
6122 f.addStep(Framboozle())
6123 @end example
6127 @example
6128 import framboozle
6129 f = BuildFactory()
6130 f.addStep(SVN(svnurl="stuff"))
6131 f.addStep(framboozle.Framboozle())
6132 @end example
6134 (check out the python docs for details about how "import" and "from A
6135 import B" work).
6137 What we've done here is to tell python that every time it handles an
6138 "import" statement for some named module, it should look in our
6139 ~/lib/python/ for that module before it looks anywhere else. After our
6140 directories, it will try in a bunch of standard directories too
6141 (including the one where buildbot is installed). By setting the
6142 PYTHONPATH environment variable, you can add directories to the front
6143 of this search list.
6145 Python knows that once it "import"s a file, it doesn't need to
6146 re-import it again. This means that reconfiguring the buildmaster
6147 (with "buildbot reconfig", for example) won't make it think the
6148 Framboozle class has changed every time, so the Builders that use it
6149 will not be spuriously restarted. On the other hand, you either have
6150 to start your buildmaster in a slightly weird way, or you have to
6151 modify your environment to set the PYTHONPATH variable.
6154 Option 3: Install this code into a standard python library directory
6156 Find out what your python's standard include path is by asking it:
6158 @example
6159 80:warner@@luther% python
6160 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46)
6161 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
6162 Type "help", "copyright", "credits" or "license" for more information.
6163 >>> import sys
6164 >>> import pprint
6165 >>> pprint.pprint(sys.path)
6166 ['',
6167  '/usr/lib/python24.zip',
6168  '/usr/lib/python2.4',
6169  '/usr/lib/python2.4/plat-linux2',
6170  '/usr/lib/python2.4/lib-tk',
6171  '/usr/lib/python2.4/lib-dynload',
6172  '/usr/local/lib/python2.4/site-packages',
6173  '/usr/lib/python2.4/site-packages',
6174  '/usr/lib/python2.4/site-packages/Numeric',
6175  '/var/lib/python-support/python2.4',
6176  '/usr/lib/site-python']
6177 @end example
6179 In this case, putting the code into
6180 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
6181 fine. We can use the same master.cfg "import framboozle" statement as
6182 in Option 2. By putting it in a standard include directory (instead of
6183 the decidedly non-standard ~/lib/python), we don't even have to set
6184 PYTHONPATH to anything special. The downside is that you probably have
6185 to be root to write to one of those standard include directories.
6188 Option 4: Submit the code for inclusion in the Buildbot distribution
6190 Contribute the code in an Enhancement Request on SourceForge, via
6191 http://buildbot.sf.net . Lobby, convince, coerce, bribe, badger,
6192 harass, threaten, or otherwise encourage the author to accept the
6193 patch. This lets you do something like:
6195 @example
6196 from buildbot.steps import framboozle
6197 f = BuildFactory()
6198 f.addStep(SVN(svnurl="stuff"))
6199 f.addStep(framboozle.Framboozle())
6200 @end example
6202 And then you don't even have to install framboozle.py anywhere on your
6203 system, since it will ship with Buildbot. You don't have to be root,
6204 you don't have to set PYTHONPATH. But you do have to make a good case
6205 for Framboozle being worth going into the main distribution, you'll
6206 probably have to provide docs and some unit test cases, you'll need to
6207 figure out what kind of beer the author likes, and then you'll have to
6208 wait until the next release. But in some environments, all this is
6209 easier than getting root on your buildmaster box, so the tradeoffs may
6210 actually be worth it.
6214 Putting the code in master.cfg (1) makes it available to that
6215 buildmaster instance. Putting it in a file in a personal library
6216 directory (2) makes it available for any buildmasters you might be
6217 running. Putting it in a file in a system-wide shared library
6218 directory (3) makes it available for any buildmasters that anyone on
6219 that system might be running. Getting it into the buildbot's upstream
6220 repository (4) makes it available for any buildmasters that anyone in
6221 the world might be running. It's all a matter of how widely you want
6222 to deploy that new class.
6226 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
6227 @subsubsection BuildStep URLs
6229 @cindex links
6230 @cindex BuildStep URLs
6231 @cindex addURL
6233 Each BuildStep has a collection of ``links''. Like its collection of
6234 LogFiles, each link has a name and a target URL. The web status page
6235 creates HREFs for each link in the same box as it does for LogFiles,
6236 except that the target of the link is the external URL instead of an
6237 internal link to a page that shows the contents of the LogFile.
6239 These external links can be used to point at build information hosted
6240 on other servers. For example, the test process might produce an
6241 intricate description of which tests passed and failed, or some sort
6242 of code coverage data in HTML form, or a PNG or GIF image with a graph
6243 of memory usage over time. The external link can provide an easy way
6244 for users to navigate from the buildbot's status page to these
6245 external web sites or file servers. Note that the step itself is
6246 responsible for insuring that there will be a document available at
6247 the given URL (perhaps by using @command{scp} to copy the HTML output
6248 to a @file{~/public_html/} directory on a remote web server). Calling
6249 @code{addURL} does not magically populate a web server.
6251 To set one of these links, the BuildStep should call the @code{addURL}
6252 method with the name of the link and the target URL. Multiple URLs can
6253 be set.
6255 In this example, we assume that the @command{make test} command causes
6256 a collection of HTML files to be created and put somewhere on the
6257 coverage.example.org web server, in a filename that incorporates the
6258 build number.
6260 @example
6261 class TestWithCodeCoverage(BuildStep):
6262     command = ["make", "test",
6263                WithProperties("buildnum=%s" % "buildnumber")]
6265     def createSummary(self, log):
6266         buildnumber = self.getProperty("buildnumber")
6267         url = "http://coverage.example.org/builds/%s.html" % buildnumber
6268         self.addURL("coverage", url)
6269 @end example
6271 You might also want to extract the URL from some special message
6272 output by the build process itself:
6274 @example
6275 class TestWithCodeCoverage(BuildStep):
6276     command = ["make", "test",
6277                WithProperties("buildnum=%s" % "buildnumber")]
6279     def createSummary(self, log):
6280         output = StringIO(log.getText())
6281         for line in output.readlines():
6282             if line.startswith("coverage-url:"):
6283                 url = line[len("coverage-url:"):].strip()
6284                 self.addURL("coverage", url)
6285                 return
6286 @end example
6288 Note that a build process which emits both stdout and stderr might
6289 cause this line to be split or interleaved between other lines. It
6290 might be necessary to restrict the getText() call to only stdout with
6291 something like this:
6293 @example
6294         output = StringIO("".join([c[1]
6295                                    for c in log.getChunks()
6296                                    if c[0] == LOG_CHANNEL_STDOUT]))
6297 @end example
6299 Of course if the build is run under a PTY, then stdout and stderr will
6300 be merged before the buildbot ever sees them, so such interleaving
6301 will be unavoidable.
6304 @node Interlocks, Build Factories, Build Steps, Build Process
6305 @section Interlocks
6307 @cindex locks
6308 @slindex buildbot.locks.MasterLock
6309 @slindex buildbot.locks.SlaveLock
6310 @slindex buildbot.locks.LockAccess
6312 Until now, we assumed that a master can run builds at any slave whenever
6313 needed or desired.  Some times, you want to enforce additional constraints on
6314 builds. For reasons like limited network bandwidth, old slave machines, or a
6315 self-willed data base server, you may want to limit the number of builds (or
6316 build steps) that can access a resource.
6318 The mechanism used by Buildbot is known as the read/write lock.@footnote{See
6319 http://en.wikipedia.org/wiki/Read/write_lock_pattern for more information.} It
6320 allows either many readers or a single writer but not a combination of readers
6321 and writers. The general lock has been modified and extended for use in
6322 Buildbot. Firstly, the general lock allows an infinite number of readers. In
6323 Buildbot, we often want to put an upper limit on the number of readers, for
6324 example allowing two out of five possible builds at the same time. To do this,
6325 the lock counts the number of active readers. Secondly, the terms @emph{read
6326 mode} and @emph{write mode} are confusing in Buildbot context. They have been
6327 replaced by @emph{counting mode} (since the lock counts them) and @emph{exclusive
6328 mode}.  As a result of these changes, locks in Buildbot allow a number of
6329 builds (upto some fixed number) in counting mode, or they allow one build in
6330 exclusive mode.
6332 Often, not all slaves are equal. To allow for this situation, Buildbot allows
6333 to have a separate upper limit on the count for each slave. In this way, you
6334 can have at most 3 concurrent builds at a fast slave, 2 at a slightly older
6335 slave, and 1 at all other slaves.
6337 The final thing you can specify when you introduce a new lock is its scope.
6338 Some constraints are global -- they must be enforced over all slaves. Other
6339 constraints are local to each slave.  A @emph{master lock} is used for the
6340 global constraints. You can ensure for example that at most one build (of all
6341 builds running at all slaves) accesses the data base server. With a
6342 @emph{slave lock} you can add a limit local to each slave. With such a lock,
6343 you can for example enforce an upper limit to the number of active builds at a
6344 slave, like above.
6346 Time for a few examples. Below a master lock is defined to protect a data base,
6347 and a slave lock is created to limit the number of builds at each slave.
6349 @example
6350 from buildbot import locks
6352 db_lock = locks.MasterLock("database")
6353 build_lock = locks.SlaveLock("slave_builds",
6354                              maxCount = 1,
6355                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6356 @end example
6358 After importing locks from buildbot, @code{db_lock} is defined to be a master
6359 lock. The @code{"database"} string is used for uniquely identifying the lock.
6360 At the next line, a slave lock called @code{build_lock} is created. It is
6361 identified by the @code{"slave_builds"} string. Since the requirements of the
6362 lock are a bit more complicated, two optional arguments are also specified. The
6363 @code{maxCount} parameter sets the default limit for builds in counting mode to
6364 @code{1}. For the slave called @code{'fast'} however, we want to have at most
6365 three builds, and for the slave called @code{'new'} the upper limit is two
6366 builds running at the same time.
6368 The next step is using the locks in builds.  Buildbot allows a lock to be used
6369 during an entire build (from beginning to end), or only during a single build
6370 step. In the latter case, the lock is claimed for use just before the step
6371 starts, and released again when the step ends. To prevent
6372 deadlocks,@footnote{Deadlock is the situation where two or more slaves each
6373 hold a lock in exclusive mode, and in addition want to claim the lock held by
6374 the other slave exclusively as well. Since locks allow at most one exclusive
6375 user, both slaves will wait forever.} it is not possible to claim or release
6376 locks at other times.
6378 To use locks, you should add them with a @code{locks} argument.
6379 Each use of a lock is either in counting mode (that is, possibly shared with
6380 other builds) or in exclusive mode. A build or build step proceeds only when it
6381 has acquired all locks. If a build or step needs a lot of locks, it may be
6382 starved@footnote{Starving is the situation that only a few locks are available,
6383 and they are immediately grabbed by another build. As a result, it may take a
6384 long time before all locks needed by the starved build are free at the same
6385 time.} by other builds that need fewer locks.
6387 To illustrate use of locks, a few examples.
6389 @example
6390 from buildbot import locks
6391 from buildbot.steps import source, shell
6392 from buildbot.process import factory
6394 db_lock = locks.MasterLock("database")
6395 build_lock = locks.SlaveLock("slave_builds",
6396                              maxCount = 1,
6397                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6399 f = factory.BuildFactory()
6400 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
6401 f.addStep(shell.ShellCommand(command="make all"))
6402 f.addStep(shell.ShellCommand(command="make test",
6403                              locks=[db_lock.access('exclusive')]))
6405 b1 = @{'name': 'full1', 'slavename': 'fast',  'builddir': 'f1', 'factory': f,
6406        'locks': [build_lock.access('counting')] @}
6408 b2 = @{'name': 'full2', 'slavename': 'new',   'builddir': 'f2', 'factory': f.
6409        'locks': [build_lock.access('counting')] @}
6411 b3 = @{'name': 'full3', 'slavename': 'old',   'builddir': 'f3', 'factory': f.
6412        'locks': [build_lock.access('counting')] @}
6414 b4 = @{'name': 'full4', 'slavename': 'other', 'builddir': 'f4', 'factory': f.
6415        'locks': [build_lock.access('counting')] @}
6417 c['builders'] = [b1, b2, b3, b4]
6418 @end example
6420 Here we have four slaves @code{b1}, @code{b2}, @code{b3}, and @code{b4}. Each
6421 slave performs the same checkout, make, and test build step sequence.
6422 We want to enforce that at most one test step is executed between all slaves due
6423 to restrictions with the data base server. This is done by adding the
6424 @code{locks=} parameter with the third step. It takes a list of locks with their
6425 access mode. In this case only the @code{db_lock} is needed. The exclusive
6426 access mode is used to ensure there is at most one slave that executes the test
6427 step.
6429 In addition to exclusive accessing the data base, we also want slaves to stay
6430 responsive even under the load of a large number of builds being triggered.
6431 For this purpose, the slave lock called @code{build_lock} is defined. Since
6432 the restraint holds for entire builds, the lock is specified in the builder
6433 with @code{'locks': [build_lock.access('counting')]}.
6434 @node Build Factories,  , Interlocks, Build Process
6435 @section Build Factories
6438 Each Builder is equipped with a ``build factory'', which is
6439 responsible for producing the actual @code{Build} objects that perform
6440 each build. This factory is created in the configuration file, and
6441 attached to a Builder through the @code{factory} element of its
6442 dictionary.
6444 The standard @code{BuildFactory} object creates @code{Build} objects
6445 by default. These Builds will each execute a collection of BuildSteps
6446 in a fixed sequence. Each step can affect the results of the build,
6447 but in general there is little intelligence to tie the different steps
6448 together. You can create subclasses of @code{Build} to implement more
6449 sophisticated build processes, and then use a subclass of
6450 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
6451 create instances of your new Build subclass.
6454 @menu
6455 * BuildStep Objects::
6456 * BuildFactory::
6457 * Process-Specific build factories::
6458 @end menu
6460 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
6461 @subsection BuildStep Objects
6463 The steps used by these builds are all subclasses of @code{BuildStep}.
6464 The standard ones provided with Buildbot are documented later,
6465 @xref{Build Steps}. You can also write your own subclasses to use in
6466 builds.
6468 The basic behavior for a @code{BuildStep} is to:
6470 @itemize @bullet
6471 @item
6472 run for a while, then stop
6473 @item
6474 possibly invoke some RemoteCommands on the attached build slave
6475 @item
6476 possibly produce a set of log files
6477 @item
6478 finish with a status described by one of four values defined in
6479 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
6480 @item
6481 provide a list of short strings to describe the step
6482 @item
6483 define a color (generally green, orange, or red) with which the
6484 step should be displayed
6485 @end itemize
6488 More sophisticated steps may produce additional information and
6489 provide it to later build steps, or store it in the factory to provide
6490 to later builds.
6493 @menu
6494 * BuildFactory Attributes::
6495 * Quick builds::
6496 @end menu
6498 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
6499 @subsection BuildFactory
6501 @bfindex buildbot.process.factory.BuildFactory
6502 @bfindex buildbot.process.factory.BasicBuildFactory
6503 @c TODO: what is BasicSVN anyway?
6504 @bfindex buildbot.process.factory.BasicSVN
6506 The default @code{BuildFactory}, provided in the
6507 @code{buildbot.process.factory} module, contains an internal list of
6508 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
6509 tuples for each. These specification tuples are constructed when the
6510 config file is read, by asking the instances passed to @code{addStep}
6511 for their subclass and arguments.
6513 When asked to create a Build, the @code{BuildFactory} puts a copy of
6514 the list of step specifications into the new Build object. When the
6515 Build is actually started, these step specifications are used to
6516 create the actual set of BuildSteps, which are then executed one at a
6517 time. This serves to give each Build an independent copy of each step.
6518 For example, a build which consists of a CVS checkout followed by a
6519 @code{make build} would be constructed as follows:
6521 @example
6522 from buildbot.steps import source, shell
6523 from buildbot.process import factory
6525 f = factory.BuildFactory()
6526 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
6527 f.addStep(shell.Compile(command=["make", "build"]))
6528 @end example
6530 (To support config files from buildbot-0.7.5 and earlier,
6531 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
6532 command=["make","build"])} form, although its use is discouraged
6533 because then the @code{Compile} step doesn't get to validate or
6534 complain about its arguments until build time. The modern
6535 pass-by-instance approach allows this validation to occur while the
6536 config file is being loaded, where the admin has a better chance of
6537 noticing problems).
6539 It is also possible to pass a list of steps into the
6540 @code{BuildFactory} when it is created. Using @code{addStep} is
6541 usually simpler, but there are cases where is is more convenient to
6542 create the list of steps ahead of time.:
6544 @example
6545 from buildbot.steps import source, shell
6546 from buildbot.process import factory
6548 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
6549              shell.Compile(command=["make", "build"]),
6550             ]
6551 f = factory.BuildFactory(all_steps)
6552 @end example
6555 Each step can affect the build process in the following ways:
6557 @itemize @bullet
6558 @item
6559 If the step's @code{haltOnFailure} attribute is True, then a failure
6560 in the step (i.e. if it completes with a result of FAILURE) will cause
6561 the whole build to be terminated immediately: no further steps will be
6562 executed, with the exception of steps with @code{alwaysRun} set to
6563 True. @code{haltOnFailure} is useful for setup steps upon which the
6564 rest of the build depends: if the CVS checkout or @code{./configure}
6565 process fails, there is no point in trying to compile or test the
6566 resulting tree.
6568 @item
6569 If the step's @code{alwaysRun} attribute is True, then it will always
6570 be run, regardless of if previous steps have failed. This is useful
6571 for cleanup steps that should always be run to return the build
6572 directory or build slave into a good state.
6574 @item
6575 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
6576 then a result of FAILURE or WARNINGS will mark the build as a whole as
6577 FAILED. However, the remaining steps will still be executed. This is
6578 appropriate for things like multiple testing steps: a failure in any
6579 one of them will indicate that the build has failed, however it is
6580 still useful to run them all to completion.
6582 @item
6583 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
6584 is set, then a result of FAILURE or WARNINGS will mark the build as
6585 having WARNINGS, and the remaining steps will still be executed. This
6586 may be appropriate for certain kinds of optional build or test steps.
6587 For example, a failure experienced while building documentation files
6588 should be made visible with a WARNINGS result but not be serious
6589 enough to warrant marking the whole build with a FAILURE.
6591 @end itemize
6593 In addition, each Step produces its own results, may create logfiles,
6594 etc. However only the flags described above have any effect on the
6595 build as a whole.
6597 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
6598 reasonably appropriate flags set on them already. For example, without
6599 a source tree there is no point in continuing the build, so the
6600 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
6601 in @file{buildbot/steps/*.py} to see how the other Steps are
6602 marked.
6604 Each Step is created with an additional @code{workdir} argument that
6605 indicates where its actions should take place. This is specified as a
6606 subdirectory of the slave builder's base directory, with a default
6607 value of @code{build}. This is only implemented as a step argument (as
6608 opposed to simply being a part of the base directory) because the
6609 CVS/SVN steps need to perform their checkouts from the parent
6610 directory.
6612 @menu
6613 * BuildFactory Attributes::
6614 * Quick builds::
6615 @end menu
6617 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
6618 @subsubsection BuildFactory Attributes
6620 Some attributes from the BuildFactory are copied into each Build.
6622 @cindex treeStableTimer
6624 @table @code
6625 @item useProgress
6626 (defaults to True): if True, the buildmaster keeps track of how long
6627 each step takes, so it can provide estimates of how long future builds
6628 will take. If builds are not expected to take a consistent amount of
6629 time (such as incremental builds in which a random set of files are
6630 recompiled or tested each time), this should be set to False to
6631 inhibit progress-tracking.
6633 @end table
6636 @node Quick builds,  , BuildFactory Attributes, BuildFactory
6637 @subsubsection Quick builds
6639 @bfindex buildbot.process.factory.QuickBuildFactory
6641 The difference between a ``full build'' and a ``quick build'' is that
6642 quick builds are generally done incrementally, starting with the tree
6643 where the previous build was performed. That simply means that the
6644 source-checkout step should be given a @code{mode='update'} flag, to
6645 do the source update in-place.
6647 In addition to that, the @code{useProgress} flag should be set to
6648 False. Incremental builds will (or at least the ought to) compile as
6649 few files as necessary, so they will take an unpredictable amount of
6650 time to run. Therefore it would be misleading to claim to predict how
6651 long the build will take.
6654 @node Process-Specific build factories,  , BuildFactory, Build Factories
6655 @subsection Process-Specific build factories
6657 Many projects use one of a few popular build frameworks to simplify
6658 the creation and maintenance of Makefiles or other compilation
6659 structures. Buildbot provides several pre-configured BuildFactory
6660 subclasses which let you build these projects with a minimum of fuss.
6662 @menu
6663 * GNUAutoconf::
6664 * CPAN::
6665 * Python distutils::
6666 * Python/Twisted/trial projects::
6667 @end menu
6669 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
6670 @subsubsection GNUAutoconf
6672 @bfindex buildbot.process.factory.GNUAutoconf
6674 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
6675 software portability tool, intended to make it possible to write
6676 programs in C (and other languages) which will run on a variety of
6677 UNIX-like systems. Most GNU software is built using autoconf. It is
6678 frequently used in combination with GNU automake. These tools both
6679 encourage a build process which usually looks like this:
6681 @example
6682 % CONFIG_ENV=foo ./configure --with-flags
6683 % make all
6684 % make check
6685 # make install
6686 @end example
6688 (except of course the Buildbot always skips the @code{make install}
6689 part).
6691 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
6692 designed to build projects which use GNU autoconf and/or automake. The
6693 configuration environment variables, the configure flags, and command
6694 lines used for the compile and test are all configurable, in general
6695 the default values will be suitable.
6697 Example:
6699 @example
6700 # use the s() convenience function defined earlier
6701 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
6702                         flags=["--disable-nls"])
6703 @end example
6705 Required Arguments:
6707 @table @code
6708 @item source
6709 This argument must be a step specification tuple that provides a
6710 BuildStep to generate the source tree.
6711 @end table
6713 Optional Arguments:
6715 @table @code
6716 @item configure
6717 The command used to configure the tree. Defaults to
6718 @code{./configure}. Accepts either a string or a list of shell argv
6719 elements.
6721 @item configureEnv
6722 The environment used for the initial configuration step. This accepts
6723 a dictionary which will be merged into the buildslave's normal
6724 environment. This is commonly used to provide things like
6725 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
6726 Defaults to an empty dictionary.
6728 @item configureFlags
6729 A list of flags to be appended to the argument list of the configure
6730 command. This is commonly used to enable or disable specific features
6731 of the autoconf-controlled package, like @code{["--without-x"]} to
6732 disable windowing support. Defaults to an empty list.
6734 @item compile
6735 this is a shell command or list of argv values which is used to
6736 actually compile the tree. It defaults to @code{make all}. If set to
6737 None, the compile step is skipped.
6739 @item test
6740 this is a shell command or list of argv values which is used to run
6741 the tree's self-tests. It defaults to @code{make check}. If set to
6742 None, the test step is skipped.
6744 @end table
6747 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
6748 @subsubsection CPAN
6750 @bfindex buildbot.process.factory.CPAN
6752 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
6753 archive use the @code{MakeMaker} module to provide configuration,
6754 build, and test services. The standard build routine for these modules
6755 looks like:
6757 @example
6758 % perl Makefile.PL
6759 % make
6760 % make test
6761 # make install
6762 @end example
6764 (except again Buildbot skips the install step)
6766 Buildbot provides a @code{CPAN} factory to compile and test these
6767 projects.
6770 Arguments:
6771 @table @code
6772 @item source
6773 (required): A step specification tuple, that that used by GNUAutoconf.
6775 @item perl
6776 A string which specifies the @code{perl} executable to use. Defaults
6777 to just @code{perl}.
6779 @end table
6782 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
6783 @subsubsection Python distutils
6785 @bfindex buildbot.process.factory.Distutils
6787 Most Python modules use the @code{distutils} package to provide
6788 configuration and build services. The standard build process looks
6789 like:
6791 @example
6792 % python ./setup.py build
6793 % python ./setup.py install
6794 @end example
6796 Unfortunately, although Python provides a standard unit-test framework
6797 named @code{unittest}, to the best of my knowledge @code{distutils}
6798 does not provide a standardized target to run such unit tests. (please
6799 let me know if I'm wrong, and I will update this factory).
6801 The @code{Distutils} factory provides support for running the build
6802 part of this process. It accepts the same @code{source=} parameter as
6803 the other build factories.
6806 Arguments:
6807 @table @code
6808 @item source
6809 (required): A step specification tuple, that that used by GNUAutoconf.
6811 @item python
6812 A string which specifies the @code{python} executable to use. Defaults
6813 to just @code{python}.
6815 @item test
6816 Provides a shell command which runs unit tests. This accepts either a
6817 string or a list. The default value is None, which disables the test
6818 step (since there is no common default command to run unit tests in
6819 distutils modules).
6821 @end table
6824 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
6825 @subsubsection Python/Twisted/trial projects
6827 @bfindex buildbot.process.factory.Trial
6828 @c TODO: document these steps better
6829 @bsindex buildbot.steps.python_twisted.HLint
6830 @bsindex buildbot.steps.python_twisted.Trial
6831 @bsindex buildbot.steps.python_twisted.ProcessDocs
6832 @bsindex buildbot.steps.python_twisted.BuildDebs
6833 @bsindex buildbot.steps.python_twisted.RemovePYCs
6835 Twisted provides a unit test tool named @code{trial} which provides a
6836 few improvements over Python's built-in @code{unittest} module. Many
6837 python projects which use Twisted for their networking or application
6838 services also use trial for their unit tests. These modules are
6839 usually built and tested with something like the following:
6841 @example
6842 % python ./setup.py build
6843 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
6844 % python ./setup.py install
6845 @end example
6847 Unfortunately, the @file{build/lib} directory into which the
6848 built/copied .py files are placed is actually architecture-dependent,
6849 and I do not yet know of a simple way to calculate its value. For many
6850 projects it is sufficient to import their libraries ``in place'' from
6851 the tree's base directory (@code{PYTHONPATH=.}).
6853 In addition, the @var{PROJECTNAME} value where the test files are
6854 located is project-dependent: it is usually just the project's
6855 top-level library directory, as common practice suggests the unit test
6856 files are put in the @code{test} sub-module. This value cannot be
6857 guessed, the @code{Trial} class must be told where to find the test
6858 files.
6860 The @code{Trial} class provides support for building and testing
6861 projects which use distutils and trial. If the test module name is
6862 specified, trial will be invoked. The library path used for testing
6863 can also be set.
6865 One advantage of trial is that the Buildbot happens to know how to
6866 parse trial output, letting it identify which tests passed and which
6867 ones failed. The Buildbot can then provide fine-grained reports about
6868 how many tests have failed, when individual tests fail when they had
6869 been passing previously, etc.
6871 Another feature of trial is that you can give it a series of source
6872 .py files, and it will search them for special @code{test-case-name}
6873 tags that indicate which test cases provide coverage for that file.
6874 Trial can then run just the appropriate tests. This is useful for
6875 quick builds, where you want to only run the test cases that cover the
6876 changed functionality.
6878 Arguments:
6879 @table @code
6880 @item source
6881 (required): A step specification tuple, like that used by GNUAutoconf.
6883 @item buildpython
6884 A list (argv array) of strings which specifies the @code{python}
6885 executable to use when building the package. Defaults to just
6886 @code{['python']}. It may be useful to add flags here, to supress
6887 warnings during compilation of extension modules. This list is
6888 extended with @code{['./setup.py', 'build']} and then executed in a
6889 ShellCommand.
6891 @item testpath
6892 Provides a directory to add to @code{PYTHONPATH} when running the unit
6893 tests, if tests are being run. Defaults to @code{.} to include the
6894 project files in-place. The generated build library is frequently
6895 architecture-dependent, but may simply be @file{build/lib} for
6896 pure-python modules.
6898 @item trialpython
6899 Another list of strings used to build the command that actually runs
6900 trial. This is prepended to the contents of the @code{trial} argument
6901 below. It may be useful to add @code{-W} flags here to supress
6902 warnings that occur while tests are being run. Defaults to an empty
6903 list, meaning @code{trial} will be run without an explicit
6904 interpreter, which is generally what you want if you're using
6905 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
6906 lives in the Twisted source tree.
6908 @item trial
6909 provides the name of the @code{trial} command. It is occasionally
6910 useful to use an alternate executable, such as @code{trial2.2} which
6911 might run the tests under an older version of Python. Defaults to
6912 @code{trial}.
6914 @item tests
6915 Provides a module name or names which contain the unit tests for this
6916 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
6917 list of strings. Defaults to None, indicating that no tests should be
6918 run. You must either set this or @code{useTestCaseNames} to do anyting
6919 useful with the Trial factory.
6921 @item useTestCaseNames
6922 Tells the Step to provide the names of all changed .py files to trial,
6923 so it can look for test-case-name tags and run just the matching test
6924 cases. Suitable for use in quick builds. Defaults to False.
6926 @item randomly
6927 If @code{True}, tells Trial (with the @code{--random=0} argument) to
6928 run the test cases in random order, which sometimes catches subtle
6929 inter-test dependency bugs. Defaults to @code{False}.
6931 @item recurse
6932 If @code{True}, tells Trial (with the @code{--recurse} argument) to
6933 look in all subdirectories for additional test cases. It isn't clear
6934 to me how this works, but it may be useful to deal with the
6935 unknown-PROJECTNAME problem described above, and is currently used in
6936 the Twisted buildbot to accomodate the fact that test cases are now
6937 distributed through multiple twisted.SUBPROJECT.test directories.
6939 @end table
6941 Unless one of @code{trialModule} or @code{useTestCaseNames}
6942 are set, no tests will be run.
6944 Some quick examples follow. Most of these examples assume that the
6945 target python code (the ``code under test'') can be reached directly
6946 from the root of the target tree, rather than being in a @file{lib/}
6947 subdirectory.
6949 @example
6950 #  Trial(source, tests="toplevel.test") does:
6951 #   python ./setup.py build
6952 #   PYTHONPATH=. trial -to toplevel.test
6954 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
6955 #   python ./setup.py build
6956 #   PYTHONPATH=. trial -to toplevel.test other.test
6958 #  Trial(source, useTestCaseNames=True) does:
6959 #   python ./setup.py build
6960 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
6962 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
6963 #   python2.3 -Wall ./setup.py build
6964 #   PYTHONPATH=. trial -to foo.tests
6966 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
6967 #        tests="foo.tests") does:
6968 #   python2.3 -Wall ./setup.py build
6969 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
6971 # For running trial out of the tree being tested (only useful when the
6972 # tree being built is Twisted itself):
6973 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
6974 #        tests="foo.tests") does:
6975 #   python2.3 -Wall ./setup.py build
6976 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
6977 @end example
6979 If the output directory of @code{./setup.py build} is known, you can
6980 pull the python code from the built location instead of the source
6981 directories. This should be able to handle variations in where the
6982 source comes from, as well as accomodating binary extension modules:
6984 @example
6985 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
6986 # does:
6987 #  python ./setup.py build
6988 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
6989 @end example
6992 @node Status Delivery, Command-line tool, Build Process, Top
6993 @chapter Status Delivery
6995 More details are available in the docstrings for each class, use a
6996 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
6997 Most status delivery objects take a @code{categories=} argument, which
6998 can contain a list of ``category'' names: in this case, it will only
6999 show status for Builders that are in one of the named categories.
7001 (implementor's note: each of these objects should be a
7002 service.MultiService which will be attached to the BuildMaster object
7003 when the configuration is processed. They should use
7004 @code{self.parent.getStatus()} to get access to the top-level IStatus
7005 object, either inside @code{startService} or later. They may call
7006 @code{status.subscribe()} in @code{startService} to receive
7007 notifications of builder events, in which case they must define
7008 @code{builderAdded} and related methods. See the docstrings in
7009 @file{buildbot/interfaces.py} for full details.)
7011 @menu
7012 * WebStatus::
7013 * MailNotifier::
7014 * IRC Bot::
7015 * PBListener::
7016 * Writing New Status Plugins::
7017 @end menu
7019 @c @node Email Delivery,  , Status Delivery, Status Delivery
7020 @c @subsection Email Delivery
7022 @c DOCUMENT THIS
7025 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
7026 @section WebStatus
7028 @cindex WebStatus
7029 @stindex buildbot.status.web.baseweb.WebStatus
7031 The @code{buildbot.status.html.WebStatus} status target runs a small
7032 web server inside the buildmaster. You can point a browser at this web
7033 server and retrieve information about every build the buildbot knows
7034 about, as well as find out what the buildbot is currently working on.
7036 The first page you will see is the ``Welcome Page'', which contains
7037 links to all the other useful pages. This page is simply served from
7038 the @file{public_html/index.html} file in the buildmaster's base
7039 directory, where it is created by the @command{buildbot create-master}
7040 command along with the rest of the buildmaster.
7042 The most complex resource provided by @code{WebStatus} is the
7043 ``Waterfall Display'', which shows a time-based chart of events. This
7044 somewhat-busy display provides detailed information about all steps of
7045 all recent builds, and provides hyperlinks to look at individual build
7046 logs and source changes. By simply reloading this page on a regular
7047 basis, you will see a complete description of everything the buildbot
7048 is currently working on.
7050 There are also pages with more specialized information. For example,
7051 there is a page which shows the last 20 builds performed by the
7052 buildbot, one line each. Each line is a link to detailed information
7053 about that build. By adding query arguments to the URL used to reach
7054 this page, you can narrow the display to builds that involved certain
7055 branches, or which ran on certain Builders. These pages are described
7056 in great detail below.
7059 When the buildmaster is created, a subdirectory named
7060 @file{public_html/} is created in its base directory. By default, @code{WebStatus}
7061 will serve files from this directory: for example, when a user points
7062 their browser at the buildbot's @code{WebStatus} URL, they will see
7063 the contents of the @file{public_html/index.html} file. Likewise,
7064 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
7065 @file{public_html/favicon.ico} are all useful things to have in there.
7066 The first time a buildmaster is created, the @file{public_html}
7067 directory is populated with some sample files, which you will probably
7068 want to customize for your own project. These files are all static:
7069 the buildbot does not modify them in any way as it serves them to HTTP
7070 clients.
7072 @example
7073 from buildbot.status.html import WebStatus
7074 c['status'].append(WebStatus(8080))
7075 @end example
7077 Note that the initial robots.txt file has Disallow lines for all of
7078 the dynamically-generated buildbot pages, to discourage web spiders
7079 and search engines from consuming a lot of CPU time as they crawl
7080 through the entire history of your buildbot. If you are running the
7081 buildbot behind a reverse proxy, you'll probably need to put the
7082 robots.txt file somewhere else (at the top level of the parent web
7083 server), and replace the URL prefixes in it with more suitable values.
7085 If you would like to use an alternative root directory, add the
7086 @code{public_html=..} option to the @code{WebStatus} creation:
7088 @example
7089 c['status'].append(WebStatus(8080, public_html="/var/www/buildbot"))
7090 @end example
7092 In addition, if you are familiar with twisted.web @emph{Resource
7093 Trees}, you can write code to add additional pages at places inside
7094 this web space. Just use @code{webstatus.putChild} to place these
7095 resources.
7097 The following section describes the special URLs and the status views
7098 they provide.
7101 @menu
7102 * WebStatus Configuration Parameters::
7103 * Buildbot Web Resources::
7104 * XMLRPC server::
7105 * HTML Waterfall::
7106 @end menu
7108 @node WebStatus Configuration Parameters, Buildbot Web Resources, WebStatus, WebStatus
7109 @subsection WebStatus Configuration Parameters
7111 The most common way to run a @code{WebStatus} is on a regular TCP
7112 port. To do this, just pass in the TCP port number when you create the
7113 @code{WebStatus} instance; this is called the @code{http_port} argument:
7115 @example
7116 from buildbot.status.html import WebStatus
7117 c['status'].append(WebStatus(8080))
7118 @end example
7120 The @code{http_port} argument is actually a ``strports specification''
7121 for the port that the web server should listen on. This can be a
7122 simple port number, or a string like
7123 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
7124 loopback interface, and therefore to clients running on the same
7125 host)@footnote{It may even be possible to provide SSL access by using
7126 a specification like
7127 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
7128 completely untested}.
7130 If instead (or in addition) you provide the @code{distrib_port}
7131 argument, a twisted.web distributed server will be started either on a
7132 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
7133 likely on a UNIX socket (if @code{distrib_port} is like
7134 @code{"unix:/path/to/socket"}).
7136 The @code{distrib_port} option means that, on a host with a
7137 suitably-configured twisted-web server, you do not need to consume a
7138 separate TCP port for the buildmaster's status web page. When the web
7139 server is constructed with @code{mktap web --user}, URLs that point to
7140 @code{http://host/~username/} are dispatched to a sub-server that is
7141 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
7142 such a system, it is convenient to create a dedicated @code{buildbot}
7143 user, then set @code{distrib_port} to
7144 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
7145 configuration will make the HTML status page available at
7146 @code{http://host/~buildbot/} . Suitable URL remapping can make it
7147 appear at @code{http://host/buildbot/}, and the right virtual host
7148 setup can even place it at @code{http://buildbot.host/} .
7150 The other @code{WebStatus} argument is @code{allowForce}. If set to
7151 True, then the web page will provide a ``Force Build'' button that
7152 allows visitors to manually trigger builds. This is useful for
7153 developers to re-run builds that have failed because of intermittent
7154 problems in the test suite, or because of libraries that were not
7155 installed at the time of the previous build. You may not wish to allow
7156 strangers to cause a build to run: in that case, set this to False to
7157 remove these buttons. The default value is False.
7161 @node Buildbot Web Resources, XMLRPC server, WebStatus Configuration Parameters, WebStatus
7162 @subsection Buildbot Web Resources
7164 Certain URLs are ``magic'', and the pages they serve are created by
7165 code in various classes in the @file{buildbot.status.web} package
7166 instead of being read from disk. The most common way to access these
7167 pages is for the buildmaster admin to write or modify the
7168 @file{index.html} page to contain links to them. Of course other
7169 project web pages can contain links to these buildbot pages as well.
7171 Many pages can be modified by adding query arguments to the URL. For
7172 example, a page which shows the results of the most recent build
7173 normally does this for all builders at once. But by appending
7174 ``?builder=i386'' to the end of the URL, the page will show only the
7175 results for the ``i386'' builder. When used in this way, you can add
7176 multiple ``builder='' arguments to see multiple builders. Remembering
7177 that URL query arguments are separated @emph{from each other} with
7178 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
7179 show builds for just those two Builders.
7181 The @code{branch=} query argument can be used on some pages. This
7182 filters the information displayed by that page down to only the builds
7183 or changes which involved the given branch. Use @code{branch=trunk} to
7184 reference the trunk: if you aren't intentionally using branches,
7185 you're probably using trunk. Multiple @code{branch=} arguments can be
7186 used to examine multiple branches at once (so appending
7187 @code{?branch=foo&branch=bar} to the URL will show builds involving
7188 either branch). No @code{branch=} arguments means to show builds and
7189 changes for all branches.
7191 Some pages may include the Builder name or the build number in the
7192 main part of the URL itself. For example, a page that describes Build
7193 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
7195 The table below lists all of the internal pages and the URLs that can
7196 be used to access them.
7198 NOTE: of the pages described here, @code{/slave_status_timeline} and
7199 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
7200 has only a few methods so far. Future releases will improve this.
7202 @table @code
7204 @item /waterfall
7206 This provides a chronologically-oriented display of the activity of
7207 all builders. It is the same display used by the Waterfall display.
7209 By adding one or more ``builder='' query arguments, the Waterfall is
7210 restricted to only showing information about the given Builders. By
7211 adding one or more ``branch='' query arguments, the display is
7212 restricted to showing information about the given branches. In
7213 addition, adding one or more ``category='' query arguments to the URL
7214 will limit the display to Builders that were defined with one of the
7215 given categories.
7217 A 'show_events=true' query argument causes the display to include
7218 non-Build events, like slaves attaching and detaching, as well as
7219 reconfiguration events. 'show_events=false' hides these events. The
7220 default is to show them.
7222 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
7223 arguments will control what interval of time is displayed. The default
7224 is to show the latest events, but these can be used to look at earlier
7225 periods in history. The @code{num_events=} argument also provides a
7226 limit on the size of the displayed page.
7228 The Waterfall has references to resources many of the other portions
7229 of the URL space: @file{/builders} for access to individual builds,
7230 @file{/changes} for access to information about source code changes,
7231 etc.
7233 @item /builders/$BUILDERNAME
7235 This describes the given Builder, and provides buttons to force a build.
7237 @item /builders/$BUILDERNAME/builds/$BUILDNUM
7239 This describes a specific Build.
7241 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
7243 This describes a specific BuildStep.
7245 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
7247 This provides an HTML representation of a specific logfile.
7249 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
7251 This returns the logfile as plain text, without any HTML coloring
7252 markup. It also removes the ``headers'', which are the lines that
7253 describe what command was run and what the environment variable
7254 settings were like. This maybe be useful for saving to disk and
7255 feeding to tools like 'grep'.
7257 @item /changes
7259 This provides a brief description of the ChangeSource in use
7260 (@pxref{Change Sources}).
7262 @item /changes/NN
7264 This shows detailed information about the numbered Change: who was the
7265 author, what files were changed, what revision number was represented,
7266 etc.
7268 @item /buildslaves
7270 This summarizes each BuildSlave, including which Builders are
7271 configured to use it, whether the buildslave is currently connected or
7272 not, and host information retrieved from the buildslave itself.
7274 @item /one_line_per_build
7276 This page shows one line of text for each build, merging information
7277 from all Builders@footnote{Apparently this is the same way
7278 http://buildd.debian.org displays build status}. Each line specifies
7279 the name of the Builder, the number of the Build, what revision it
7280 used, and a summary of the results. Successful builds are in green,
7281 while failing builds are in red. The date and time of the build are
7282 added to the right-hand edge of the line. The lines are ordered by
7283 build finish timestamp.
7285 One or more @code{builder=} or @code{branch=} arguments can be used to
7286 restrict the list. In addition, a @code{numbuilds=} argument will
7287 control how many lines are displayed (20 by default).
7289 @item /one_box_per_builder
7291 This page shows a small table, with one box for each Builder,
7292 containing the results of the most recent Build. It does not show the
7293 individual steps, or the current status. This is a simple summary of
7294 buildbot status: if this page is green, then all tests are passing.
7296 As with @code{/one_line_per_build}, this page will also honor
7297 @code{builder=} and @code{branch=} arguments.
7299 @item /about
7301 This page gives a brief summary of the Buildbot itself: software
7302 version, versions of some libraries that the Buildbot depends upon,
7303 etc. It also contains a link to the buildbot.net home page.
7305 @item /slave_status_timeline
7307 (note: this page has not yet been implemented)
7309 This provides a chronological display of configuration and operational
7310 events: master startup/shutdown, slave connect/disconnect, and
7311 config-file changes. When a config-file reload is abandoned because of
7312 an error in the config file, the error is displayed on this page.
7314 This page does not show any builds.
7316 @item /last_build/$BUILDERNAME/status.png
7318 This returns a PNG image that describes the results of the most recent
7319 build, which can be referenced in an IMG tag by other pages, perhaps
7320 from a completely different site. Use it as you would a webcounter.
7322 @end table
7324 There are also a set of web-status resources that are intended for use
7325 by other programs, rather than humans.
7327 @table @code
7329 @item /xmlrpc
7331 This runs an XML-RPC server which can be used to query status
7332 information about various builds. See @ref{XMLRPC server} for more
7333 details.
7335 @end table
7337 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
7338 @subsection XMLRPC server
7340 When using WebStatus, the buildbot runs an XML-RPC server at
7341 @file{/xmlrpc} that can be used by other programs to query build
7342 status. The following table lists the methods that can be invoked
7343 using this interface.
7345 @table @code
7346 @item getAllBuildsInInterval(start, stop)
7348 Return a list of builds that have completed after the 'start'
7349 timestamp and before the 'stop' timestamp. This looks at all Builders.
7351 The timestamps are integers, interpreted as standard unix timestamps
7352 (seconds since epoch).
7354 Each Build is returned as a tuple in the form: @code{(buildername,
7355 buildnumber, build_end, branchname, revision, results, text)}
7357 The buildnumber is an integer. 'build_end' is an integer (seconds
7358 since epoch) specifying when the build finished.
7360 The branchname is a string, which may be an empty string to indicate
7361 None (i.e. the default branch). The revision is a string whose meaning
7362 is specific to the VC system in use, and comes from the 'got_revision'
7363 build property. The results are expressed as a string, one of
7364 ('success', 'warnings', 'failure', 'exception'). The text is a list of
7365 short strings that ought to be joined by spaces and include slightly
7366 more data about the results of the build.
7368 @item getBuild(builder_name, build_number)
7370 Return information about a specific build.
7372 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
7373 complete information about the build. It does not include the contents
7374 of the log files, but it has just about everything else.
7376 @end table
7378 @node HTML Waterfall,  , XMLRPC server, WebStatus
7379 @subsection HTML Waterfall
7381 @cindex Waterfall
7382 @stindex buildbot.status.html.Waterfall
7384 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
7385 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
7386 This section (and the @code{Waterfall} class itself) will be removed
7387 from a future release.
7389 @example
7390 from buildbot.status import html
7391 w = html.WebStatus(http_port=8080)
7392 c['status'].append(w)
7393 @end example
7397 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
7398 @section MailNotifier
7400 @cindex email
7401 @cindex mail
7402 @stindex buildbot.status.mail.MailNotifier
7404 The buildbot can also send email when builds finish. The most common
7405 use of this is to tell developers when their change has caused the
7406 build to fail. It is also quite common to send a message to a mailing
7407 list (usually named ``builds'' or similar) about every build.
7409 The @code{MailNotifier} status target is used to accomplish this. You
7410 configure it by specifying who mail should be sent to, under what
7411 circumstances mail should be sent, and how to deliver the mail. It can
7412 be configured to only send out mail for certain builders, and only
7413 send messages when the build fails, or when the builder transitions
7414 from success to failure. It can also be configured to include various
7415 build logs in each message.
7418 By default, the message will be sent to the Interested Users list
7419 (@pxref{Doing Things With Users}), which includes all developers who
7420 made changes in the build. You can add additional recipients with the
7421 extraRecipients argument.
7423 Each MailNotifier sends mail to a single set of recipients. To send
7424 different kinds of mail to different recipients, use multiple
7425 MailNotifiers.
7427 The following simple example will send an email upon the completion of
7428 each build, to just those developers whose Changes were included in
7429 the build. The email contains a description of the Build, its results,
7430 and URLs where more information can be obtained.
7432 @example
7433 from buildbot.status.mail import MailNotifier
7434 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
7435 c['status'].append(mn)
7436 @end example
7438 To get a simple one-message-per-build (say, for a mailing list), use
7439 the following form instead. This form does not send mail to individual
7440 developers (and thus does not need the @code{lookup=} argument,
7441 explained below), instead it only ever sends mail to the ``extra
7442 recipients'' named in the arguments:
7444 @example
7445 mn = MailNotifier(fromaddr="buildbot@@example.org",
7446                   sendToInterestedUsers=False,
7447                   extraRecipients=['listaddr@@example.org'])
7448 @end example
7450 In some cases it is desirable to have different information then what
7451 is provided in a standard MailNotifier message. For this purpose 
7452 MailNotifier provides the argument customMesg (a function) which allows 
7453 for the creation of messages with unique content.
7455 For example it can be useful to display the last few lines of a log file 
7456 and recent changes when a builder fails:
7458 @example
7459 def message(attrs):
7460     logLines = 10
7461     text = list()
7462     text.append("STATUS: %s" % attrs['result'].title())
7463     text.append("")
7464     text.extend([c.asText() for c in attrs['changes']])
7465     text.append("")
7466     name, url, lines = attrs['logs'][-1]
7467     text.append("Last %d lines of '%s':" % (logLines, name))
7468     text.extend(["\t%s\n" % line for line in lines[len(lines)-logLines:]])
7469     text.append("")
7470     text.append("-buildbot")
7471     return ("\n".join(text), 'plain')
7473 mn = MailNotifier(fromaddr="buildbot@@example.org",
7474                   sendToInterestedUsers=False,
7475                   mode='problem',
7476                   extraRecipients=['listaddr@@example.org'],
7477                   customMesg=message)
7478 @end example
7480 A customMesg function takes a single dict argument (see below) and returns a 
7481 tuple of strings. The first string is the complete text of the message and the
7482 second is the message type ('plain' or 'html'). The 'html' type should be used
7483 when generating an HTML message: 
7485 @example
7486 def message(attrs):
7487     logLines = 10
7488     text = list()
7489     text.append('<h4>Build status %s.</h4>' % (attrs['result'].title()))
7490     if attrs['changes']:
7491         text.append('<h4>Recent Changes:</h4>')
7492         text.extend([c.asHTML() for c in attrs['changes']])
7493     name, url, lines = attrs['logs'][-1]
7494     text.append('<h4>Last %d lines of "%s":</h4>' % (logLines, name))
7495     text.append('<p>')
7496     text.append('<br>'.join([line for line in lines[len(lines)-logLines:]]))
7497     text.append('</p>')
7498     text.append('<br><br>')
7499     text.append('Full log at: %s' % url)
7500     text.append('<br><br>')
7501     text.append('<b>-buildbot</b>')
7502     return ('\n'.join(text), 'html')
7503 @end example 
7505 @heading MailNotifier arguments
7507 @table @code
7508 @item fromaddr
7509 The email address to be used in the 'From' header.
7511 @item sendToInterestedUsers
7512 (boolean). If True (the default), send mail to all of the Interested
7513 Users. If False, only send mail to the extraRecipients list.
7515 @item extraRecipients
7516 (tuple of strings). A list of email addresses to which messages should
7517 be sent (in addition to the InterestedUsers list, which includes any
7518 developers who made Changes that went into this build). It is a good
7519 idea to create a small mailing list and deliver to that, then let
7520 subscribers come and go as they please.
7522 @item subject
7523 (string). A string to be used as the subject line of the message.
7524 @code{%(builder)s} will be replaced with the name of the builder which
7525 provoked the message.
7527 @item mode
7528 (string). Default to 'all'. One of:
7529 @table @code
7530 @item all
7531 Send mail about all builds, bothpassing and failing
7532 @item failing
7533 Only send mail about builds which fail
7534 @item problem
7535 Only send mail about a build which failed when the previous build has passed.
7536 If your builds usually pass, then this will only send mail when a problem
7537 occurs.
7538 @end table
7540 @item builders
7541 (list of strings). A list of builder names for which mail should be
7542 sent. Defaults to None (send mail for all builds). Use either builders
7543 or categories, but not both.
7545 @item categories
7546 (list of strings). A list of category names to serve status
7547 information for. Defaults to None (all categories). Use either
7548 builders or categories, but not both.
7550 @item addLogs
7551 (boolean). If True, include all build logs as attachments to the
7552 messages. These can be quite large. This can also be set to a list of
7553 log names, to send a subset of the logs. Defaults to False.
7555 @item relayhost
7556 (string). The host to which the outbound SMTP connection should be
7557 made. Defaults to 'localhost'
7559 @item lookup
7560 (implementor of @code{IEmailLookup}). Object which provides
7561 IEmailLookup, which is responsible for mapping User names (which come
7562 from the VC system) into valid email addresses. If not provided, the
7563 notifier will only be able to send mail to the addresses in the
7564 extraRecipients list. Most of the time you can use a simple Domain
7565 instance. As a shortcut, you can pass as string: this will be treated
7566 as if you had provided Domain(str). For example,
7567 lookup='twistedmatrix.com' will allow mail to be sent to all
7568 developers whose SVN usernames match their twistedmatrix.com account
7569 names. See buildbot/status/mail.py for more details.
7571 @item customMesg
7572 This is a optional function that can be used to generate a custom mail 
7573 message. The customMesg function takes a single dict and must return a 
7574 tuple containing the message text and type ('html' or 'plain'). Below is a list 
7575 of availale keys in the dict passed to customMesg:
7577 @table @code
7578 @item builderName 
7579 (str) Name of the builder that generated this event.
7580 @item projectName 
7581 (str) Name of the project.
7582 @item mode 
7583 (str) Mode set in MailNotifier. (failing, passing, problem).
7584 @item result 
7585 (str) Builder result as a string. 'success', 'warnings', 'failure', 'skipped', or 'exception'
7586 @item buildURL 
7587 (str) URL to build page.
7588 @item buildbotURL 
7589 (str) URL to buildbot main page.
7590 @item buildText 
7591 (str) Build text from build.getText().
7592 @item slavename 
7593 (str) Slavename.
7594 @item reason 
7595 (str) Build reason from build.getReason().
7596 @item responsibleUsers 
7597 (List of str) List of responsible users.
7598 @item branch 
7599 (str) Name of branch used. If no SourceStamp exists branch
7600 is an empty string.
7601 @item revision 
7602 (str) Name of revision used. If no SourceStamp exists revision
7603 is an empty string.
7604 @item patch 
7605 (str) Name of patch used. If no SourceStamp exists patch
7606 is an empty string.
7607 @item changes
7608 (list of objs) List of change objects from SourceStamp. A change
7609 object has the following useful information:
7610 @table @code
7611 @item who
7612 (str) who made this change
7613 @item revision 
7614 (str) what VC revision is this change
7615 @item branch 
7616 (str) on what branch did this change occur
7617 @item when 
7618 (str) when did this change occur
7619 @item files 
7620 (list of str) what files were affected in this change
7621 @item comments 
7622 (str) comments reguarding the change.
7623 @end table
7624 The functions asText and asHTML return a list of strings with
7625 the above information formatted. 
7626 @item logs
7627 (List of Tuples) List of tuples where each tuple contains the log name, log url,
7628 and log contents as a list of strings.
7629 @end table
7630 @end table
7632 @node IRC Bot, PBListener, MailNotifier, Status Delivery
7633 @section IRC Bot
7635 @cindex IRC
7636 @stindex buildbot.status.words.IRC
7639 The @code{buildbot.status.words.IRC} status target creates an IRC bot
7640 which will attach to certain channels and be available for status
7641 queries. It can also be asked to announce builds as they occur, or be
7642 told to shut up.
7644 @example
7645 from buildbot.status import words
7646 irc = words.IRC("irc.example.org", "botnickname",
7647                 channels=["channel1", "channel2"],
7648                 password="mysecretpassword")
7649 c['status'].append(irc)
7650 @end example
7652 Take a look at the docstring for @code{words.IRC} for more details on
7653 configuring this service. The @code{password} argument, if provided,
7654 will be sent to Nickserv to claim the nickname: some IRC servers will
7655 not allow clients to send private messages until they have logged in
7656 with a password.
7658 To use the service, you address messages at the buildbot, either
7659 normally (@code{botnickname: status}) or with private messages
7660 (@code{/msg botnickname status}). The buildbot will respond in kind.
7662 Some of the commands currently available:
7664 @table @code
7666 @item list builders
7667 Emit a list of all configured builders
7668 @item status BUILDER
7669 Announce the status of a specific Builder: what it is doing right now.
7670 @item status all
7671 Announce the status of all Builders
7672 @item watch BUILDER
7673 If the given Builder is currently running, wait until the Build is
7674 finished and then announce the results.
7675 @item last BUILDER
7676 Return the results of the last build to run on the given Builder.
7677 @item join CHANNEL
7678 Join the given IRC channel
7679 @item leave CHANNEL
7680 Leave the given IRC channel
7681 @item notify on|off|list EVENT
7682 Report events relating to builds.  If the command is issued as a
7683 private message, then the report will be sent back as a private
7684 message to the user who issued the command.  Otherwise, the report
7685 will be sent to the channel.  Available events to be notified are:
7687 @table @code
7688 @item started
7689 A build has started
7690 @item finished
7691 A build has finished
7692 @item success
7693 A build finished successfully
7694 @item failed
7695 A build failed
7696 @item exception
7697 A build generated and exception
7698 @item successToFailed
7699 The previous build was successful, but this one failed
7700 @item failedToSuccess
7701 The previous build failed, but this one was successful
7702 @end table
7704 @item help COMMAND
7705 Describe a command. Use @code{help commands} to get a list of known
7706 commands.
7707 @item source
7708 Announce the URL of the Buildbot's home page.
7709 @item version
7710 Announce the version of this Buildbot.
7711 @end table
7713 If the @code{allowForce=True} option was used, some addtional commands
7714 will be available:
7716 @table @code
7717 @item force build BUILDER REASON
7718 Tell the given Builder to start a build of the latest code. The user
7719 requesting the build and REASON are recorded in the Build status. The
7720 buildbot will announce the build's status when it finishes.
7722 @item stop build BUILDER REASON
7723 Terminate any running build in the given Builder. REASON will be added
7724 to the build status to explain why it was stopped. You might use this
7725 if you committed a bug, corrected it right away, and don't want to
7726 wait for the first build (which is destined to fail) to complete
7727 before starting the second (hopefully fixed) build.
7728 @end table
7730 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
7731 @section PBListener
7733 @cindex PBListener
7734 @stindex buildbot.status.client.PBListener
7737 @example
7738 import buildbot.status.client
7739 pbl = buildbot.status.client.PBListener(port=int, user=str,
7740                                         passwd=str)
7741 c['status'].append(pbl)
7742 @end example
7744 This sets up a PB listener on the given TCP port, to which a PB-based
7745 status client can connect and retrieve status information.
7746 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
7747 status client. The @code{port} argument can also be a strports
7748 specification string.
7750 @node Writing New Status Plugins,  , PBListener, Status Delivery
7751 @section Writing New Status Plugins
7753 TODO: this needs a lot more examples
7755 Each status plugin is an object which provides the
7756 @code{twisted.application.service.IService} interface, which creates a
7757 tree of Services with the buildmaster at the top [not strictly true].
7758 The status plugins are all children of an object which implements
7759 @code{buildbot.interfaces.IStatus}, the main status object. From this
7760 object, the plugin can retrieve anything it wants about current and
7761 past builds. It can also subscribe to hear about new and upcoming
7762 builds.
7764 Status plugins which only react to human queries (like the Waterfall
7765 display) never need to subscribe to anything: they are idle until
7766 someone asks a question, then wake up and extract the information they
7767 need to answer it, then they go back to sleep. Plugins which need to
7768 act spontaneously when builds complete (like the MailNotifier plugin)
7769 need to subscribe to hear about new builds.
7771 If the status plugin needs to run network services (like the HTTP
7772 server used by the Waterfall plugin), they can be attached as Service
7773 children of the plugin itself, using the @code{IServiceCollection}
7774 interface.
7778 @node Command-line tool, Resources, Status Delivery, Top
7779 @chapter Command-line tool
7781 The @command{buildbot} command-line tool can be used to start or stop a
7782 buildmaster or buildbot, and to interact with a running buildmaster.
7783 Some of its subcommands are intended for buildmaster admins, while
7784 some are for developers who are editing the code that the buildbot is
7785 monitoring.
7787 @menu
7788 * Administrator Tools::
7789 * Developer Tools::
7790 * Other Tools::
7791 * .buildbot config directory::
7792 @end menu
7794 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
7795 @section Administrator Tools
7797 The following @command{buildbot} sub-commands are intended for
7798 buildmaster administrators:
7800 @heading create-master
7802 This creates a new directory and populates it with files that allow it
7803 to be used as a buildmaster's base directory.
7805 @example
7806 buildbot create-master BASEDIR
7807 @end example
7809 @heading create-slave
7811 This creates a new directory and populates it with files that let it
7812 be used as a buildslave's base directory. You must provide several
7813 arguments, which are used to create the initial @file{buildbot.tac}
7814 file.
7816 @example
7817 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
7818 @end example
7820 @heading start
7822 This starts a buildmaster or buildslave which was already created in
7823 the given base directory. The daemon is launched in the background,
7824 with events logged to a file named @file{twistd.log}.
7826 @example
7827 buildbot start BASEDIR
7828 @end example
7830 @heading stop
7832 This terminates the daemon (either buildmaster or buildslave) running
7833 in the given directory.
7835 @example
7836 buildbot stop BASEDIR
7837 @end example
7839 @heading sighup
7841 This sends a SIGHUP to the buildmaster running in the given directory,
7842 which causes it to re-read its @file{master.cfg} file.
7844 @example
7845 buildbot sighup BASEDIR
7846 @end example
7848 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
7849 @section Developer Tools
7851 These tools are provided for use by the developers who are working on
7852 the code that the buildbot is monitoring.
7854 @menu
7855 * statuslog::
7856 * statusgui::
7857 * try::
7858 @end menu
7860 @node statuslog, statusgui, Developer Tools, Developer Tools
7861 @subsection statuslog
7863 @example
7864 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
7865 @end example
7867 This command starts a simple text-based status client, one which just
7868 prints out a new line each time an event occurs on the buildmaster.
7870 The @option{--master} option provides the location of the
7871 @code{buildbot.status.client.PBListener} status port, used to deliver
7872 build information to realtime status clients. The option is always in
7873 the form of a string, with hostname and port number separated by a
7874 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
7875 same as the slaveport (although a future version may allow the same
7876 port number to be used for both purposes). If you get an error message
7877 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
7878 this may indicate that you are connecting to the slaveport rather than
7879 a @code{PBListener} port.
7881 The @option{--master} option can also be provided by the
7882 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
7883 config directory}).
7885 @node statusgui, try, statuslog, Developer Tools
7886 @subsection statusgui
7888 @cindex statusgui
7890 If you have set up a PBListener (@pxref{PBListener}), you will be able
7891 to monitor your Buildbot using a simple Gtk+ application invoked with
7892 the @code{buildbot statusgui} command:
7894 @example
7895 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
7896 @end example
7898 This command starts a simple Gtk+-based status client, which contains
7899 a few boxes for each Builder that change color as events occur. It
7900 uses the same @option{--master} argument as the @command{buildbot
7901 statuslog} command (@pxref{statuslog}).
7903 @node try,  , statusgui, Developer Tools
7904 @subsection try
7906 This lets a developer to ask the question ``What would happen if I
7907 committed this patch right now?''. It runs the unit test suite (across
7908 multiple build platforms) on the developer's current code, allowing
7909 them to make sure they will not break the tree when they finally
7910 commit their changes.
7912 The @command{buildbot try} command is meant to be run from within a
7913 developer's local tree, and starts by figuring out the base revision
7914 of that tree (what revision was current the last time the tree was
7915 updated), and a patch that can be applied to that revision of the tree
7916 to make it match the developer's copy. This (revision, patch) pair is
7917 then sent to the buildmaster, which runs a build with that
7918 SourceStamp. If you want, the tool will emit status messages as the
7919 builds run, and will not terminate until the first failure has been
7920 detected (or the last success).
7922 There is an alternate form which accepts a pre-made patch file
7923 (typically the output of a command like 'svn diff'). This ``--diff''
7924 form does not require a local tree to run from. See @xref{try --diff}.
7926 For this command to work, several pieces must be in place:
7929 @heading TryScheduler
7931 @slindex buildbot.scheduler.Try_Jobdir
7932 @slindex buildbot.scheduler.Try_Userpass
7934 The buildmaster must have a @code{scheduler.Try} instance in
7935 the config file's @code{c['schedulers']} list. This lets the
7936 administrator control who may initiate these ``trial'' builds, which
7937 branches are eligible for trial builds, and which Builders should be
7938 used for them.
7940 The @code{TryScheduler} has various means to accept build requests:
7941 all of them enforce more security than the usual buildmaster ports do.
7942 Any source code being built can be used to compromise the buildslave
7943 accounts, but in general that code must be checked out from the VC
7944 repository first, so only people with commit privileges can get
7945 control of the buildslaves. The usual force-build control channels can
7946 waste buildslave time but do not allow arbitrary commands to be
7947 executed by people who don't have those commit privileges. However,
7948 the source code patch that is provided with the trial build does not
7949 have to go through the VC system first, so it is important to make
7950 sure these builds cannot be abused by a non-committer to acquire as
7951 much control over the buildslaves as a committer has. Ideally, only
7952 developers who have commit access to the VC repository would be able
7953 to start trial builds, but unfortunately the buildmaster does not, in
7954 general, have access to VC system's user list.
7956 As a result, the @code{TryScheduler} requires a bit more
7957 configuration. There are currently two ways to set this up:
7959 @table @strong
7960 @item jobdir (ssh)
7962 This approach creates a command queue directory, called the
7963 ``jobdir'', in the buildmaster's working directory. The buildmaster
7964 admin sets the ownership and permissions of this directory to only
7965 grant write access to the desired set of developers, all of whom must
7966 have accounts on the machine. The @code{buildbot try} command creates
7967 a special file containing the source stamp information and drops it in
7968 the jobdir, just like a standard maildir. When the buildmaster notices
7969 the new file, it unpacks the information inside and starts the builds.
7971 The config file entries used by 'buildbot try' either specify a local
7972 queuedir (for which write and mv are used) or a remote one (using scp
7973 and ssh).
7975 The advantage of this scheme is that it is quite secure, the
7976 disadvantage is that it requires fiddling outside the buildmaster
7977 config (to set the permissions on the jobdir correctly). If the
7978 buildmaster machine happens to also house the VC repository, then it
7979 can be fairly easy to keep the VC userlist in sync with the
7980 trial-build userlist. If they are on different machines, this will be
7981 much more of a hassle. It may also involve granting developer accounts
7982 on a machine that would not otherwise require them.
7984 To implement this, the buildslave invokes 'ssh -l username host
7985 buildbot tryserver ARGS', passing the patch contents over stdin. The
7986 arguments must include the inlet directory and the revision
7987 information.
7989 @item user+password (PB)
7991 In this approach, each developer gets a username/password pair, which
7992 are all listed in the buildmaster's configuration file. When the
7993 developer runs @code{buildbot try}, their machine connects to the
7994 buildmaster via PB and authenticates themselves using that username
7995 and password, then sends a PB command to start the trial build.
7997 The advantage of this scheme is that the entire configuration is
7998 performed inside the buildmaster's config file. The disadvantages are
7999 that it is less secure (while the ``cred'' authentication system does
8000 not expose the password in plaintext over the wire, it does not offer
8001 most of the other security properties that SSH does). In addition, the
8002 buildmaster admin is responsible for maintaining the username/password
8003 list, adding and deleting entries as developers come and go.
8005 @end table
8008 For example, to set up the ``jobdir'' style of trial build, using a
8009 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
8010 all your project developers were members of the @code{developers} unix
8011 group), you would first create that directory (with @command{mkdir
8012 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
8013 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
8014 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
8015 MASTERDIR/jobdir/*}), and then use the following scheduler in the
8016 buildmaster's config file:
8018 @example
8019 from buildbot.scheduler import Try_Jobdir
8020 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
8021                jobdir="jobdir")
8022 c['schedulers'] = [s]
8023 @end example
8025 Note that you must create the jobdir before telling the buildmaster to
8026 use this configuration, otherwise you will get an error. Also remember
8027 that the buildmaster must be able to read and write to the jobdir as
8028 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
8029 as you start using the jobdir, to make sure the buildmaster is happy
8030 with it.
8032 To use the username/password form of authentication, create a
8033 @code{Try_Userpass} instance instead. It takes the same
8034 @code{builderNames} argument as the @code{Try_Jobdir} form, but
8035 accepts an addtional @code{port} argument (to specify the TCP port to
8036 listen on) and a @code{userpass} list of username/password pairs to
8037 accept. Remember to use good passwords for this: the security of the
8038 buildslave accounts depends upon it:
8040 @example
8041 from buildbot.scheduler import Try_Userpass
8042 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
8043                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
8044 c['schedulers'] = [s]
8045 @end example
8047 Like most places in the buildbot, the @code{port} argument takes a
8048 strports specification. See @code{twisted.application.strports} for
8049 details.
8052 @heading locating the master
8054 The @command{try} command needs to be told how to connect to the
8055 @code{TryScheduler}, and must know which of the authentication
8056 approaches described above is in use by the buildmaster. You specify
8057 the approach by using @option{--connect=ssh} or @option{--connect=pb}
8058 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
8059 @file{.buildbot/options}).
8061 For the PB approach, the command must be given a @option{--master}
8062 argument (in the form HOST:PORT) that points to TCP port that you
8063 picked in the @code{Try_Userpass} scheduler. It also takes a
8064 @option{--username} and @option{--passwd} pair of arguments that match
8065 one of the entries in the buildmaster's @code{userpass} list. These
8066 arguments can also be provided as @code{try_master},
8067 @code{try_username}, and @code{try_password} entries in the
8068 @file{.buildbot/options} file.
8070 For the SSH approach, the command must be given @option{--tryhost},
8071 @option{--username}, and optionally @option{--password} (TODO:
8072 really?) to get to the buildmaster host. It must also be given
8073 @option{--trydir}, which points to the inlet directory configured
8074 above. The trydir can be relative to the user's home directory, but
8075 most of the time you will use an explicit path like
8076 @file{~buildbot/project/trydir}. These arguments can be provided in
8077 @file{.buildbot/options} as @code{try_host}, @code{try_username},
8078 @code{try_password}, and @code{try_dir}.
8080 In addition, the SSH approach needs to connect to a PBListener status
8081 port, so it can retrieve and report the results of the build (the PB
8082 approach uses the existing connection to retrieve status information,
8083 so this step is not necessary). This requires a @option{--master}
8084 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
8085 in the form of a HOSTNAME:PORT string.
8088 @heading choosing the Builders
8090 A trial build is performed on multiple Builders at the same time, and
8091 the developer gets to choose which Builders are used (limited to a set
8092 selected by the buildmaster admin with the TryScheduler's
8093 @code{builderNames=} argument). The set you choose will depend upon
8094 what your goals are: if you are concerned about cross-platform
8095 compatibility, you should use multiple Builders, one from each
8096 platform of interest. You might use just one builder if that platform
8097 has libraries or other facilities that allow better test coverage than
8098 what you can accomplish on your own machine, or faster test runs.
8100 The set of Builders to use can be specified with multiple
8101 @option{--builder} arguments on the command line. It can also be
8102 specified with a single @code{try_builders} option in
8103 @file{.buildbot/options} that uses a list of strings to specify all
8104 the Builder names:
8106 @example
8107 try_builders = ["full-OSX", "full-win32", "full-linux"]
8108 @end example
8110 @heading specifying the VC system
8112 The @command{try} command also needs to know how to take the
8113 developer's current tree and extract the (revision, patch)
8114 source-stamp pair. Each VC system uses a different process, so you
8115 start by telling the @command{try} command which VC system you are
8116 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
8117 This can also be provided as @code{try_vc} in
8118 @file{.buildbot/options}.
8120 The following names are recognized: @code{cvs} @code{svn} @code{baz}
8121 @code{tla} @code{hg} @code{darcs}
8124 @heading finding the top of the tree
8126 Some VC systems (notably CVS and SVN) track each directory
8127 more-or-less independently, which means the @command{try} command
8128 needs to move up to the top of the project tree before it will be able
8129 to construct a proper full-tree patch. To accomplish this, the
8130 @command{try} command will crawl up through the parent directories
8131 until it finds a marker file. The default name for this marker file is
8132 @file{.buildbot-top}, so when you are using CVS or SVN you should
8133 @code{touch .buildbot-top} from the top of your tree before running
8134 @command{buildbot try}. Alternatively, you can use a filename like
8135 @file{ChangeLog} or @file{README}, since many projects put one of
8136 these files in their top-most directory (and nowhere else). To set
8137 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
8138 options file with @code{try_topfile = 'ChangeLog'}.
8140 You can also manually set the top of the tree with
8141 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
8142 '~/trees/mytree'}. If you use @code{try_topdir}, in a
8143 @file{.buildbot/options} file, you will need a separate options file
8144 for each tree you use, so it may be more convenient to use the
8145 @code{try_topfile} approach instead.
8147 Other VC systems which work on full projects instead of individual
8148 directories (tla, baz, darcs, monotone, mercurial, git) do not require
8149 @command{try} to know the top directory, so the @option{--try-topfile}
8150 and @option{--try-topdir} arguments will be ignored.
8151 @c is this true? I think I currently require topdirs all the time.
8153 If the @command{try} command cannot find the top directory, it will
8154 abort with an error message.
8156 @heading determining the branch name
8158 Some VC systems record the branch information in a way that ``try''
8159 can locate it, in particular Arch (both @command{tla} and
8160 @command{baz}). For the others, if you are using something other than
8161 the default branch, you will have to tell the buildbot which branch
8162 your tree is using. You can do this with either the @option{--branch}
8163 argument, or a @option{try_branch} entry in the
8164 @file{.buildbot/options} file.
8166 @heading determining the revision and patch
8168 Each VC system has a separate approach for determining the tree's base
8169 revision and computing a patch.
8171 @table @code
8173 @item CVS
8175 @command{try} pretends that the tree is up to date. It converts the
8176 current time into a @code{-D} time specification, uses it as the base
8177 revision, and computes the diff between the upstream tree as of that
8178 point in time versus the current contents. This works, more or less,
8179 but requires that the local clock be in reasonably good sync with the
8180 repository.
8182 @item SVN
8183 @command{try} does a @code{svn status -u} to find the latest
8184 repository revision number (emitted on the last line in the ``Status
8185 against revision: NN'' message). It then performs an @code{svn diff
8186 -rNN} to find out how your tree differs from the repository version,
8187 and sends the resulting patch to the buildmaster. If your tree is not
8188 up to date, this will result in the ``try'' tree being created with
8189 the latest revision, then @emph{backwards} patches applied to bring it
8190 ``back'' to the version you actually checked out (plus your actual
8191 code changes), but this will still result in the correct tree being
8192 used for the build.
8194 @item baz
8195 @command{try} does a @code{baz tree-id} to determine the
8196 fully-qualified version and patch identifier for the tree
8197 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
8198 as the base revision. It then does a @code{baz diff} to obtain the
8199 patch.
8201 @item tla
8202 @command{try} does a @code{tla tree-version} to get the
8203 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
8204 first line of @code{tla logs --reverse} to figure out the base
8205 revision. Then it does @code{tla changes --diffs} to obtain the patch.
8207 @item Darcs
8208 @code{darcs changes --context} emits a text file that contains a list
8209 of all patches back to and including the last tag was made. This text
8210 file (plus the location of a repository that contains all these
8211 patches) is sufficient to re-create the tree. Therefore the contents
8212 of this ``context'' file @emph{are} the revision stamp for a
8213 Darcs-controlled source tree.
8215 So @command{try} does a @code{darcs changes --context} to determine
8216 what your tree's base revision is, and then does a @code{darcs diff
8217 -u} to compute the patch relative to that revision.
8219 @item Mercurial
8220 @code{hg identify} emits a short revision ID (basically a truncated
8221 SHA1 hash of the current revision's contents), which is used as the
8222 base revision. @code{hg diff} then provides the patch relative to that
8223 revision. For @command{try} to work, your working directory must only
8224 have patches that are available from the same remotely-available
8225 repository that the build process' @code{step.Mercurial} will use.
8227 @item Git
8228 @code{git branch -v} lists all the branches available in the local
8229 repository along with the revision ID it points to and a short summary
8230 of the last commit. The line containing the currently checked out
8231 branch begins with '* ' (star and space) while all the others start
8232 with '  ' (two spaces). @command{try} scans for this line and extracts
8233 the branch name and revision from it. Then it generates a diff against
8234 the base revision.
8235 @c TODO: I'm not sure if this actually works the way it's intended
8236 @c since the extracted base revision might not actually exist in the
8237 @c upstream repository. Perhaps we need to add a --remote option to
8238 @c specify the remote tracking branch to generate a diff against.
8240 @c TODO: monotone
8241 @end table
8243 @heading waiting for results
8245 If you provide the @option{--wait} option (or @code{try_wait = True}
8246 in @file{.buildbot/options}), the @command{buildbot try} command will
8247 wait until your changes have either been proven good or bad before
8248 exiting. Unless you use the @option{--quiet} option (or
8249 @code{try_quiet=True}), it will emit a progress message every 60
8250 seconds until the builds have completed.
8252 @menu
8253 * try --diff::
8254 @end menu
8256 @node try --diff,  , try, try
8257 @subsubsection try --diff
8259 Sometimes you might have a patch from someone else that you want to
8260 submit to the buildbot. For example, a user may have created a patch
8261 to fix some specific bug and sent it to you by email. You've inspected
8262 the patch and suspect that it might do the job (and have at least
8263 confirmed that it doesn't do anything evil). Now you want to test it
8264 out.
8266 One approach would be to check out a new local tree, apply the patch,
8267 run your local tests, then use ``buildbot try'' to run the tests on
8268 other platforms. An alternate approach is to use the @command{buildbot
8269 try --diff} form to have the buildbot test the patch without using a
8270 local tree.
8272 This form takes a @option{--diff} argument which points to a file that
8273 contains the patch you want to apply. By default this patch will be
8274 applied to the TRUNK revision, but if you give the optional
8275 @option{--baserev} argument, a tree of the given revision will be used
8276 as a starting point instead of TRUNK.
8278 You can also use @command{buildbot try --diff=-} to read the patch
8279 from stdin.
8281 Each patch has a ``patchlevel'' associated with it. This indicates the
8282 number of slashes (and preceding pathnames) that should be stripped
8283 before applying the diff. This exactly corresponds to the @option{-p}
8284 or @option{--strip} argument to the @command{patch} utility. By
8285 default @command{buildbot try --diff} uses a patchlevel of 0, but you
8286 can override this with the @option{-p} argument.
8288 When you use @option{--diff}, you do not need to use any of the other
8289 options that relate to a local tree, specifically @option{--vc},
8290 @option{--try-topfile}, or @option{--try-topdir}. These options will
8291 be ignored. Of course you must still specify how to get to the
8292 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
8295 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
8296 @section Other Tools
8298 These tools are generally used by buildmaster administrators.
8300 @menu
8301 * sendchange::
8302 * debugclient::
8303 @end menu
8305 @node sendchange, debugclient, Other Tools, Other Tools
8306 @subsection sendchange
8308 This command is used to tell the buildmaster about source changes. It
8309 is intended to be used from within a commit script, installed on the
8310 VC server. It requires that you have a PBChangeSource
8311 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
8312 @code{c['change_source']}).
8315 @example
8316 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
8317 @end example
8319 There are other (optional) arguments which can influence the
8320 @code{Change} that gets submitted:
8322 @table @code
8323 @item --branch
8324 This provides the (string) branch specifier. If omitted, it defaults
8325 to None, indicating the ``default branch''. All files included in this
8326 Change must be on the same branch.
8328 @item --revision_number
8329 This provides a (numeric) revision number for the change, used for VC systems
8330 that use numeric transaction numbers (like Subversion).
8332 @item --revision
8333 This provides a (string) revision specifier, for VC systems that use
8334 strings (Arch would use something like patch-42 etc).
8336 @item --revision_file
8337 This provides a filename which will be opened and the contents used as
8338 the revision specifier. This is specifically for Darcs, which uses the
8339 output of @command{darcs changes --context} as a revision specifier.
8340 This context file can be a couple of kilobytes long, spanning a couple
8341 lines per patch, and would be a hassle to pass as a command-line
8342 argument.
8344 @item --comments
8345 This provides the change comments as a single argument. You may want
8346 to use @option{--logfile} instead.
8348 @item --logfile
8349 This instructs the tool to read the change comments from the given
8350 file. If you use @code{-} as the filename, the tool will read the
8351 change comments from stdin.
8352 @end table
8355 @node debugclient,  , sendchange, Other Tools
8356 @subsection debugclient
8358 @example
8359 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
8360 @end example
8362 This launches a small Gtk+/Glade-based debug tool, connecting to the
8363 buildmaster's ``debug port''. This debug port shares the same port
8364 number as the slaveport (@pxref{Setting the slaveport}), but the
8365 @code{debugPort} is only enabled if you set a debug password in the
8366 buildmaster's config file (@pxref{Debug options}). The
8367 @option{--passwd} option must match the @code{c['debugPassword']}
8368 value.
8370 @option{--master} can also be provided in @file{.debug/options} by the
8371 @code{master} key. @option{--passwd} can be provided by the
8372 @code{debugPassword} key.
8374 The @code{Connect} button must be pressed before any of the other
8375 buttons will be active. This establishes the connection to the
8376 buildmaster. The other sections of the tool are as follows:
8378 @table @code
8379 @item Reload .cfg
8380 Forces the buildmaster to reload its @file{master.cfg} file. This is
8381 equivalent to sending a SIGHUP to the buildmaster, but can be done
8382 remotely through the debug port. Note that it is a good idea to be
8383 watching the buildmaster's @file{twistd.log} as you reload the config
8384 file, as any errors which are detected in the config file will be
8385 announced there.
8387 @item Rebuild .py
8388 (not yet implemented). The idea here is to use Twisted's ``rebuild''
8389 facilities to replace the buildmaster's running code with a new
8390 version. Even if this worked, it would only be used by buildbot
8391 developers.
8393 @item poke IRC
8394 This locates a @code{words.IRC} status target and causes it to emit a
8395 message on all the channels to which it is currently connected. This
8396 was used to debug a problem in which the buildmaster lost the
8397 connection to the IRC server and did not attempt to reconnect.
8399 @item Commit
8400 This allows you to inject a Change, just as if a real one had been
8401 delivered by whatever VC hook you are using. You can set the name of
8402 the committed file and the name of the user who is doing the commit.
8403 Optionally, you can also set a revision for the change. If the
8404 revision you provide looks like a number, it will be sent as an
8405 integer, otherwise it will be sent as a string.
8407 @item Force Build
8408 This lets you force a Builder (selected by name) to start a build of
8409 the current source tree.
8411 @item Currently
8412 (obsolete). This was used to manually set the status of the given
8413 Builder, but the status-assignment code was changed in an incompatible
8414 way and these buttons are no longer meaningful.
8416 @end table
8419 @node .buildbot config directory,  , Other Tools, Command-line tool
8420 @section .buildbot config directory
8422 Many of the @command{buildbot} tools must be told how to contact the
8423 buildmaster that they interact with. This specification can be
8424 provided as a command-line argument, but most of the time it will be
8425 easier to set them in an ``options'' file. The @command{buildbot}
8426 command will look for a special directory named @file{.buildbot},
8427 starting from the current directory (where the command was run) and
8428 crawling upwards, eventually looking in the user's home directory. It
8429 will look for a file named @file{options} in this directory, and will
8430 evaluate it as a python script, looking for certain names to be set.
8431 You can just put simple @code{name = 'value'} pairs in this file to
8432 set the options.
8434 For a description of the names used in this file, please see the
8435 documentation for the individual @command{buildbot} sub-commands. The
8436 following is a brief sample of what this file's contents could be.
8438 @example
8439 # for status-reading tools
8440 masterstatus = 'buildbot.example.org:12345'
8441 # for 'sendchange' or the debug port
8442 master = 'buildbot.example.org:18990'
8443 debugPassword = 'eiv7Po'
8444 @end example
8446 @table @code
8447 @item masterstatus
8448 Location of the @code{client.PBListener} status port, used by
8449 @command{statuslog} and @command{statusgui}.
8451 @item master
8452 Location of the @code{debugPort} (for @command{debugclient}). Also the
8453 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
8454 Usually shares the slaveport, but a future version may make it
8455 possible to have these listen on a separate port number.
8457 @item debugPassword
8458 Must match the value of @code{c['debugPassword']}, used to protect the
8459 debug port, for the @command{debugclient} command.
8461 @item username
8462 Provides a default username for the @command{sendchange} command.
8464 @end table
8467 The following options are used by the @code{buildbot try} command
8468 (@pxref{try}):
8470 @table @code
8471 @item try_connect
8472 This specifies how the ``try'' command should deliver its request to
8473 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
8474 @item try_builders
8475 Which builders should be used for the ``try'' build.
8476 @item try_vc
8477 This specifies the version control system being used.
8478 @item try_branch
8479 This indicates that the current tree is on a non-trunk branch.
8480 @item try_topdir
8481 @item try_topfile
8482 Use @code{try_topdir} to explicitly indicate the top of your working
8483 tree, or @code{try_topfile} to name a file that will only be found in
8484 that top-most directory.
8486 @item try_host
8487 @item try_username
8488 @item try_dir
8489 When try_connect is ``ssh'', the command will pay attention to
8490 @code{try_host}, @code{try_username}, and @code{try_dir}.
8492 @item try_username
8493 @item try_password
8494 @item try_master
8495 Instead, when @code{try_connect} is ``pb'', the command will pay
8496 attention to @code{try_username}, @code{try_password}, and
8497 @code{try_master}.
8499 @item try_wait
8500 @item masterstatus
8501 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
8502 command to wait for the requested build to complete.
8504 @end table
8508 @node Resources, Developer's Appendix, Command-line tool, Top
8509 @chapter Resources
8511 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
8513 For configuration questions and general discussion, please use the
8514 @code{buildbot-devel} mailing list. The subscription instructions and
8515 archives are available at
8516 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
8518 @node Developer's Appendix, Index of Useful Classes, Resources, Top
8519 @unnumbered Developer's Appendix
8521 This appendix contains random notes about the implementation of the
8522 Buildbot, and is likely to only be of use to people intending to
8523 extend the Buildbot's internals.
8525 The buildmaster consists of a tree of Service objects, which is shaped
8526 as follows:
8528 @example
8529 BuildMaster
8530  ChangeMaster  (in .change_svc)
8531   [IChangeSource instances]
8532  [IScheduler instances]  (in .schedulers)
8533  BotMaster  (in .botmaster)
8534   [IBuildSlave instances]
8535  [IStatusTarget instances]  (in .statusTargets)
8536 @end example
8538 The BotMaster has a collection of Builder objects as values of its
8539 @code{.builders} dictionary.
8542 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
8543 @unnumbered Index of Useful Classes
8545 This is a list of all user-visible classes. There are the ones that
8546 are useful in @file{master.cfg}, the buildmaster's configuration file.
8547 Classes that are not listed here are generally internal things that
8548 admins are unlikely to have much use for.
8551 @heading Change Sources
8552 @printindex cs
8554 @heading Schedulers and Locks
8555 @printindex sl
8557 @heading Build Factories
8558 @printindex bf
8560 @heading Build Steps
8561 @printindex bs
8563 @c undocumented steps
8564 @bsindex buildbot.steps.source.Git
8565 @bsindex buildbot.steps.maxq.MaxQ
8568 @heading Status Targets
8569 @printindex st
8571 @c TODO: undocumented targets
8573 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
8574 @unnumbered Index of master.cfg keys
8576 This is a list of all of the significant keys in master.cfg . Recall
8577 that master.cfg is effectively a small python program with exactly one
8578 responsibility: create a dictionary named @code{BuildmasterConfig}.
8579 The keys of this dictionary are listed here. The beginning of the
8580 master.cfg file typically starts with something like:
8582 @example
8583 BuildmasterConfig = c = @{@}
8584 @end example
8586 Therefore a config key of @code{change_source} will usually appear in
8587 master.cfg as @code{c['change_source']}.
8589 @printindex bc
8592 @node Index,  , Index of master.cfg keys, Top
8593 @unnumbered Index
8595 @printindex cp
8598 @bye