Add MasterShellCommand
[buildbot.git] / docs / buildbot.texinfo
blob5ba5320eb617923a4fb38313462b76bafa4e47c0
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 * Steps That Run on the Master::
204 * Triggering Schedulers::
205 * Writing New BuildSteps::
207 Source Checkout
209 * CVS::
210 * SVN::
211 * Darcs::
212 * Mercurial::
213 * Arch::
214 * Bazaar::
215 * Bzr::
216 * P4::
217 * Git::
219 Simple ShellCommand Subclasses
221 * Configure::
222 * Compile::
223 * Test::
224 * TreeSize::
225 * PerlModuleTest::
226 * SetProperty::
228 Python BuildSteps
230 * BuildEPYDoc::
231 * PyFlakes::
233 Writing New BuildSteps
235 * BuildStep LogFiles::
236 * Reading Logfiles::
237 * Adding LogObservers::
238 * BuildStep URLs::
240 Build Factories
242 * BuildStep Objects::
243 * BuildFactory::
244 * Process-Specific build factories::
246 BuildStep Objects
248 * BuildFactory Attributes::
249 * Quick builds::
251 BuildFactory
253 * BuildFactory Attributes::
254 * Quick builds::
256 Process-Specific build factories
258 * GNUAutoconf::
259 * CPAN::
260 * Python distutils::
261 * Python/Twisted/trial projects::
263 Status Delivery
265 * WebStatus::
266 * MailNotifier::
267 * IRC Bot::
268 * PBListener::
269 * Writing New Status Plugins::
271 WebStatus
273 * WebStatus Configuration Parameters::
274 * Buildbot Web Resources::
275 * XMLRPC server::
276 * HTML Waterfall::
278 Command-line tool
280 * Administrator Tools::
281 * Developer Tools::
282 * Other Tools::
283 * .buildbot config directory::
285 Developer Tools
287 * statuslog::
288 * statusgui::
289 * try::
291 waiting for results
293 * try --diff::
295 Other Tools
297 * sendchange::
298 * debugclient::
300 @end detailmenu
301 @end menu
303 @node Introduction, Installation, Top, Top
304 @chapter Introduction
306 @cindex introduction
308 The BuildBot is a system to automate the compile/test cycle required by most
309 software projects to validate code changes. By automatically rebuilding and
310 testing the tree each time something has changed, build problems are
311 pinpointed quickly, before other developers are inconvenienced by the
312 failure. The guilty developer can be identified and harassed without human
313 intervention. By running the builds on a variety of platforms, developers
314 who do not have the facilities to test their changes everywhere before
315 checkin will at least know shortly afterwards whether they have broken the
316 build or not. Warning counts, lint checks, image size, compile time, and
317 other build parameters can be tracked over time, are more visible, and
318 are therefore easier to improve.
320 The overall goal is to reduce tree breakage and provide a platform to
321 run tests or code-quality checks that are too annoying or pedantic for
322 any human to waste their time with. Developers get immediate (and
323 potentially public) feedback about their changes, encouraging them to
324 be more careful about testing before checkin.
326 Features:
328 @itemize @bullet
329 @item
330 run builds on a variety of slave platforms
331 @item
332 arbitrary build process: handles projects using C, Python, whatever
333 @item
334 minimal host requirements: python and Twisted
335 @item
336 slaves can be behind a firewall if they can still do checkout
337 @item
338 status delivery through web page, email, IRC, other protocols
339 @item
340 track builds in progress, provide estimated completion time
341 @item
342 flexible configuration by subclassing generic build process classes
343 @item
344 debug tools to force a new build, submit fake Changes, query slave status
345 @item
346 released under the GPL
347 @end itemize
349 @menu
350 * History and Philosophy::
351 * System Architecture::
352 * Control Flow::
353 @end menu
356 @node History and Philosophy, System Architecture, Introduction, Introduction
357 @section History and Philosophy
359 @cindex Philosophy of operation
361 The Buildbot was inspired by a similar project built for a development
362 team writing a cross-platform embedded system. The various components
363 of the project were supposed to compile and run on several flavors of
364 unix (linux, solaris, BSD), but individual developers had their own
365 preferences and tended to stick to a single platform. From time to
366 time, incompatibilities would sneak in (some unix platforms want to
367 use @code{string.h}, some prefer @code{strings.h}), and then the tree
368 would compile for some developers but not others. The buildbot was
369 written to automate the human process of walking into the office,
370 updating a tree, compiling (and discovering the breakage), finding the
371 developer at fault, and complaining to them about the problem they had
372 introduced. With multiple platforms it was difficult for developers to
373 do the right thing (compile their potential change on all platforms);
374 the buildbot offered a way to help.
376 Another problem was when programmers would change the behavior of a
377 library without warning its users, or change internal aspects that
378 other code was (unfortunately) depending upon. Adding unit tests to
379 the codebase helps here: if an application's unit tests pass despite
380 changes in the libraries it uses, you can have more confidence that
381 the library changes haven't broken anything. Many developers
382 complained that the unit tests were inconvenient or took too long to
383 run: having the buildbot run them reduces the developer's workload to
384 a minimum.
386 In general, having more visibility into the project is always good,
387 and automation makes it easier for developers to do the right thing.
388 When everyone can see the status of the project, developers are
389 encouraged to keep the tree in good working order. Unit tests that
390 aren't run on a regular basis tend to suffer from bitrot just like
391 code does: exercising them on a regular basis helps to keep them
392 functioning and useful.
394 The current version of the Buildbot is additionally targeted at
395 distributed free-software projects, where resources and platforms are
396 only available when provided by interested volunteers. The buildslaves
397 are designed to require an absolute minimum of configuration, reducing
398 the effort a potential volunteer needs to expend to be able to
399 contribute a new test environment to the project. The goal is for
400 anyone who wishes that a given project would run on their favorite
401 platform should be able to offer that project a buildslave, running on
402 that platform, where they can verify that their portability code
403 works, and keeps working.
405 @node System Architecture, Control Flow, History and Philosophy, Introduction
406 @comment  node-name,  next,  previous,  up
407 @section System Architecture
409 The Buildbot consists of a single @code{buildmaster} and one or more
410 @code{buildslaves}, connected in a star topology. The buildmaster
411 makes all decisions about what, when, and how to build. It sends
412 commands to be run on the build slaves, which simply execute the
413 commands and return the results. (certain steps involve more local
414 decision making, where the overhead of sending a lot of commands back
415 and forth would be inappropriate, but in general the buildmaster is
416 responsible for everything).
418 The buildmaster is usually fed @code{Changes} by some sort of version
419 control system (@pxref{Change Sources}), which may cause builds to be
420 run. As the builds are performed, various status messages are
421 produced, which are then sent to any registered Status Targets
422 (@pxref{Status Delivery}).
424 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
425 @image{images/overview,,,Overview Diagram,}
427 The buildmaster is configured and maintained by the ``buildmaster
428 admin'', who is generally the project team member responsible for
429 build process issues. Each buildslave is maintained by a ``buildslave
430 admin'', who do not need to be quite as involved. Generally slaves are
431 run by anyone who has an interest in seeing the project work well on
432 their favorite platform.
434 @menu
435 * BuildSlave Connections::
436 * Buildmaster Architecture::
437 * Status Delivery Architecture::
438 @end menu
440 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
441 @subsection BuildSlave Connections
443 The buildslaves are typically run on a variety of separate machines,
444 at least one per platform of interest. These machines connect to the
445 buildmaster over a TCP connection to a publically-visible port. As a
446 result, the buildslaves can live behind a NAT box or similar
447 firewalls, as long as they can get to buildmaster. The TCP connections
448 are initiated by the buildslave and accepted by the buildmaster, but
449 commands and results travel both ways within this connection. The
450 buildmaster is always in charge, so all commands travel exclusively
451 from the buildmaster to the buildslave.
453 To perform builds, the buildslaves must typically obtain source code
454 from a CVS/SVN/etc repository. Therefore they must also be able to
455 reach the repository. The buildmaster provides instructions for
456 performing builds, but does not provide the source code itself.
458 @image{images/slaves,,,BuildSlave Connections,}
460 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
461 @subsection Buildmaster Architecture
463 The Buildmaster consists of several pieces:
465 @image{images/master,,,BuildMaster Architecture,}
467 @itemize @bullet
469 @item
470 Change Sources, which create a Change object each time something is
471 modified in the VC repository. Most ChangeSources listen for messages
472 from a hook script of some sort. Some sources actively poll the
473 repository on a regular basis. All Changes are fed to the Schedulers.
475 @item
476 Schedulers, which decide when builds should be performed. They collect
477 Changes into BuildRequests, which are then queued for delivery to
478 Builders until a buildslave is available.
480 @item
481 Builders, which control exactly @emph{how} each build is performed
482 (with a series of BuildSteps, configured in a BuildFactory). Each
483 Build is run on a single buildslave.
485 @item
486 Status plugins, which deliver information about the build results
487 through protocols like HTTP, mail, and IRC.
489 @end itemize
491 @image{images/slavebuilder,,,SlaveBuilders,}
493 Each Builder is configured with a list of BuildSlaves that it will use
494 for its builds. These buildslaves are expected to behave identically:
495 the only reason to use multiple BuildSlaves for a single Builder is to
496 provide a measure of load-balancing.
498 Within a single BuildSlave, each Builder creates its own SlaveBuilder
499 instance. These SlaveBuilders operate independently from each other.
500 Each gets its own base directory to work in. It is quite common to
501 have many Builders sharing the same buildslave. For example, there
502 might be two buildslaves: one for i386, and a second for PowerPC.
503 There may then be a pair of Builders that do a full compile/test run,
504 one for each architecture, and a lone Builder that creates snapshot
505 source tarballs if the full builders complete successfully. The full
506 builders would each run on a single buildslave, whereas the tarball
507 creation step might run on either buildslave (since the platform
508 doesn't matter when creating source tarballs). In this case, the
509 mapping would look like:
511 @example
512 Builder(full-i386)  ->  BuildSlaves(slave-i386)
513 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
514 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
515 @end example
517 and each BuildSlave would have two SlaveBuilders inside it, one for a
518 full builder, and a second for the source-tarball builder.
520 Once a SlaveBuilder is available, the Builder pulls one or more
521 BuildRequests off its incoming queue. (It may pull more than one if it
522 determines that it can merge the requests together; for example, there
523 may be multiple requests to build the current HEAD revision). These
524 requests are merged into a single Build instance, which includes the
525 SourceStamp that describes what exact version of the source code
526 should be used for the build. The Build is then randomly assigned to a
527 free SlaveBuilder and the build begins.
529 The behaviour when BuildRequests are merged can be customized, @pxref{Merging
530 BuildRequests}.
532 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
533 @subsection Status Delivery Architecture
535 The buildmaster maintains a central Status object, to which various
536 status plugins are connected. Through this Status object, a full
537 hierarchy of build status objects can be obtained.
539 @image{images/status,,,Status Delivery,}
541 The configuration file controls which status plugins are active. Each
542 status plugin gets a reference to the top-level Status object. From
543 there they can request information on each Builder, Build, Step, and
544 LogFile. This query-on-demand interface is used by the html.Waterfall
545 plugin to create the main status page each time a web browser hits the
546 main URL.
548 The status plugins can also subscribe to hear about new Builds as they
549 occur: this is used by the MailNotifier to create new email messages
550 for each recently-completed Build.
552 The Status object records the status of old builds on disk in the
553 buildmaster's base directory. This allows it to return information
554 about historical builds.
556 There are also status objects that correspond to Schedulers and
557 BuildSlaves. These allow status plugins to report information about
558 upcoming builds, and the online/offline status of each buildslave.
561 @node Control Flow,  , System Architecture, Introduction
562 @comment  node-name,  next,  previous,  up
563 @section Control Flow
565 A day in the life of the buildbot:
567 @itemize @bullet
569 @item
570 A developer commits some source code changes to the repository. A hook
571 script or commit trigger of some sort sends information about this
572 change to the buildmaster through one of its configured Change
573 Sources. This notification might arrive via email, or over a network
574 connection (either initiated by the buildmaster as it ``subscribes''
575 to changes, or by the commit trigger as it pushes Changes towards the
576 buildmaster). The Change contains information about who made the
577 change, what files were modified, which revision contains the change,
578 and any checkin comments.
580 @item
581 The buildmaster distributes this change to all of its configured
582 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
583 to be started, and the Change is added to a list of those that will go
584 into a new Build. When the timer expires, a Build is started on each
585 of a set of configured Builders, all compiling/testing the same source
586 code. Unless configured otherwise, all Builds run in parallel on the
587 various buildslaves.
589 @item
590 The Build consists of a series of Steps. Each Step causes some number
591 of commands to be invoked on the remote buildslave associated with
592 that Builder. The first step is almost always to perform a checkout of
593 the appropriate revision from the same VC system that produced the
594 Change. The rest generally perform a compile and run unit tests. As
595 each Step runs, the buildslave reports back command output and return
596 status to the buildmaster.
598 @item
599 As the Build runs, status messages like ``Build Started'', ``Step
600 Started'', ``Build Finished'', etc, are published to a collection of
601 Status Targets. One of these targets is usually the HTML ``Waterfall''
602 display, which shows a chronological list of events, and summarizes
603 the results of the most recent build at the top of each column.
604 Developers can periodically check this page to see how their changes
605 have fared. If they see red, they know that they've made a mistake and
606 need to fix it. If they see green, they know that they've done their
607 duty and don't need to worry about their change breaking anything.
609 @item
610 If a MailNotifier status target is active, the completion of a build
611 will cause email to be sent to any developers whose Changes were
612 incorporated into this Build. The MailNotifier can be configured to
613 only send mail upon failing builds, or for builds which have just
614 transitioned from passing to failing. Other status targets can provide
615 similar real-time notification via different communication channels,
616 like IRC.
618 @end itemize
621 @node Installation, Concepts, Introduction, Top
622 @chapter Installation
624 @menu
625 * Requirements::
626 * Installing the code::
627 * Creating a buildmaster::
628 * Upgrading an Existing Buildmaster::
629 * Creating a buildslave::
630 * Launching the daemons::
631 * Logfiles::
632 * Shutdown::
633 * Maintenance::
634 * Troubleshooting::
635 @end menu
637 @node Requirements, Installing the code, Installation, Installation
638 @section Requirements
640 At a bare minimum, you'll need the following (for both the buildmaster
641 and a buildslave):
643 @itemize @bullet
644 @item
645 Python: http://www.python.org
647 Buildbot requires python-2.3 or later, and is primarily developed
648 against python-2.4. It is also tested against python-2.5 .
650 @item
651 Twisted: http://twistedmatrix.com
653 Both the buildmaster and the buildslaves require Twisted-2.0.x or
654 later. It has been tested against all releases of Twisted up to
655 Twisted-2.5.0 (the most recent as of this writing). As always, the
656 most recent version is recommended.
658 Twisted is delivered as a collection of subpackages. You'll need at
659 least "Twisted" (the core package), and you'll also want TwistedMail,
660 TwistedWeb, and TwistedWords (for sending email, serving a web status
661 page, and delivering build status via IRC, respectively). You might
662 also want TwistedConch (for the encrypted Manhole debug port). Note
663 that Twisted requires ZopeInterface to be installed as well.
665 @end itemize
667 Certain other packages may be useful on the system running the
668 buildmaster:
670 @itemize @bullet
671 @item
672 CVSToys: http://purl.net/net/CVSToys
674 If your buildmaster uses FreshCVSSource to receive change notification
675 from a cvstoys daemon, it will require CVSToys be installed (tested
676 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
677 only use a mail-parsing change source, or the SVN notification
678 script), you will not need CVSToys.
680 @end itemize
682 And of course, your project's build process will impose additional
683 requirements on the buildslaves. These hosts must have all the tools
684 necessary to compile and test your project's source code.
687 @node Installing the code, Creating a buildmaster, Requirements, Installation
688 @section Installing the code
690 @cindex installation
692 The Buildbot is installed using the standard python @code{distutils}
693 module. After unpacking the tarball, the process is:
695 @example
696 python setup.py build
697 python setup.py install
698 @end example
700 where the install step may need to be done as root. This will put the
701 bulk of the code in somewhere like
702 /usr/lib/python2.3/site-packages/buildbot . It will also install the
703 @code{buildbot} command-line tool in /usr/bin/buildbot.
705 To test this, shift to a different directory (like /tmp), and run:
707 @example
708 buildbot --version
709 @end example
711 If it shows you the versions of Buildbot and Twisted, the install went
712 ok. If it says @code{no such command} or it gets an @code{ImportError}
713 when it tries to load the libaries, then something went wrong.
714 @code{pydoc buildbot} is another useful diagnostic tool.
716 Windows users will find these files in other places. You will need to
717 make sure that python can find the libraries, and will probably find
718 it convenient to have @code{buildbot} on your PATH.
720 If you wish, you can run the buildbot unit test suite like this:
722 @example
723 PYTHONPATH=. trial buildbot.test
724 @end example
726 This should run up to 192 tests, depending upon what VC tools you have
727 installed. On my desktop machine it takes about five minutes to
728 complete. Nothing should fail, a few might be skipped. If any of the
729 tests fail, you should stop and investigate the cause before
730 continuing the installation process, as it will probably be easier to
731 track down the bug early.
733 If you cannot or do not wish to install the buildbot into a site-wide
734 location like @file{/usr} or @file{/usr/local}, you can also install
735 it into the account's home directory. Do the install command like
736 this:
738 @example
739 python setup.py install --home=~
740 @end example
742 That will populate @file{~/lib/python} and create
743 @file{~/bin/buildbot}. Make sure this lib directory is on your
744 @code{PYTHONPATH}.
747 @node Creating a buildmaster, Upgrading an Existing Buildmaster, Installing the code, Installation
748 @section Creating a buildmaster
750 As you learned earlier (@pxref{System Architecture}), the buildmaster
751 runs on a central host (usually one that is publically visible, so
752 everybody can check on the status of the project), and controls all
753 aspects of the buildbot system. Let us call this host
754 @code{buildbot.example.org}.
756 You may wish to create a separate user account for the buildmaster,
757 perhaps named @code{buildmaster}. This can help keep your personal
758 configuration distinct from that of the buildmaster and is useful if
759 you have to use a mail-based notification system (@pxref{Change
760 Sources}). However, the Buildbot will work just fine with your regular
761 user account.
763 You need to choose a directory for the buildmaster, called the
764 @code{basedir}. This directory will be owned by the buildmaster, which
765 will use configuration files therein, and create status files as it
766 runs. @file{~/Buildbot} is a likely value. If you run multiple
767 buildmasters in the same account, or if you run both masters and
768 slaves, you may want a more distinctive name like
769 @file{~/Buildbot/master/gnomovision} or
770 @file{~/Buildmasters/fooproject}. If you are using a separate user
771 account, this might just be @file{~buildmaster/masters/fooproject}.
773 Once you've picked a directory, use the @command{buildbot
774 create-master} command to create the directory and populate it with
775 startup files:
777 @example
778 buildbot create-master @var{basedir}
779 @end example
781 You will need to create a configuration file (@pxref{Configuration})
782 before starting the buildmaster. Most of the rest of this manual is
783 dedicated to explaining how to do this. A sample configuration file is
784 placed in the working directory, named @file{master.cfg.sample}, which
785 can be copied to @file{master.cfg} and edited to suit your purposes.
787 (Internal details: This command creates a file named
788 @file{buildbot.tac} that contains all the state necessary to create
789 the buildmaster. Twisted has a tool called @code{twistd} which can use
790 this .tac file to create and launch a buildmaster instance. twistd
791 takes care of logging and daemonization (running the program in the
792 background). @file{/usr/bin/buildbot} is a front end which runs twistd
793 for you.)
795 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
796 installed. This can be used as the basis for customized daemon startup,
797 @xref{Launching the daemons}.
799 @node Upgrading an Existing Buildmaster, Creating a buildslave, Creating a buildmaster, Installation
800 @section Upgrading an Existing Buildmaster
802 If you have just installed a new version of the Buildbot code, and you
803 have buildmasters that were created using an older version, you'll
804 need to upgrade these buildmasters before you can use them. The
805 upgrade process adds and modifies files in the buildmaster's base
806 directory to make it compatible with the new code.
808 @example
809 buildbot upgrade-master @var{basedir}
810 @end example
812 This command will also scan your @file{master.cfg} file for
813 incompatbilities (by loading it and printing any errors or deprecation
814 warnings that occur). Each buildbot release tries to be compatible
815 with configurations that worked cleanly (i.e. without deprecation
816 warnings) on the previous release: any functions or classes that are
817 to be removed will first be deprecated in a release, to give users a
818 chance to start using their replacement.
820 The 0.7.6 release introduced the @file{public_html/} directory, which
821 contains @file{index.html} and other files served by the
822 @code{WebStatus} and @code{Waterfall} status displays. The
823 @code{upgrade-master} command will create these files if they do not
824 already exist. It will not modify existing copies, but it will write a
825 new copy in e.g. @file{index.html.new} if the new version differs from
826 the version that already exists.
828 The @code{upgrade-master} command is idempotent. It is safe to run it
829 multiple times. After each upgrade of the buildbot code, you should
830 use @code{upgrade-master} on all your buildmasters.
833 @node Creating a buildslave, Launching the daemons, Upgrading an Existing Buildmaster, Installation
834 @section Creating a buildslave
836 Typically, you will be adding a buildslave to an existing buildmaster,
837 to provide additional architecture coverage. The buildbot
838 administrator will give you several pieces of information necessary to
839 connect to the buildmaster. You should also be somewhat familiar with
840 the project being tested, so you can troubleshoot build problems
841 locally.
843 The buildbot exists to make sure that the project's stated ``how to
844 build it'' process actually works. To this end, the buildslave should
845 run in an environment just like that of your regular developers.
846 Typically the project build process is documented somewhere
847 (@file{README}, @file{INSTALL}, etc), in a document that should
848 mention all library dependencies and contain a basic set of build
849 instructions. This document will be useful as you configure the host
850 and account in which the buildslave runs.
852 Here's a good checklist for setting up a buildslave:
854 @enumerate
855 @item
856 Set up the account
858 It is recommended (although not mandatory) to set up a separate user
859 account for the buildslave. This account is frequently named
860 @code{buildbot} or @code{buildslave}. This serves to isolate your
861 personal working environment from that of the slave's, and helps to
862 minimize the security threat posed by letting possibly-unknown
863 contributors run arbitrary code on your system. The account should
864 have a minimum of fancy init scripts.
866 @item
867 Install the buildbot code
869 Follow the instructions given earlier (@pxref{Installing the code}).
870 If you use a separate buildslave account, and you didn't install the
871 buildbot code to a shared location, then you will need to install it
872 with @code{--home=~} for each account that needs it.
874 @item
875 Set up the host
877 Make sure the host can actually reach the buildmaster. Usually the
878 buildmaster is running a status webserver on the same machine, so
879 simply point your web browser at it and see if you can get there.
880 Install whatever additional packages or libraries the project's
881 INSTALL document advises. (or not: if your buildslave is supposed to
882 make sure that building without optional libraries still works, then
883 don't install those libraries).
885 Again, these libraries don't necessarily have to be installed to a
886 site-wide shared location, but they must be available to your build
887 process. Accomplishing this is usually very specific to the build
888 process, so installing them to @file{/usr} or @file{/usr/local} is
889 usually the best approach.
891 @item
892 Test the build process
894 Follow the instructions in the INSTALL document, in the buildslave's
895 account. Perform a full CVS (or whatever) checkout, configure, make,
896 run tests, etc. Confirm that the build works without manual fussing.
897 If it doesn't work when you do it by hand, it will be unlikely to work
898 when the buildbot attempts to do it in an automated fashion.
900 @item
901 Choose a base directory
903 This should be somewhere in the buildslave's account, typically named
904 after the project which is being tested. The buildslave will not touch
905 any file outside of this directory. Something like @file{~/Buildbot}
906 or @file{~/Buildslaves/fooproject} is appropriate.
908 @item
909 Get the buildmaster host/port, botname, and password
911 When the buildbot admin configures the buildmaster to accept and use
912 your buildslave, they will provide you with the following pieces of
913 information:
915 @itemize @bullet
916 @item
917 your buildslave's name
918 @item
919 the password assigned to your buildslave
920 @item
921 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
922 @end itemize
924 @item
925 Create the buildslave
927 Now run the 'buildbot' command as follows:
929 @example
930 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
931 @end example
933 This will create the base directory and a collection of files inside,
934 including the @file{buildbot.tac} file that contains all the
935 information you passed to the @code{buildbot} command.
937 @item
938 Fill in the hostinfo files
940 When it first connects, the buildslave will send a few files up to the
941 buildmaster which describe the host that it is running on. These files
942 are presented on the web status display so that developers have more
943 information to reproduce any test failures that are witnessed by the
944 buildbot. There are sample files in the @file{info} subdirectory of
945 the buildbot's base directory. You should edit these to correctly
946 describe you and your host.
948 @file{BASEDIR/info/admin} should contain your name and email address.
949 This is the ``buildslave admin address'', and will be visible from the
950 build status page (so you may wish to munge it a bit if
951 address-harvesting spambots are a concern).
953 @file{BASEDIR/info/host} should be filled with a brief description of
954 the host: OS, version, memory size, CPU speed, versions of relevant
955 libraries installed, and finally the version of the buildbot code
956 which is running the buildslave.
958 If you run many buildslaves, you may want to create a single
959 @file{~buildslave/info} file and share it among all the buildslaves
960 with symlinks.
962 @end enumerate
964 @menu
965 * Buildslave Options::
966 @end menu
968 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
969 @subsection Buildslave Options
971 There are a handful of options you might want to use when creating the
972 buildslave with the @command{buildbot create-slave <options> DIR <params>}
973 command. You can type @command{buildbot create-slave --help} for a summary.
974 To use these, just include them on the @command{buildbot create-slave}
975 command line, like this:
977 @example
978 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
979 @end example
981 @table @code
982 @item --usepty
983 This is a boolean flag that tells the buildslave whether to launch
984 child processes in a PTY (the default) or with regular pipes. The
985 advantage of using a PTY is that ``grandchild'' processes are more
986 likely to be cleaned up if the build is interrupted or times out
987 (since it enables the use of a ``process group'' in which all child
988 processes will be placed). The disadvantages: some forms of Unix have
989 problems with PTYs, some of your unit tests may behave differently
990 when run under a PTY (generally those which check to see if they are
991 being run interactively), and PTYs will merge the stdout and stderr
992 streams into a single output stream (which means the red-vs-black
993 coloring in the logfiles will be lost). If you encounter problems, you
994 can add @code{--usepty=0} to disable the use of PTYs. Note that
995 windows buildslaves never use PTYs.
997 @item --umask
998 This is a string (generally an octal representation of an integer)
999 which will cause the buildslave process' ``umask'' value to be set
1000 shortly after initialization. The ``twistd'' daemonization utility
1001 forces the umask to 077 at startup (which means that all files created
1002 by the buildslave or its child processes will be unreadable by any
1003 user other than the buildslave account). If you want build products to
1004 be readable by other accounts, you can add @code{--umask=022} to tell
1005 the buildslave to fix the umask after twistd clobbers it. If you want
1006 build products to be @emph{writable} by other accounts too, use
1007 @code{--umask=000}, but this is likely to be a security problem.
1009 @item --keepalive
1010 This is a number that indicates how frequently ``keepalive'' messages
1011 should be sent from the buildslave to the buildmaster, expressed in
1012 seconds. The default (600) causes a message to be sent to the
1013 buildmaster at least once every 10 minutes. To set this to a lower
1014 value, use e.g. @code{--keepalive=120}.
1016 If the buildslave is behind a NAT box or stateful firewall, these
1017 messages may help to keep the connection alive: some NAT boxes tend to
1018 forget about a connection if it has not been used in a while. When
1019 this happens, the buildmaster will think that the buildslave has
1020 disappeared, and builds will time out. Meanwhile the buildslave will
1021 not realize than anything is wrong.
1023 @item --maxdelay
1024 This is a number that indicates the maximum amount of time the
1025 buildslave will wait between connection attempts, expressed in
1026 seconds. The default (300) causes the buildslave to wait at most 5
1027 minutes before trying to connect to the buildmaster again.
1029 @item --log-size
1030 This is the size in bytes when to rotate the Twisted log files.
1032 @item --log-count
1033 This is the number of log rotations to keep around. You can either
1034 specify a number or @code{None} (the default) to keep all
1035 @file{twistd.log} files around.
1037 @end table
1040 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
1041 @section Launching the daemons
1043 Both the buildmaster and the buildslave run as daemon programs. To
1044 launch them, pass the working directory to the @code{buildbot}
1045 command:
1047 @example
1048 buildbot start @var{BASEDIR}
1049 @end example
1051 This command will start the daemon and then return, so normally it
1052 will not produce any output. To verify that the programs are indeed
1053 running, look for a pair of files named @file{twistd.log} and
1054 @file{twistd.pid} that should be created in the working directory.
1055 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
1057 When the buildslave connects to the buildmaster, new directories will
1058 start appearing in its base directory. The buildmaster tells the slave
1059 to create a directory for each Builder which will be using that slave.
1060 All build operations are performed within these directories: CVS
1061 checkouts, compiles, and tests.
1063 Once you get everything running, you will want to arrange for the
1064 buildbot daemons to be started at boot time. One way is to use
1065 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
1066 @@reboot syntax is understood by Vixie cron, which is the flavor
1067 usually provided with linux systems. Other unices may have a cron that
1068 doesn't understand @@reboot}:
1070 @example
1071 @@reboot buildbot start @var{BASEDIR}
1072 @end example
1074 When you run @command{crontab} to set this up, remember to do it as
1075 the buildmaster or buildslave account! If you add this to your crontab
1076 when running as your regular account (or worse yet, root), then the
1077 daemon will run as the wrong user, quite possibly as one with more
1078 authority than you intended to provide.
1080 It is important to remember that the environment provided to cron jobs
1081 and init scripts can be quite different that your normal runtime.
1082 There may be fewer environment variables specified, and the PATH may
1083 be shorter than usual. It is a good idea to test out this method of
1084 launching the buildslave by using a cron job with a time in the near
1085 future, with the same command, and then check @file{twistd.log} to
1086 make sure the slave actually started correctly. Common problems here
1087 are for @file{/usr/local} or @file{~/bin} to not be on your
1088 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
1089 Sometimes @code{HOME} is messed up too.
1091 To modify the way the daemons are started (perhaps you want to set
1092 some environment variables first, or perform some cleanup each time),
1093 you can create a file named @file{Makefile.buildbot} in the base
1094 directory. When the @file{buildbot} front-end tool is told to
1095 @command{start} the daemon, and it sees this file (and
1096 @file{/usr/bin/make} exists), it will do @command{make -f
1097 Makefile.buildbot start} instead of its usual action (which involves
1098 running @command{twistd}). When the buildmaster or buildslave is
1099 installed, a @file{Makefile.sample} is created which implements the
1100 same behavior as the the @file{buildbot} tool uses, so if you want to
1101 customize the process, just copy @file{Makefile.sample} to
1102 @file{Makefile.buildbot} and edit it as necessary.
1104 Some distributions may include conveniences to make starting buildbot
1105 at boot time easy.  For instance, with the default buildbot package in
1106 Debian-based distributions, you may only need to modify
1107 @code{/etc/default/buildbot} (see also @code{/etc/init.d/buildbot}, which
1108 reads the configuration in @code{/etc/default/buildbot}).
1110 @node Logfiles, Shutdown, Launching the daemons, Installation
1111 @section Logfiles
1113 @cindex logfiles
1115 While a buildbot daemon runs, it emits text to a logfile, named
1116 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1117 to watch the command output as it runs.
1119 The buildmaster will announce any errors with its configuration file
1120 in the logfile, so it is a good idea to look at the log at startup
1121 time to check for any problems. Most buildmaster activities will cause
1122 lines to be added to the log.
1124 @node Shutdown, Maintenance, Logfiles, Installation
1125 @section Shutdown
1127 To stop a buildmaster or buildslave manually, use:
1129 @example
1130 buildbot stop @var{BASEDIR}
1131 @end example
1133 This simply looks for the @file{twistd.pid} file and kills whatever
1134 process is identified within.
1136 At system shutdown, all processes are sent a @code{SIGKILL}. The
1137 buildmaster and buildslave will respond to this by shutting down
1138 normally.
1140 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1141 config file. Of course, this only works on unix-like systems with
1142 signal support, and won't work on Windows. The following shortcut is
1143 available:
1145 @example
1146 buildbot reconfig @var{BASEDIR}
1147 @end example
1149 When you update the Buildbot code to a new release, you will need to
1150 restart the buildmaster and/or buildslave before it can take advantage
1151 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1152 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1153 use the @code{restart} shortcut, which does both steps for you:
1155 @example
1156 buildbot restart @var{BASEDIR}
1157 @end example
1159 There are certain configuration changes that are not handled cleanly
1160 by @code{buildbot reconfig}. If this occurs, @code{buildbot restart}
1161 is a more robust tool to fully switch over to the new configuration.
1163 @code{buildbot restart} may also be used to start a stopped Buildbot
1164 instance. This behaviour is useful when writing scripts that stop, start
1165 and restart Buildbot.
1168 @node Maintenance, Troubleshooting, Shutdown, Installation
1169 @section Maintenance
1171 It is a good idea to check the buildmaster's status page every once in
1172 a while, to see if your buildslave is still online. Eventually the
1173 buildbot will probably be enhanced to send you email (via the
1174 @file{info/admin} email address) when the slave has been offline for
1175 more than a few hours.
1177 If you find you can no longer provide a buildslave to the project, please
1178 let the project admins know, so they can put out a call for a
1179 replacement.
1181 The Buildbot records status and logs output continually, each time a
1182 build is performed. The status tends to be small, but the build logs
1183 can become quite large. Each build and log are recorded in a separate
1184 file, arranged hierarchically under the buildmaster's base directory.
1185 To prevent these files from growing without bound, you should
1186 periodically delete old build logs. A simple cron job to delete
1187 anything older than, say, two weeks should do the job. The only trick
1188 is to leave the @file{buildbot.tac} and other support files alone, for
1189 which find's @code{-mindepth} argument helps skip everything in the
1190 top directory. You can use something like the following:
1192 @example
1193 @@weekly cd BASEDIR && find . -mindepth 2 i-path './public_html/*' -prune -o -type f -mtime +14 -exec rm @{@} \;
1194 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1195 @end example
1197 @node Troubleshooting,  , Maintenance, Installation
1198 @section Troubleshooting
1200 Here are a few hints on diagnosing common problems.
1202 @menu
1203 * Starting the buildslave::
1204 * Connecting to the buildmaster::
1205 * Forcing Builds::
1206 @end menu
1208 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1209 @subsection Starting the buildslave
1211 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1212 @file{/bin/bash}), and tilde expansion is not always performed in such
1213 commands. You may want to use explicit paths, because the @code{PATH}
1214 is usually quite short and doesn't include anything set by your
1215 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1216 you've installed buildbot (or other python libraries) to an unusual
1217 location, you may need to add a @code{PYTHONPATH} specification (note
1218 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1219 itself). Sometimes it is safer to fully-specify everything:
1221 @example
1222 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1223 @end example
1225 Take the time to get the @@reboot job set up. Otherwise, things will work
1226 fine for a while, but the first power outage or system reboot you have will
1227 stop the buildslave with nothing but the cries of sorrowful developers to
1228 remind you that it has gone away.
1230 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1231 @subsection Connecting to the buildmaster
1233 If the buildslave cannot connect to the buildmaster, the reason should
1234 be described in the @file{twistd.log} logfile. Some common problems
1235 are an incorrect master hostname or port number, or a mistyped bot
1236 name or password. If the buildslave loses the connection to the
1237 master, it is supposed to attempt to reconnect with an
1238 exponentially-increasing backoff. Each attempt (and the time of the
1239 next attempt) will be logged. If you get impatient, just manually stop
1240 and re-start the buildslave.
1242 When the buildmaster is restarted, all slaves will be disconnected,
1243 and will attempt to reconnect as usual. The reconnect time will depend
1244 upon how long the buildmaster is offline (i.e. how far up the
1245 exponential backoff curve the slaves have travelled). Again,
1246 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1247 speed up the process.
1249 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1250 @subsection Forcing Builds
1252 From the buildmaster's main status web page, you can force a build to
1253 be run on your build slave. Figure out which column is for a builder
1254 that runs on your slave, click on that builder's name, and the page
1255 that comes up will have a ``Force Build'' button. Fill in the form,
1256 hit the button, and a moment later you should see your slave's
1257 @file{twistd.log} filling with commands being run. Using @code{pstree}
1258 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1259 run by the buildslave. Note that the same web page should also show
1260 the @file{admin} and @file{host} information files that you configured
1261 earlier.
1263 @node Concepts, Configuration, Installation, Top
1264 @chapter Concepts
1266 This chapter defines some of the basic concepts that the Buildbot
1267 uses. You'll need to understand how the Buildbot sees the world to
1268 configure it properly.
1270 @menu
1271 * Version Control Systems::
1272 * Schedulers::
1273 * BuildSet::
1274 * BuildRequest::
1275 * Builder::
1276 * Users::
1277 * Build Properties::
1278 @end menu
1280 @node Version Control Systems, Schedulers, Concepts, Concepts
1281 @section Version Control Systems
1283 @cindex Version Control
1285 These source trees come from a Version Control System of some kind.
1286 CVS and Subversion are two popular ones, but the Buildbot supports
1287 others. All VC systems have some notion of an upstream
1288 @code{repository} which acts as a server@footnote{except Darcs, but
1289 since the Buildbot never modifies its local source tree we can ignore
1290 the fact that Darcs uses a less centralized model}, from which clients
1291 can obtain source trees according to various parameters. The VC
1292 repository provides source trees of various projects, for different
1293 branches, and from various points in time. The first thing we have to
1294 do is to specify which source tree we want to get.
1296 @menu
1297 * Generalizing VC Systems::
1298 * Source Tree Specifications::
1299 * How Different VC Systems Specify Sources::
1300 * Attributes of Changes::
1301 @end menu
1303 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1304 @subsection Generalizing VC Systems
1306 For the purposes of the Buildbot, we will try to generalize all VC
1307 systems as having repositories that each provide sources for a variety
1308 of projects. Each project is defined as a directory tree with source
1309 files. The individual files may each have revisions, but we ignore
1310 that and treat the project as a whole as having a set of revisions
1311 (CVS is really the only VC system still in widespread use that has
1312 per-file revisions.. everything modern has moved to atomic tree-wide
1313 changesets). Each time someone commits a change to the project, a new
1314 revision becomes available. These revisions can be described by a
1315 tuple with two items: the first is a branch tag, and the second is
1316 some kind of revision stamp or timestamp. Complex projects may have
1317 multiple branch tags, but there is always a default branch. The
1318 timestamp may be an actual timestamp (such as the -D option to CVS),
1319 or it may be a monotonically-increasing transaction number (such as
1320 the change number used by SVN and P4, or the revision number used by
1321 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1322 systems provide more complexity than this: in particular the local
1323 views that P4 and ClearCase can assemble out of various source
1324 directories are more complex than we're prepared to take advantage of
1325 here}. The SHA1 revision ID used by Monotone, Mercurial, and Git is
1326 also a kind of revision stamp, in that it specifies a unique copy of
1327 the source tree, as does a Darcs ``context'' file.
1329 When we aren't intending to make any changes to the sources we check out
1330 (at least not any that need to be committed back upstream), there are two
1331 basic ways to use a VC system:
1333 @itemize @bullet
1334 @item
1335 Retrieve a specific set of source revisions: some tag or key is used
1336 to index this set, which is fixed and cannot be changed by subsequent
1337 developers committing new changes to the tree. Releases are built from
1338 tagged revisions like this, so that they can be rebuilt again later
1339 (probably with controlled modifications).
1340 @item
1341 Retrieve the latest sources along a specific branch: some tag is used
1342 to indicate which branch is to be used, but within that constraint we want
1343 to get the latest revisions.
1344 @end itemize
1346 Build personnel or CM staff typically use the first approach: the
1347 build that results is (ideally) completely specified by the two
1348 parameters given to the VC system: repository and revision tag. This
1349 gives QA and end-users something concrete to point at when reporting
1350 bugs. Release engineers are also reportedly fond of shipping code that
1351 can be traced back to a concise revision tag of some sort.
1353 Developers are more likely to use the second approach: each morning
1354 the developer does an update to pull in the changes committed by the
1355 team over the last day. These builds are not easy to fully specify: it
1356 depends upon exactly when you did a checkout, and upon what local
1357 changes the developer has in their tree. Developers do not normally
1358 tag each build they produce, because there is usually significant
1359 overhead involved in creating these tags. Recreating the trees used by
1360 one of these builds can be a challenge. Some VC systems may provide
1361 implicit tags (like a revision number), while others may allow the use
1362 of timestamps to mean ``the state of the tree at time X'' as opposed
1363 to a tree-state that has been explicitly marked.
1365 The Buildbot is designed to help developers, so it usually works in
1366 terms of @emph{the latest} sources as opposed to specific tagged
1367 revisions. However, it would really prefer to build from reproducible
1368 source trees, so implicit revisions are used whenever possible.
1370 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1371 @subsection Source Tree Specifications
1373 So for the Buildbot's purposes we treat each VC system as a server
1374 which can take a list of specifications as input and produce a source
1375 tree as output. Some of these specifications are static: they are
1376 attributes of the builder and do not change over time. Others are more
1377 variable: each build will have a different value. The repository is
1378 changed over time by a sequence of Changes, each of which represents a
1379 single developer making changes to some set of files. These Changes
1380 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1381 violates this assumption of cumulative Changes, but in most situations
1382 the changes don't occur frequently enough for this to be a significant
1383 problem}.
1385 For normal builds, the Buildbot wants to get well-defined source trees
1386 that contain specific Changes, and exclude other Changes that may have
1387 occurred after the desired ones. We assume that the Changes arrive at
1388 the buildbot (through one of the mechanisms described in @pxref{Change
1389 Sources}) in the same order in which they are committed to the
1390 repository. The Buildbot waits for the tree to become ``stable''
1391 before initiating a build, for two reasons. The first is that
1392 developers frequently make multiple related commits in quick
1393 succession, even when the VC system provides ways to make atomic
1394 transactions involving multiple files at the same time. Running a
1395 build in the middle of these sets of changes would use an inconsistent
1396 set of source files, and is likely to fail (and is certain to be less
1397 useful than a build which uses the full set of changes). The
1398 tree-stable-timer is intended to avoid these useless builds that
1399 include some of the developer's changes but not all. The second reason
1400 is that some VC systems (i.e. CVS) do not provide repository-wide
1401 transaction numbers, so that timestamps are the only way to refer to
1402 a specific repository state. These timestamps may be somewhat
1403 ambiguous, due to processing and notification delays. By waiting until
1404 the tree has been stable for, say, 10 minutes, we can choose a
1405 timestamp from the middle of that period to use for our source
1406 checkout, and then be reasonably sure that any clock-skew errors will
1407 not cause the build to be performed on an inconsistent set of source
1408 files.
1410 The Schedulers always use the tree-stable-timer, with a timeout that
1411 is configured to reflect a reasonable tradeoff between build latency
1412 and change frequency. When the VC system provides coherent
1413 repository-wide revision markers (such as Subversion's revision
1414 numbers, or in fact anything other than CVS's timestamps), the
1415 resulting Build is simply performed against a source tree defined by
1416 that revision marker. When the VC system does not provide this, a
1417 timestamp from the middle of the tree-stable period is used to
1418 generate the source tree@footnote{this @code{checkoutDelay} defaults
1419 to half the tree-stable timer, but it can be overridden with an
1420 argument to the Source Step}.
1422 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1423 @subsection How Different VC Systems Specify Sources
1425 For CVS, the static specifications are @code{repository} and
1426 @code{module}. In addition to those, each build uses a timestamp (or
1427 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1428 (which defaults to HEAD). These parameters collectively specify a set
1429 of sources from which a build may be performed.
1431 @uref{http://subversion.tigris.org, Subversion} combines the
1432 repository, module, and branch into a single @code{Subversion URL}
1433 parameter. Within that scope, source checkouts can be specified by a
1434 numeric @code{revision number} (a repository-wide
1435 monotonically-increasing marker, such that each transaction that
1436 changes the repository is indexed by a different revision number), or
1437 a revision timestamp. When branches are used, the repository and
1438 module form a static @code{baseURL}, while each build has a
1439 @code{revision number} and a @code{branch} (which defaults to a
1440 statically-specified @code{defaultBranch}). The @code{baseURL} and
1441 @code{branch} are simply concatenated together to derive the
1442 @code{svnurl} to use for the checkout.
1444 @uref{http://www.perforce.com/, Perforce} is similar. The server
1445 is specified through a @code{P4PORT} parameter. Module and branch
1446 are specified in a single depot path, and revisions are
1447 depot-wide. When branches are used, the @code{p4base} and
1448 @code{defaultBranch} are concatenated together to produce the depot
1449 path.
1451 @uref{http://wiki.gnuarch.org/, Arch} and
1452 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1453 URL, as well as a @code{version} which is kind of like a branch name.
1454 Arch uses the word @code{archive} to represent the repository. Arch
1455 lets you push changes from one archive to another, removing the strict
1456 centralization required by CVS and SVN. It retains the distinction
1457 between repository and working directory that most other VC systems
1458 use. For complex multi-module directory structures, Arch has a
1459 built-in @code{build config} layer with which the checkout process has
1460 two steps. First, an initial bootstrap checkout is performed to
1461 retrieve a set of build-config files. Second, one of these files is
1462 used to figure out which archives/modules should be used to populate
1463 subdirectories of the initial checkout.
1465 Builders which use Arch and Bazaar therefore have a static archive
1466 @code{url}, and a default ``branch'' (which is a string that specifies
1467 a complete category--branch--version triple). Each build can have its
1468 own branch (the category--branch--version string) to override the
1469 default, as well as a revision number (which is turned into a
1470 --patch-NN suffix when performing the checkout).
1473 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1474 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1475 sort of repository-vs-workspace model as Arch, but the repository data
1476 can either be stored inside the working directory or kept elsewhere
1477 (either on the same machine or on an entirely different machine). For
1478 the purposes of Buildbot (which never commits changes), the repository
1479 is specified with a URL and a revision number.
1481 The most common way to obtain read-only access to a bzr tree is via
1482 HTTP, simply by making the repository visible through a web server
1483 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1484 process has sufficient privileges to access them. Higher performance
1485 can be obtained by running a special Bazaar-specific server. None of
1486 these matter to the buildbot: the repository URL just has to match the
1487 kind of server being used. The @code{repoURL} argument provides the
1488 location of the repository.
1490 Branches are expressed as subdirectories of the main central
1491 repository, which means that if branches are being used, the BZR step
1492 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1493 the @code{repoURL} argument.
1496 @uref{http://darcs.net/, Darcs} doesn't really have the
1497 notion of a single master repository. Nor does it really have
1498 branches. In Darcs, each working directory is also a repository, and
1499 there are operations to push and pull patches from one of these
1500 @code{repositories} to another. For the Buildbot's purposes, all you
1501 need to do is specify the URL of a repository that you want to build
1502 from. The build slave will then pull the latest patches from that
1503 repository and build them. Multiple branches are implemented by using
1504 multiple repositories (possibly living on the same server).
1506 Builders which use Darcs therefore have a static @code{repourl} which
1507 specifies the location of the repository. If branches are being used,
1508 the source Step is instead configured with a @code{baseURL} and a
1509 @code{defaultBranch}, and the two strings are simply concatenated
1510 together to obtain the repository's URL. Each build then has a
1511 specific branch which replaces @code{defaultBranch}, or just uses the
1512 default one. Instead of a revision number, each build can have a
1513 ``context'', which is a string that records all the patches that are
1514 present in a given tree (this is the output of @command{darcs changes
1515 --context}, and is considerably less concise than, e.g. Subversion's
1516 revision number, but the patch-reordering flexibility of Darcs makes
1517 it impossible to provide a shorter useful specification).
1519 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1520 each branch is stored in a separate repository. The @code{repourl},
1521 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1522 same way as with Darcs. The ``revision'', however, is the hash
1523 identifier returned by @command{hg identify}.
1525 @uref{http://git.or.cz/, Git} also follows a decentralized model, and
1526 each repository can have several branches and tags. The source Step is
1527 configured with a static @code{repourl} which specifies the location
1528 of the repository. In addition, an optional @code{branch} parameter
1529 can be specified to check out code from a specific branch instead of
1530 the default ``master'' branch. The ``revision'' is specified as a SHA1
1531 hash as returned by e.g. @command{git rev-parse}. No attempt is made
1532 to ensure that the specified revision is actually a subset of the
1533 specified branch.
1536 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1537 @subsection Attributes of Changes
1539 @heading Who
1541 Each Change has a @code{who} attribute, which specifies which
1542 developer is responsible for the change. This is a string which comes
1543 from a namespace controlled by the VC repository. Frequently this
1544 means it is a username on the host which runs the repository, but not
1545 all VC systems require this (Arch, for example, uses a fully-qualified
1546 @code{Arch ID}, which looks like an email address, as does Darcs).
1547 Each StatusNotifier will map the @code{who} attribute into something
1548 appropriate for their particular means of communication: an email
1549 address, an IRC handle, etc.
1551 @heading Files
1553 It also has a list of @code{files}, which are just the tree-relative
1554 filenames of any files that were added, deleted, or modified for this
1555 Change. These filenames are used by the @code{isFileImportant}
1556 function (in the Scheduler) to decide whether it is worth triggering a
1557 new build or not, e.g. the function could use
1558 @code{filename.endswith(".c")} to only run a build if a C file were
1559 checked in. Certain BuildSteps can also use the list of changed files
1560 to run a more targeted series of tests, e.g. the
1561 @code{python_twisted.Trial} step can run just the unit tests that
1562 provide coverage for the modified .py files instead of running the
1563 full test suite.
1565 @heading Comments
1567 The Change also has a @code{comments} attribute, which is a string
1568 containing any checkin comments.
1570 @heading Revision
1572 Each Change can have a @code{revision} attribute, which describes how
1573 to get a tree with a specific state: a tree which includes this Change
1574 (and all that came before it) but none that come after it. If this
1575 information is unavailable, the @code{.revision} attribute will be
1576 @code{None}. These revisions are provided by the ChangeSource, and
1577 consumed by the @code{computeSourceRevision} method in the appropriate
1578 @code{step.Source} class.
1580 @table @samp
1581 @item CVS
1582 @code{revision} is an int, seconds since the epoch
1583 @item SVN
1584 @code{revision} is an int, a transation number (r%d)
1585 @item Darcs
1586 @code{revision} is a large string, the output of @code{darcs changes --context}
1587 @item Mercurial
1588 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1589 @item Arch/Bazaar
1590 @code{revision} is the full revision ID (ending in --patch-%d)
1591 @item P4
1592 @code{revision} is an int, the transaction number
1593 @item Git
1594 @code{revision} is a short string (a SHA1 hash), the output of e.g.
1595 @code{git rev-parse}
1596 @end table
1598 @heading Branches
1600 The Change might also have a @code{branch} attribute. This indicates
1601 that all of the Change's files are in the same named branch. The
1602 Schedulers get to decide whether the branch should be built or not.
1604 For VC systems like CVS, Arch, Monotone, and Git, the @code{branch}
1605 name is unrelated to the filename. (that is, the branch name and the
1606 filename inhabit unrelated namespaces). For SVN, branches are
1607 expressed as subdirectories of the repository, so the file's
1608 ``svnurl'' is a combination of some base URL, the branch name, and the
1609 filename within the branch. (In a sense, the branch name and the
1610 filename inhabit the same namespace). Darcs branches are
1611 subdirectories of a base URL just like SVN. Mercurial branches are the
1612 same as Darcs.
1614 @table @samp
1615 @item CVS
1616 branch='warner-newfeature', files=['src/foo.c']
1617 @item SVN
1618 branch='branches/warner-newfeature', files=['src/foo.c']
1619 @item Darcs
1620 branch='warner-newfeature', files=['src/foo.c']
1621 @item Mercurial
1622 branch='warner-newfeature', files=['src/foo.c']
1623 @item Arch/Bazaar
1624 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1625 @item Git
1626 branch='warner-newfeature', files=['src/foo.c']
1627 @end table
1629 @heading Links
1631 @c TODO: who is using 'links'? how is it being used?
1633 Finally, the Change might have a @code{links} list, which is intended
1634 to provide a list of URLs to a @emph{viewcvs}-style web page that
1635 provides more detail for this Change, perhaps including the full file
1636 diffs.
1639 @node Schedulers, BuildSet, Version Control Systems, Concepts
1640 @section Schedulers
1642 @cindex Scheduler
1644 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1645 gets a copy of every incoming Change. The Schedulers are responsible
1646 for deciding when Builds should be run. Some Buildbot installations
1647 might have a single Scheduler, while others may have several, each for
1648 a different purpose.
1650 For example, a ``quick'' scheduler might exist to give immediate
1651 feedback to developers, hoping to catch obvious problems in the code
1652 that can be detected quickly. These typically do not run the full test
1653 suite, nor do they run on a wide variety of platforms. They also
1654 usually do a VC update rather than performing a brand-new checkout
1655 each time. You could have a ``quick'' scheduler which used a 30 second
1656 timeout, and feeds a single ``quick'' Builder that uses a VC
1657 @code{mode='update'} setting.
1659 A separate ``full'' scheduler would run more comprehensive tests a
1660 little while later, to catch more subtle problems. This scheduler
1661 would have a longer tree-stable-timer, maybe 30 minutes, and would
1662 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1663 @code{'clobber'}, or @code{'export'}).
1665 The @code{tree-stable-timer} and @code{isFileImportant} decisions are
1666 made by the Scheduler. Dependencies are also implemented here.
1667 Periodic builds (those which are run every N seconds rather than after
1668 new Changes arrive) are triggered by a special @code{Periodic}
1669 Scheduler subclass. The default Scheduler class can also be told to
1670 watch for specific branches, ignoring Changes on other branches. This
1671 may be useful if you have a trunk and a few release branches which
1672 should be tracked, but when you don't want to have the Buildbot pay
1673 attention to several dozen private user branches.
1675 When the setup has multiple sources of Changes the @code{category}
1676 can be used for @code{Scheduler} objects to filter out a subset
1677 of the Changes.  Note that not all change sources can attach a category.
1679 Some Schedulers may trigger builds for other reasons, other than
1680 recent Changes. For example, a Scheduler subclass could connect to a
1681 remote buildmaster and watch for builds of a library to succeed before
1682 triggering a local build that uses that library.
1684 Each Scheduler creates and submits @code{BuildSet} objects to the
1685 @code{BuildMaster}, which is then responsible for making sure the
1686 individual @code{BuildRequests} are delivered to the target
1687 @code{Builders}.
1689 @code{Scheduler} instances are activated by placing them in the
1690 @code{c['schedulers']} list in the buildmaster config file. Each
1691 Scheduler has a unique name.
1694 @node BuildSet, BuildRequest, Schedulers, Concepts
1695 @section BuildSet
1697 @cindex BuildSet
1699 A @code{BuildSet} is the name given to a set of Builds that all
1700 compile/test the same version of the tree on multiple Builders. In
1701 general, all these component Builds will perform the same sequence of
1702 Steps, using the same source code, but on different platforms or
1703 against a different set of libraries.
1705 The @code{BuildSet} is tracked as a single unit, which fails if any of
1706 the component Builds have failed, and therefore can succeed only if
1707 @emph{all} of the component Builds have succeeded. There are two kinds
1708 of status notification messages that can be emitted for a BuildSet:
1709 the @code{firstFailure} type (which fires as soon as we know the
1710 BuildSet will fail), and the @code{Finished} type (which fires once
1711 the BuildSet has completely finished, regardless of whether the
1712 overall set passed or failed).
1714 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1715 (branch, revision, changes, patch), some of which may be None, and a
1716 list of Builders on which it is to be run. They are then given to the
1717 BuildMaster, which is responsible for creating a separate
1718 @code{BuildRequest} for each Builder.
1720 There are a couple of different likely values for the
1721 @code{SourceStamp}:
1723 @table @code
1724 @item (revision=None, changes=[CHANGES], patch=None)
1725 This is a @code{SourceStamp} used when a series of Changes have
1726 triggered a build. The VC step will attempt to check out a tree that
1727 contains CHANGES (and any changes that occurred before CHANGES, but
1728 not any that occurred after them).
1730 @item (revision=None, changes=None, patch=None)
1731 This builds the most recent code on the default branch. This is the
1732 sort of @code{SourceStamp} that would be used on a Build that was
1733 triggered by a user request, or a Periodic scheduler. It is also
1734 possible to configure the VC Source Step to always check out the
1735 latest sources rather than paying attention to the Changes in the
1736 SourceStamp, which will result in same behavior as this.
1738 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1739 This builds the most recent code on the given BRANCH. Again, this is
1740 generally triggered by a user request or Periodic build.
1742 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1743 This checks out the tree at the given revision REV, then applies a
1744 patch (using @code{patch -pLEVEL <DIFF}). The @ref{try} feature uses
1745 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1746 step is bypassed.
1748 @end table
1750 The buildmaster is responsible for turning the @code{BuildSet} into a
1751 set of @code{BuildRequest} objects and queueing them on the
1752 appropriate Builders.
1755 @node BuildRequest, Builder, BuildSet, Concepts
1756 @section BuildRequest
1758 @cindex BuildRequest
1760 A @code{BuildRequest} is a request to build a specific set of sources
1761 on a single specific @code{Builder}. Each @code{Builder} runs the
1762 @code{BuildRequest} as soon as it can (i.e. when an associated
1763 buildslave becomes free). @code{BuildRequest}s are prioritized from
1764 oldest to newest, so when a buildslave becomes free, the
1765 @code{Builder} with the oldest @code{BuildRequest} is run.
1767 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1768 The actual process of running the build (the series of Steps that will
1769 be executed) is implemented by the @code{Build} object. In this future
1770 this might be changed, to have the @code{Build} define @emph{what}
1771 gets built, and a separate @code{BuildProcess} (provided by the
1772 Builder) to define @emph{how} it gets built.
1774 @code{BuildRequest} is created with optional @code{Properties}.  One
1775 of these, @code{owner}, is collected by the resultant @code{Build} and
1776 added to the set of @emph{interested users} to which status
1777 notifications will be sent, depending on the configuration for each
1778 status object.
1780 The @code{BuildRequest} may be mergeable with other compatible
1781 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1782 will generally be mergeable. Builds that are triggered by user
1783 requests are generally not, unless they are multiple requests to build
1784 the @emph{latest sources} of the same branch.
1786 @node Builder, Users, BuildRequest, Concepts
1787 @section Builder
1789 @cindex Builder
1791 The @code{Builder} is a long-lived object which controls all Builds of
1792 a given type. Each one is created when the config file is first
1793 parsed, and lives forever (or rather until it is removed from the
1794 config file). It mediates the connections to the buildslaves that do
1795 all the work, and is responsible for creating the @code{Build} objects
1796 that decide @emph{how} a build is performed (i.e., which steps are
1797 executed in what order).
1799 Each @code{Builder} gets a unique name, and the path name of a
1800 directory where it gets to do all its work (there is a
1801 buildmaster-side directory for keeping status information, as well as
1802 a buildslave-side directory where the actual checkout/compile/test
1803 commands are executed). It also gets a @code{BuildFactory}, which is
1804 responsible for creating new @code{Build} instances: because the
1805 @code{Build} instance is what actually performs each build, choosing
1806 the @code{BuildFactory} is the way to specify what happens each time a
1807 build is done.
1809 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1810 A @code{Builder} which is used to perform OS-X builds (as opposed to
1811 Linux or Solaris builds) should naturally be associated with an
1812 OS-X-based buildslave.
1814 A @code{Builder} may be given a set of environment variables to be used
1815 in its @pxref{ShellCommand}s. These variables will override anything in the
1816 buildslave's environment. Variables passed directly to a ShellCommand will
1817 override variables of the same name passed to the Builder.
1819 For example, if you a pool of identical slaves it is often easier to manage
1820 variables like PATH from Buildbot rather than manually editing it inside of
1821 the slaves' environment.
1823 @example
1824 f = factory.BuildFactory
1825 f.addStep(ShellCommand(
1826               command=['bash', './configure']))
1827 f.addStep(Compile())
1829 c['builders'] = [
1830   @{'name': 'test', 'slavenames': ['slave1', 'slave2', 'slave3', 'slave4',
1831                                    'slave5', 'slave6'],
1832     'builddir': 'test', 'factory': f',
1833     'env': @{'PATH': '/opt/local/bin:/opt/app/bin:/usr/local/bin:/usr/bin'@}@}
1835 @end example
1837 @node Users, Build Properties, Builder, Concepts
1838 @section Users
1840 @cindex Users
1842 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1843 the world consists of a set of developers, each of whom can be
1844 described by a couple of simple attributes. These developers make
1845 changes to the source code, causing builds which may succeed or fail.
1847 Each developer is primarily known through the source control system. Each
1848 Change object that arrives is tagged with a @code{who} field that
1849 typically gives the account name (on the repository machine) of the user
1850 responsible for that change. This string is the primary key by which the
1851 User is known, and is displayed on the HTML status pages and in each Build's
1852 ``blamelist''.
1854 To do more with the User than just refer to them, this username needs to
1855 be mapped into an address of some sort. The responsibility for this mapping
1856 is left up to the status module which needs the address. The core code knows
1857 nothing about email addresses or IRC nicknames, just user names.
1859 @menu
1860 * Doing Things With Users::
1861 * Email Addresses::
1862 * IRC Nicknames::
1863 * Live Status Clients::
1864 @end menu
1866 @node Doing Things With Users, Email Addresses, Users, Users
1867 @subsection Doing Things With Users
1869 Each Change has a single User who is responsible for that Change. Most
1870 Builds have a set of Changes: the Build represents the first time these
1871 Changes have been built and tested by the Buildbot. The build has a
1872 ``blamelist'' that consists of a simple union of the Users responsible
1873 for all the Build's Changes.
1875 The Build provides (through the IBuildStatus interface) a list of Users
1876 who are ``involved'' in the build. For now this is equal to the
1877 blamelist, but in the future it will be expanded to include a ``build
1878 sheriff'' (a person who is ``on duty'' at that time and responsible for
1879 watching over all builds that occur during their shift), as well as
1880 per-module owners who simply want to keep watch over their domain (chosen by
1881 subdirectory or a regexp matched against the filenames pulled out of the
1882 Changes). The Involved Users are those who probably have an interest in the
1883 results of any given build.
1885 In the future, Buildbot will acquire the concept of ``Problems'',
1886 which last longer than builds and have beginnings and ends. For example, a
1887 test case which passed in one build and then failed in the next is a
1888 Problem. The Problem lasts until the test case starts passing again, at
1889 which point the Problem is said to be ``resolved''.
1891 If there appears to be a code change that went into the tree at the
1892 same time as the test started failing, that Change is marked as being
1893 resposible for the Problem, and the user who made the change is added
1894 to the Problem's ``Guilty'' list. In addition to this user, there may
1895 be others who share responsibility for the Problem (module owners,
1896 sponsoring developers). In addition to the Responsible Users, there
1897 may be a set of Interested Users, who take an interest in the fate of
1898 the Problem.
1900 Problems therefore have sets of Users who may want to be kept aware of
1901 the condition of the problem as it changes over time. If configured, the
1902 Buildbot can pester everyone on the Responsible list with increasing
1903 harshness until the problem is resolved, with the most harshness reserved
1904 for the Guilty parties themselves. The Interested Users may merely be told
1905 when the problem starts and stops, as they are not actually responsible for
1906 fixing anything.
1908 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1909 @subsection Email Addresses
1911 The @code{buildbot.status.mail.MailNotifier} class
1912 (@pxref{MailNotifier}) provides a status target which can send email
1913 about the results of each build. It accepts a static list of email
1914 addresses to which each message should be delivered, but it can also
1915 be configured to send mail to the Build's Interested Users. To do
1916 this, it needs a way to convert User names into email addresses.
1918 For many VC systems, the User Name is actually an account name on the
1919 system which hosts the repository. As such, turning the name into an
1920 email address is a simple matter of appending
1921 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1922 (for example the preferred email address may be at ``project.org''
1923 despite the repository host being named ``cvs.project.org''), and some
1924 VC systems have full separation between the concept of a user and that
1925 of an account on the repository host (like Perforce). Some systems
1926 (like Arch) put a full contact email address in every change.
1928 To convert these names to addresses, the MailNotifier uses an EmailLookup
1929 object. This provides a .getAddress method which accepts a name and
1930 (eventually) returns an address. The default @code{MailNotifier}
1931 module provides an EmailLookup which simply appends a static string,
1932 configurable when the notifier is created. To create more complex behaviors
1933 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1934 determine a preferred address for the developer), provide a different object
1935 as the @code{lookup} argument.
1937 In the future, when the Problem mechanism has been set up, the Buildbot
1938 will need to send mail to arbitrary Users. It will do this by locating a
1939 MailNotifier-like object among all the buildmaster's status targets, and
1940 asking it to send messages to various Users. This means the User-to-address
1941 mapping only has to be set up once, in your MailNotifier, and every email
1942 message the buildbot emits will take advantage of it.
1944 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1945 @subsection IRC Nicknames
1947 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1948 provides a status target which can announce the results of each build. It
1949 also provides an interactive interface by responding to online queries
1950 posted in the channel or sent as private messages.
1952 In the future, the buildbot can be configured map User names to IRC
1953 nicknames, to watch for the recent presence of these nicknames, and to
1954 deliver build status messages to the interested parties. Like
1955 @code{MailNotifier} does for email addresses, the @code{IRC} object
1956 will have an @code{IRCLookup} which is responsible for nicknames. The
1957 mapping can be set up statically, or it can be updated by online users
1958 themselves (by claiming a username with some kind of ``buildbot: i am
1959 user warner'' commands).
1961 Once the mapping is established, the rest of the buildbot can ask the
1962 @code{IRC} object to send messages to various users. It can report on
1963 the likelihood that the user saw the given message (based upon how long the
1964 user has been inactive on the channel), which might prompt the Problem
1965 Hassler logic to send them an email message instead.
1967 @node Live Status Clients,  , IRC Nicknames, Users
1968 @subsection Live Status Clients
1970 The Buildbot also offers a PB-based status client interface which can
1971 display real-time build status in a GUI panel on the developer's desktop.
1972 This interface is normally anonymous, but it could be configured to let the
1973 buildmaster know @emph{which} developer is using the status client. The
1974 status client could then be used as a message-delivery service, providing an
1975 alternative way to deliver low-latency high-interruption messages to the
1976 developer (like ``hey, you broke the build'').
1978 @node Build Properties,  , Users, Concepts
1979 @section Build Properties
1980 @cindex Properties
1982 Each build has a set of ``Build Properties'', which can be used by its
1983 BuildStep to modify their actions.  These properties, in the form of
1984 key-value pairs, provide a general framework for dynamically altering
1985 the behavior of a build based on its circumstances.
1987 Properties come from a number of places:
1988 @itemize
1989 @item global configuration --
1990 These properties apply to all builds.
1991 @item schedulers --
1992 A scheduler can specify properties available to all the builds it
1993 starts.
1994 @item buildslaves --
1995 A buildslave can pass properties on to the builds it performs.
1996 @item builds --
1997 A build automatically sets a number of properties on itself.
1998 @item steps --
1999 Steps of a build can set properties that are available to subsequent
2000 steps.  In particular, source steps set a number of properties.
2001 @end itemize
2003 Properties are very flexible, and can be used to implement all manner
2004 of functionality.  Here are some examples:
2006 Most Source steps record the revision that they checked out in
2007 the @code{got_revision} property.  A later step could use this
2008 property to specify the name of a fully-built tarball, dropped in an
2009 easily-acessible directory for later testing.
2011 Some projects want to perform nightly builds as well as in response
2012 to committed changes.  Such a project would run two schedulers,
2013 both pointing to the same set of builders, but could provide an
2014 @code{is_nightly} property so that steps can distinguish the nightly
2015 builds, perhaps to run more resource-intensive tests.
2017 Some projects have different build processes on different systems.
2018 Rather than create a build factory for each slave, the steps can use
2019 buildslave properties to identify the unique aspects of each slave
2020 and adapt the build process dynamically.
2022 @node Configuration, Getting Source Code Changes, Concepts, Top
2023 @chapter Configuration
2025 @cindex Configuration
2027 The buildbot's behavior is defined by the ``config file'', which
2028 normally lives in the @file{master.cfg} file in the buildmaster's base
2029 directory (but this can be changed with an option to the
2030 @code{buildbot create-master} command). This file completely specifies
2031 which Builders are to be run, which slaves they should use, how
2032 Changes should be tracked, and where the status information is to be
2033 sent. The buildmaster's @file{buildbot.tac} file names the base
2034 directory; everything else comes from the config file.
2036 A sample config file was installed for you when you created the
2037 buildmaster, but you will need to edit it before your buildbot will do
2038 anything useful.
2040 This chapter gives an overview of the format of this file and the
2041 various sections in it. You will need to read the later chapters to
2042 understand how to fill in each section properly.
2044 @menu
2045 * Config File Format::
2046 * Loading the Config File::
2047 * Testing the Config File::
2048 * Defining the Project::
2049 * Change Sources and Schedulers::
2050 * Merging BuildRequests::
2051 * Setting the slaveport::
2052 * Buildslave Specifiers::
2053 * On-Demand ("Latent") Buildslaves::
2054 * Defining Global Properties::
2055 * Defining Builders::
2056 * Defining Status Targets::
2057 * Debug options::
2058 @end menu
2060 @node Config File Format, Loading the Config File, Configuration, Configuration
2061 @section Config File Format
2063 The config file is, fundamentally, just a piece of Python code which
2064 defines a dictionary named @code{BuildmasterConfig}, with a number of
2065 keys that are treated specially. You don't need to know Python to do
2066 basic configuration, though, you can just copy the syntax of the
2067 sample file. If you @emph{are} comfortable writing Python code,
2068 however, you can use all the power of a full programming language to
2069 achieve more complicated configurations.
2071 The @code{BuildmasterConfig} name is the only one which matters: all
2072 other names defined during the execution of the file are discarded.
2073 When parsing the config file, the Buildmaster generally compares the
2074 old configuration with the new one and performs the minimum set of
2075 actions necessary to bring the buildbot up to date: Builders which are
2076 not changed are left untouched, and Builders which are modified get to
2077 keep their old event history.
2079 Basic Python syntax: comments start with a hash character (``#''),
2080 tuples are defined with @code{(parenthesis, pairs)}, arrays are
2081 defined with @code{[square, brackets]}, tuples and arrays are mostly
2082 interchangeable. Dictionaries (data structures which map ``keys'' to
2083 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
2084 'key2': 'value2'@} }. Function calls (and object instantiation) can use
2085 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
2087 The config file starts with a series of @code{import} statements,
2088 which make various kinds of Steps and Status targets available for
2089 later use. The main @code{BuildmasterConfig} dictionary is created,
2090 then it is populated with a variety of keys. These keys are broken
2091 roughly into the following sections, each of which is documented in
2092 the rest of this chapter:
2094 @itemize @bullet
2095 @item
2096 Project Definitions
2097 @item
2098 Change Sources / Schedulers
2099 @item
2100 Slaveport
2101 @item
2102 Buildslave Configuration
2103 @item
2104 Builders / Interlocks
2105 @item
2106 Status Targets
2107 @item
2108 Debug options
2109 @end itemize
2111 The config file can use a few names which are placed into its namespace:
2113 @table @code
2114 @item basedir
2115 the base directory for the buildmaster. This string has not been
2116 expanded, so it may start with a tilde. It needs to be expanded before
2117 use. The config file is located in
2118 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
2120 @end table
2123 @node Loading the Config File, Testing the Config File, Config File Format, Configuration
2124 @section Loading the Config File
2126 The config file is only read at specific points in time. It is first
2127 read when the buildmaster is launched. Once it is running, there are
2128 various ways to ask it to reload the config file. If you are on the
2129 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
2130 it: the @command{buildbot} tool has a shortcut for this:
2132 @example
2133 buildbot reconfig @var{BASEDIR}
2134 @end example
2136 This command will show you all of the lines from @file{twistd.log}
2137 that relate to the reconfiguration. If there are any problems during
2138 the config-file reload, they will be displayed in these lines.
2140 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
2141 ``Reload .cfg'' button which will also trigger a reload. In the
2142 future, there will be other ways to accomplish this step (probably a
2143 password-protected button on the web page, as well as a privileged IRC
2144 command).
2146 When reloading the config file, the buildmaster will endeavor to
2147 change as little as possible about the running system. For example,
2148 although old status targets may be shut down and new ones started up,
2149 any status targets that were not changed since the last time the
2150 config file was read will be left running and untouched. Likewise any
2151 Builders which have not been changed will be left running. If a
2152 Builder is modified (say, the build process is changed) while a Build
2153 is currently running, that Build will keep running with the old
2154 process until it completes. Any previously queued Builds (or Builds
2155 which get queued after the reconfig) will use the new process.
2157 @node Testing the Config File, Defining the Project, Loading the Config File, Configuration
2158 @section Testing the Config File
2160 To verify that the config file is well-formed and contains no
2161 deprecated or invalid elements, use the ``checkconfig'' command:
2163 @example
2164 % buildbot checkconfig master.cfg
2165 Config file is good!
2166 @end example
2168 If the config file has deprecated features (perhaps because you've
2169 upgraded the buildmaster and need to update the config file to match),
2170 they will be announced by checkconfig. In this case, the config file
2171 will work, but you should really remove the deprecated items and use
2172 the recommended replacements instead:
2174 @example
2175 % buildbot checkconfig master.cfg
2176 /usr/lib/python2.4/site-packages/buildbot/master.py:559: DeprecationWarning: c['sources'] is
2177 deprecated as of 0.7.6 and will be removed by 0.8.0 . Please use c['change_source'] instead.
2178   warnings.warn(m, DeprecationWarning)
2179 Config file is good!
2180 @end example
2182 If the config file is simply broken, that will be caught too:
2184 @example
2185 % buildbot checkconfig master.cfg
2186 Traceback (most recent call last):
2187   File "/usr/lib/python2.4/site-packages/buildbot/scripts/runner.py", line 834, in doCheckConfig
2188     ConfigLoader(configFile)
2189   File "/usr/lib/python2.4/site-packages/buildbot/scripts/checkconfig.py", line 31, in __init__
2190     self.loadConfig(configFile)
2191   File "/usr/lib/python2.4/site-packages/buildbot/master.py", line 480, in loadConfig
2192     exec f in localDict
2193   File "/home/warner/BuildBot/master/foolscap/master.cfg", line 90, in ?
2194     c[bogus] = "stuff"
2195 NameError: name 'bogus' is not defined
2196 @end example
2199 @node Defining the Project, Change Sources and Schedulers, Testing the Config File, Configuration
2200 @section Defining the Project
2202 There are a couple of basic settings that you use to tell the buildbot
2203 what project it is working on. This information is used by status
2204 reporters to let users find out more about the codebase being
2205 exercised by this particular Buildbot installation.
2207 @example
2208 c['projectName'] = "Buildbot"
2209 c['projectURL'] = "http://buildbot.sourceforge.net/"
2210 c['buildbotURL'] = "http://localhost:8010/"
2211 @end example
2213 @bcindex c['projectName']
2214 @code{projectName} is a short string will be used to describe the
2215 project that this buildbot is working on. For example, it is used as
2216 the title of the waterfall HTML page.
2218 @bcindex c['projectURL']
2219 @code{projectURL} is a string that gives a URL for the project as a
2220 whole. HTML status displays will show @code{projectName} as a link to
2221 @code{projectURL}, to provide a link from buildbot HTML pages to your
2222 project's home page.
2224 @bcindex c['buildbotURL']
2225 The @code{buildbotURL} string should point to the location where the
2226 buildbot's internal web server (usually the @code{html.Waterfall}
2227 page) is visible. This typically uses the port number set when you
2228 create the @code{Waterfall} object: the buildbot needs your help to
2229 figure out a suitable externally-visible host name.
2231 When status notices are sent to users (either by email or over IRC),
2232 @code{buildbotURL} will be used to create a URL to the specific build
2233 or problem that they are being notified about. It will also be made
2234 available to queriers (over IRC) who want to find out where to get
2235 more information about this buildbot.
2237 @bcindex c['logCompressionLimit']
2238 The @code{logCompressionLimit} enables bz2-compression of build logs on
2239 disk for logs that are bigger than the given size, or disables that
2240 completely if given @code{False}. The default value is 4k, which should
2241 be a reasonable default on most file systems. This setting has no impact
2242 on status plugins, and merely affects the required disk space on the
2243 master for build logs.
2246 @node Change Sources and Schedulers, Merging BuildRequests, Defining the Project, Configuration
2247 @section Change Sources and Schedulers
2249 @bcindex c['sources']
2250 @bcindex c['change_source']
2252 The @code{c['change_source']} key is the ChangeSource
2253 instance@footnote{To be precise, it is an object or a list of objects
2254 which all implement the @code{buildbot.interfaces.IChangeSource}
2255 Interface. It is unusual to have multiple ChangeSources, so this key
2256 accepts either a single ChangeSource or a sequence of them.} that
2257 defines how the buildmaster learns about source code changes. More
2258 information about what goes here is available in @xref{Getting Source
2259 Code Changes}.
2261 @example
2262 from buildbot.changes.pb import PBChangeSource
2263 c['change_source'] = PBChangeSource()
2264 @end example
2265 @bcindex c['schedulers']
2267 (note: in buildbot-0.7.5 and earlier, this key was named
2268 @code{c['sources']}, and required a list. @code{c['sources']} is
2269 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2270 future release).
2272 @code{c['schedulers']} is a list of Scheduler instances, each
2273 of which causes builds to be started on a particular set of
2274 Builders. The two basic Scheduler classes you are likely to start
2275 with are @code{Scheduler} and @code{Periodic}, but you can write a
2276 customized subclass to implement more complicated build scheduling.
2278 Scheduler arguments
2279 should always be specified by name (as keyword arguments), to allow
2280 for future expansion:
2282 @example
2283 sched = Scheduler(name="quick", builderNames=['lin', 'win'])
2284 @end example
2286 All schedulers have several arguments in common:
2288 @table @code
2289 @item name
2291 Each Scheduler must have a unique name. This is used in status
2292 displays, and is also available in the build property @code{scheduler}.
2294 @item builderNames
2296 This is the set of builders which this scheduler should trigger, specified
2297 as a list of names (strings).
2299 @item properties
2300 @cindex Properties
2302 This is a dictionary specifying properties that will be transmitted
2303 to all builds started by this scheduler.
2305 @end table
2307 Here is a brief catalog of the available Scheduler types. All these
2308 Schedulers are classes in @code{buildbot.scheduler}, and the
2309 docstrings there are the best source of documentation on the arguments
2310 taken by each one.
2312 @menu
2313 * Scheduler Scheduler::
2314 * AnyBranchScheduler::
2315 * Dependent Scheduler::
2316 * Periodic Scheduler::
2317 * Nightly Scheduler::
2318 * Try Schedulers::
2319 * Triggerable Scheduler::
2320 @end menu
2322 @node Scheduler Scheduler, AnyBranchScheduler, Change Sources and Schedulers, Change Sources and Schedulers
2323 @subsection Scheduler Scheduler
2324 @slindex buildbot.scheduler.Scheduler
2326 This is the original and still most popular Scheduler class. It follows
2327 exactly one branch, and starts a configurable tree-stable-timer after
2328 each change on that branch. When the timer expires, it starts a build
2329 on some set of Builders. The Scheduler accepts a @code{fileIsImportant}
2330 function which can be used to ignore some Changes if they do not
2331 affect any ``important'' files.
2333 The arguments to this scheduler are:
2335 @table @code
2336 @item name
2338 @item builderNames
2340 @item properties
2342 @item branch
2343 This Scheduler will pay attention to a single branch, ignoring Changes
2344 that occur on other branches. Setting @code{branch} equal to the
2345 special value of @code{None} means it should only pay attention to
2346 the default branch. Note that @code{None} is a keyword, not a string,
2347 so you want to use @code{None} and not @code{"None"}.
2349 @item treeStableTimer
2350 The Scheduler will wait for this many seconds before starting the
2351 build. If new changes are made during this interval, the timer will be
2352 restarted, so really the build will be started after a change and then
2353 after this many seconds of inactivity.
2355 @item fileIsImportant
2356 A callable which takes one argument, a Change instance, and returns
2357 @code{True} if the change is worth building, and @code{False} if
2358 it is not.  Unimportant Changes are accumulated until the build is
2359 triggered by an important change.  The default value of None means
2360 that all Changes are important.
2362 @item categories
2363 A list of categories of changes that this scheduler will respond to.  If this
2364 is specified, then any non-matching changes are ignored.
2366 @end table
2368 Example:
2370 @example
2371 from buildbot import scheduler
2372 quick = scheduler.Scheduler(name="quick",
2373                     branch=None,
2374                     treeStableTimer=60,
2375                     builderNames=["quick-linux", "quick-netbsd"])
2376 full = scheduler.Scheduler(name="full",
2377                     branch=None,
2378                     treeStableTimer=5*60,
2379                     builderNames=["full-linux", "full-netbsd", "full-OSX"])
2380 c['schedulers'] = [quick, full]
2381 @end example
2383 In this example, the two ``quick'' builders are triggered 60 seconds
2384 after the tree has been changed. The ``full'' builds do not run quite
2385 so quickly (they wait 5 minutes), so hopefully if the quick builds
2386 fail due to a missing file or really simple typo, the developer can
2387 discover and fix the problem before the full builds are started. Both
2388 Schedulers only pay attention to the default branch: any changes
2389 on other branches are ignored by these Schedulers. Each Scheduler
2390 triggers a different set of Builders, referenced by name.
2392 @node AnyBranchScheduler, Dependent Scheduler, Scheduler Scheduler, Change Sources and Schedulers
2393 @subsection AnyBranchScheduler
2394 @slindex buildbot.scheduler.AnyBranchScheduler
2396 This scheduler uses a tree-stable-timer like the default one, but
2397 follows multiple branches at once. Each branch gets a separate timer.
2399 The arguments to this scheduler are:
2401 @table @code
2402 @item name
2404 @item builderNames
2406 @item properties
2408 @item branches
2409 This Scheduler will pay attention to any number of branches, ignoring
2410 Changes that occur on other branches. Branches are specified just as
2411 for the @code{Scheduler} class.
2413 @item treeStableTimer
2414 The Scheduler will wait for this many seconds before starting the
2415 build. If new changes are made during this interval, the timer will be
2416 restarted, so really the build will be started after a change and then
2417 after this many seconds of inactivity.
2419 @item fileIsImportant
2420 A callable which takes one argument, a Change instance, and returns
2421 @code{True} if the change is worth building, and @code{False} if
2422 it is not.  Unimportant Changes are accumulated until the build is
2423 triggered by an important change.  The default value of None means
2424 that all Changes are important.
2425 @end table
2427 @node Dependent Scheduler, Periodic Scheduler, AnyBranchScheduler, Change Sources and Schedulers
2428 @subsection Dependent Scheduler
2429 @cindex Dependent
2430 @cindex Dependencies
2431 @slindex buildbot.scheduler.Dependent
2433 It is common to wind up with one kind of build which should only be
2434 performed if the same source code was successfully handled by some
2435 other kind of build first. An example might be a packaging step: you
2436 might only want to produce .deb or RPM packages from a tree that was
2437 known to compile successfully and pass all unit tests. You could put
2438 the packaging step in the same Build as the compile and testing steps,
2439 but there might be other reasons to not do this (in particular you
2440 might have several Builders worth of compiles/tests, but only wish to
2441 do the packaging once). Another example is if you want to skip the
2442 ``full'' builds after a failing ``quick'' build of the same source
2443 code. Or, if one Build creates a product (like a compiled library)
2444 that is used by some other Builder, you'd want to make sure the
2445 consuming Build is run @emph{after} the producing one.
2447 You can use ``Dependencies'' to express this relationship
2448 to the Buildbot. There is a special kind of Scheduler named
2449 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2450 for builds to complete successfully (on all of its Builders). Each time
2451 that happens, the same source code (i.e. the same @code{SourceStamp})
2452 will be used to start a new set of builds, on a different set of
2453 Builders. This ``downstream'' scheduler doesn't pay attention to
2454 Changes at all. It only pays attention to the upstream scheduler.
2456 If the build fails on any of the Builders in the upstream set,
2457 the downstream builds will not fire.  Note that, for SourceStamps
2458 generated by a ChangeSource, the @code{revision} is None, meaning HEAD.
2459 If any changes are committed between the time the upstream scheduler
2460 begins its build and the time the dependent scheduler begins its
2461 build, then those changes will be included in the downstream build.
2462 See the @pxref{Triggerable Scheduler} for a more flexible dependency
2463 mechanism that can avoid this problem.
2465 The arguments to this scheduler are:
2467 @table @code
2468 @item name
2470 @item builderNames
2472 @item properties
2474 @item upstream
2475 The upstream scheduler to watch.  Note that this is an ``instance'',
2476 not the name of the scheduler.
2477 @end table
2479 Example:
2481 @example
2482 from buildbot import scheduler
2483 tests = scheduler.Scheduler("just-tests", None, 5*60,
2484                             ["full-linux", "full-netbsd", "full-OSX"])
2485 package = scheduler.Dependent("build-package",
2486                               tests, # upstream scheduler -- no quotes!
2487                               ["make-tarball", "make-deb", "make-rpm"])
2488 c['schedulers'] = [tests, package]
2489 @end example
2491 @node Periodic Scheduler, Nightly Scheduler, Dependent Scheduler, Change Sources and Schedulers
2492 @subsection Periodic Scheduler
2493 @slindex buildbot.scheduler.Periodic
2495 This simple scheduler just triggers a build every N seconds.
2497 The arguments to this scheduler are:
2499 @table @code
2500 @item name
2502 @item builderNames
2504 @item properties
2506 @item periodicBuildTimer
2507 The time, in seconds, after which to start a build.
2508 @end table
2510 Example:
2512 @example
2513 from buildbot import scheduler
2514 nightly = scheduler.Periodic(name="nightly",
2515                 builderNames=["full-solaris"],
2516                 periodicBuildTimer=24*60*60)
2517 c['schedulers'] = [nightly]
2518 @end example
2520 The Scheduler in this example just runs the full solaris build once
2521 per day. Note that this Scheduler only lets you control the time
2522 between builds, not the absolute time-of-day of each Build, so this
2523 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2524 depending upon when it was first activated.
2526 @node Nightly Scheduler, Try Schedulers, Periodic Scheduler, Change Sources and Schedulers
2527 @subsection Nightly Scheduler
2528 @slindex buildbot.scheduler.Nightly
2530 This is highly configurable periodic build scheduler, which triggers
2531 a build at particular times of day, week, month, or year. The
2532 configuration syntax is very similar to the well-known @code{crontab}
2533 format, in which you provide values for minute, hour, day, and month
2534 (some of which can be wildcards), and a build is triggered whenever
2535 the current time matches the given constraints. This can run a build
2536 every night, every morning, every weekend, alternate Thursdays,
2537 on your boss's birthday, etc.
2539 Pass some subset of @code{minute}, @code{hour}, @code{dayOfMonth},
2540 @code{month}, and @code{dayOfWeek}; each may be a single number or
2541 a list of valid values. The builds will be triggered whenever the
2542 current time matches these values. Wildcards are represented by a
2543 '*' string. All fields default to a wildcard except 'minute', so
2544 with no fields this defaults to a build every hour, on the hour.
2545 The full list of parameters is:
2547 @table @code
2548 @item name
2550 @item builderNames
2552 @item properties
2554 @item branch
2555 The branch to build, just as for @code{Scheduler}.
2557 @item minute
2558 The minute of the hour on which to start the build.  This defaults
2559 to 0, meaning an hourly build.
2561 @item hour
2562 The hour of the day on which to start the build, in 24-hour notation.
2563 This defaults to *, meaning every hour.
2565 @item month
2566 The month in which to start the build, with January = 1.  This defaults
2567 to *, meaning every month.
2569 @item dayOfWeek
2570 The day of the week to start a build, with Monday = 0.  This defauls
2571 to *, meaning every day of the week.
2573 @item onlyIfChanged
2574 If this is true, then builds will not be scheduled at the designated time
2575 unless the source has changed since the previous build.
2576 @end table
2578 For example, the following master.cfg clause will cause a build to be
2579 started every night at 3:00am:
2581 @example
2582 s = scheduler.Nightly(name='nightly',
2583         builderNames=['builder1', 'builder2'],
2584         hour=3,
2585         minute=0)
2586 @end example
2588 This scheduler will perform a build each monday morning at 6:23am and
2589 again at 8:23am, but only if someone has committed code in the interim:
2591 @example
2592 s = scheduler.Nightly(name='BeforeWork',
2593          builderNames=['builder1'],
2594          dayOfWeek=0,
2595          hour=[6,8],
2596          minute=23,
2597          onlyIfChanged=True)
2598 @end example
2600 The following runs a build every two hours, using Python's @code{range}
2601 function:
2603 @example
2604 s = Nightly(name='every2hours',
2605         builderNames=['builder1'],
2606         hour=range(0, 24, 2))
2607 @end example
2609 Finally, this example will run only on December 24th:
2611 @example
2612 s = Nightly(name='SleighPreflightCheck',
2613         builderNames=['flying_circuits', 'radar'],
2614         month=12,
2615         dayOfMonth=24,
2616         hour=12,
2617         minute=0)
2618 @end example
2620 @node Try Schedulers, Triggerable Scheduler, Nightly Scheduler, Change Sources and Schedulers
2621 @subsection Try Schedulers
2622 @slindex buildbot.scheduler.Try_Jobdir
2623 @slindex buildbot.scheduler.Try_Userpass
2625 This scheduler allows developers to use the @code{buildbot try}
2626 command to trigger builds of code they have not yet committed. See
2627 @ref{try} for complete details.
2629 Two implementations are available: @code{Try_Jobdir} and
2630 @code{Try_Userpass}.  The former monitors a job directory, specified
2631 by the @code{jobdir} parameter, while the latter listens for PB
2632 connections on a specific @code{port}, and authenticates against
2633 @code{userport}.
2635 @node Triggerable Scheduler,  , Try Schedulers, Change Sources and Schedulers
2636 @subsection Triggerable Scheduler
2637 @cindex Triggers
2638 @slindex buildbot.scheduler.Triggerable
2640 The @code{Triggerable} scheduler waits to be triggered by a Trigger
2641 step (see @ref{Triggering Schedulers}) in another build. That step
2642 can optionally wait for the scheduler's builds to complete. This
2643 provides two advantages over Dependent schedulers. First, the same
2644 scheduler can be triggered from multiple builds. Second, the ability
2645 to wait for a Triggerable's builds to complete provides a form of
2646 "subroutine call", where one or more builds can "call" a scheduler
2647 to perform some work for them, perhaps on other buildslaves.
2649 The parameters are just the basics:
2651 @table @code
2652 @item name
2653 @item builderNames
2654 @item properties
2655 @end table
2657 This class is only useful in conjunction with the @code{Trigger} step.
2658 Here is a fully-worked example:
2660 @example
2661 from buildbot import scheduler
2662 from buildbot.process import factory
2663 from buildbot.steps import trigger
2665 checkin = scheduler.Scheduler(name="checkin",
2666             branch=None,
2667             treeStableTimer=5*60,
2668             builderNames=["checkin"])
2669 nightly = scheduler.Nightly(name='nightly',
2670             builderNames=['nightly'],
2671             hour=3,
2672             minute=0)
2674 mktarball = scheduler.Triggerable(name="mktarball",
2675                 builderNames=["mktarball"])
2676 build = scheduler.Triggerable(name="build-all-platforms",
2677                 builderNames=["build-all-platforms"])
2678 test = scheduler.Triggerable(name="distributed-test",
2679                 builderNames=["distributed-test"])
2680 package = scheduler.Triggerable(name="package-all-platforms",
2681                 builderNames=["package-all-platforms"])
2683 c['schedulers'] = [checkin, nightly, build, test, package]
2685 # on checkin, make a tarball, build it, and test it
2686 checkin_factory = factory.BuildFactory()
2687 checkin_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2688                                        waitForFinish=True))
2689 checkin_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2690                                    waitForFinish=True))
2691 checkin_factory.addStep(trigger.Trigger(schedulerNames=['distributed-test'],
2692                                   waitForFinish=True))
2694 # and every night, make a tarball, build it, and package it
2695 nightly_factory = factory.BuildFactory()
2696 nightly_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2697                                        waitForFinish=True))
2698 nightly_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2699                                    waitForFinish=True))
2700 nightly_factory.addStep(trigger.Trigger(schedulerNames=['package-all-platforms'],
2701                                      waitForFinish=True))
2702 @end example
2704 @node Merging BuildRequests, Setting the slaveport, Change Sources and Schedulers, Configuration
2705 @section Merging BuildRequests
2707 @bcindex c['mergeRequests']
2709 By default, buildbot merges BuildRequests that have the compatible
2710 SourceStamps. This behaviour can be customized with the
2711 @code{c['mergeRequests']} configuration key.  This key specifies a function
2712 which is caleld with three arguments: a @code{Builder} and two
2713 @code{BuildRequest} objects.  It should return true if the requests can be
2714 merged.  For example:
2716 @example
2717 def mergeRequests(builder, req1, req2):
2718     """Don't merge buildrequest at all"""
2719     return False
2720 c['mergeRequests'] = mergeRequests
2721 @end example
2723 In many cases, the details of the SourceStamps and BuildRequests are important.
2724 In this example, only BuildRequests with the same "reason" are merged; thus
2725 developers forcing builds for different reasons will see distinct builds.
2727 @example
2728 def mergeRequests(builder, req1, req2):
2729     if req1.source.canBeMergedWith(req2.source) and  req1.reason == req2.reason:
2730        return True
2731     return False
2732 c['mergeRequests'] = mergeRequests
2733 @end example
2735 @node Setting the slaveport, Buildslave Specifiers, Merging BuildRequests, Configuration
2736 @section Setting the slaveport
2738 @bcindex c['slavePortnum']
2740 The buildmaster will listen on a TCP port of your choosing for
2741 connections from buildslaves. It can also use this port for
2742 connections from remote Change Sources, status clients, and debug
2743 tools. This port should be visible to the outside world, and you'll
2744 need to tell your buildslave admins about your choice.
2746 It does not matter which port you pick, as long it is externally
2747 visible, however you should probably use something larger than 1024,
2748 since most operating systems don't allow non-root processes to bind to
2749 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2750 box of some sort, you may have to configure your firewall to permit
2751 inbound connections to this port.
2753 @example
2754 c['slavePortnum'] = 10000
2755 @end example
2757 @code{c['slavePortnum']} is a @emph{strports} specification string,
2758 defined in the @code{twisted.application.strports} module (try
2759 @command{pydoc twisted.application.strports} to get documentation on
2760 the format). This means that you can have the buildmaster listen on a
2761 localhost-only port by doing:
2763 @example
2764 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2765 @end example
2767 This might be useful if you only run buildslaves on the same machine,
2768 and they are all configured to contact the buildmaster at
2769 @code{localhost:10000}.
2772 @node Buildslave Specifiers, On-Demand ("Latent") Buildslaves, Setting the slaveport, Configuration
2773 @section Buildslave Specifiers
2774 @bcindex c['slaves']
2776 The @code{c['slaves']} key is a list of known buildslaves. In the common case,
2777 each buildslave is defined by an instance of the BuildSlave class.  It
2778 represents a standard, manually started machine that will try to connect to
2779 the buildbot master as a slave.  Contrast these with the "on-demand" latent
2780 buildslaves, such as the Amazon Web Service Elastic Compute Cloud latent
2781 buildslave discussed below.
2783 The BuildSlave class is instantiated with two values: (slavename,
2784 slavepassword). These are the same two values that need to be provided to the
2785 buildslave administrator when they create the buildslave.
2787 The slavenames must be unique, of course. The password exists to
2788 prevent evildoers from interfering with the buildbot by inserting
2789 their own (broken) buildslaves into the system and thus displacing the
2790 real ones.
2792 Buildslaves with an unrecognized slavename or a non-matching password
2793 will be rejected when they attempt to connect, and a message
2794 describing the problem will be put in the log file (see @ref{Logfiles}).
2796 @example
2797 from buildbot.buildslave import BuildSlave
2798 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd')
2799                BuildSlave('bot-bsd', 'bsdpasswd')
2800               ]
2801 @end example
2803 @cindex Properties
2804 @code{BuildSlave} objects can also be created with an optional
2805 @code{properties} argument, a dictionary specifying properties that
2806 will be available to any builds performed on this slave.  For example:
2808 @example
2809 from buildbot.buildslave import BuildSlave
2810 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2811                     properties=@{'os':'solaris'@}),
2812               ]
2813 @end example
2815 The @code{BuildSlave} constructor can also take an optional
2816 @code{max_builds} parameter to limit the number of builds that it
2817 will execute simultaneously:
2819 @example
2820 from buildbot.buildslave import BuildSlave
2821 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2822 @end example
2824 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2825 key was used instead, and it took a list of (name, password) tuples.
2826 This key is accepted for backwards compatibility, but is deprecated as
2827 of 0.7.6 and will go away in some future release.
2829 @menu
2830 * When Buildslaves Go Missing::
2831 @end menu
2833 @node When Buildslaves Go Missing, , , Buildslave Specifiers
2834 @subsection When Buildslaves Go Missing
2836 Sometimes, the buildslaves go away. One very common reason for this is
2837 when the buildslave process is started once (manually) and left
2838 running, but then later the machine reboots and the process is not
2839 automatically restarted.
2841 If you'd like to have the administrator of the buildslave (or other
2842 people) be notified by email when the buildslave has been missing for
2843 too long, just add the @code{notify_on_missing=} argument to the
2844 @code{BuildSlave} definition:
2846 @example
2847 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2848                           notify_on_missing="bob@@example.com"),
2849               ]
2850 @end example
2852 By default, this will send email when the buildslave has been
2853 disconnected for more than one hour. Only one email per
2854 connection-loss event will be sent. To change the timeout, use
2855 @code{missing_timeout=} and give it a number of seconds (the default
2856 is 3600).
2858 You can have the buildmaster send email to multiple recipients: just
2859 provide a list of addresses instead of a single one:
2861 @example
2862 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2863                           notify_on_missing=["bob@@example.com",
2864                                              "alice@@example.org"],
2865                           missing_timeout=300, # notify after 5 minutes
2866                           ),
2867               ]
2868 @end example
2870 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2871 status target, if one is configured. This provides a way for you to
2872 control the ``from'' address of the email, as well as the relayhost
2873 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2874 configured on this buildmaster, the buildslave-missing emails will be
2875 sent using a default configuration.
2877 Note that if you want to have a MailNotifier for buildslave-missing
2878 emails but not for regular build emails, just create one with
2879 builders=[], as follows:
2881 @example
2882 from buildbot.status import mail
2883 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2884                       relayhost="smtp.example.org")
2885 c['status'].append(m)
2886 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2887                           notify_on_missing="bob@@example.com"),
2888               ]
2889 @end example
2891 @node On-Demand ("Latent") Buildslaves, Defining Global Properties, Buildslave Specifiers, Configuration
2892 @section On-Demand ("Latent") Buildslaves
2894 The standard buildbot model has slaves started manually.  The previous section
2895 described how to configure the master for this approach.
2897 Another approach is to let the buildbot master start slaves when builds are
2898 ready, on-demand.  Thanks to services such as Amazon Web Services' Elastic
2899 Compute Cloud ("AWS EC2"), this is relatively easy to set up, and can be
2900 very useful for some situations.
2902 The buildslaves that are started on-demand are called "latent" buildslaves.
2903 As of this writing, buildbot ships with an abstract base class for building
2904 latent buildslaves, and a concrete implementation for AWS EC2.
2906 @menu
2907 * Amazon Web Services Elastic Compute Cloud ("AWS EC2")::
2908 * Dangers with Latent Buildslaves::
2909 * Writing New Latent Buildslaves::
2910 @end menu
2912 @node Amazon Web Services Elastic Compute Cloud ("AWS EC2"), Dangers with Latent Buildslaves, , On-Demand ("Latent") Buildslaves
2913 @subsection Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2915 @url{http://aws.amazon.com/ec2/,,AWS EC2} is a web service that allows you to
2916 start virtual machines in an Amazon data center. Please see their website for
2917 details, incuding costs. Using the AWS EC2 latent buildslaves involves getting
2918 an EC2 account with AWS and setting up payment; customizing one or more EC2
2919 machine images ("AMIs") on your desired operating system(s) and publishing
2920 them (privately if needed); and configuring the buildbot master to know how to
2921 start your customized images for "substantiating" your latent slaves.
2923 @menu
2924 * Get an AWS EC2 Account::
2925 * Create an AMI::
2926 * Configure the Master with an EC2LatentBuildSlave::
2927 @end menu
2929 @node Get an AWS EC2 Account, Create an AMI, , Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2930 @subsubsection Get an AWS EC2 Account
2932 To start off, to use the AWS EC2 latent buildslave, you need to get an AWS
2933 developer account and sign up for EC2. These instructions may help you get
2934 started:
2936 @itemize @bullet
2937 @item
2938 Go to http://aws.amazon.com/ and click to "Sign Up Now" for an AWS account.
2940 @item
2941 Once you are logged into your account, you need to sign up for EC2.
2942 Instructions for how to do this have changed over time because Amazon changes
2943 their website, so the best advice is to hunt for it. After signing up for EC2,
2944 it may say it wants you to upload an x.509 cert. You will need this to create
2945 images (see below) but it is not technically necessary for the buildbot master
2946 configuration.
2948 @item
2949 You must enter a valid credit card before you will be able to use EC2. Do that
2950 under 'Payment Method'.
2952 @item
2953 Make sure you're signed up for EC2 by going to 'Your Account'->'Account
2954 Activity' and verifying EC2 is listed.
2955 @end itemize
2957 @node Create an AMI, Configure the Master with an EC2LatentBuildSlave, Get an AWS EC2 Account, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2958 @subsubsection Create an AMI
2960 Now you need to create an AMI and configure the master.  You may need to
2961 run through this cycle a few times to get it working, but these instructions
2962 should get you started.
2964 Creating an AMI is out of the scope of this document.  The
2965 @url{http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/,,EC2 Getting Started Guide}
2966 is a good resource for this task.  Here are a few additional hints.
2968 @itemize @bullet
2969 @item
2970 When an instance of the image starts, it needs to automatically start a
2971 buildbot slave that connects to your master (to create a buildbot slave,
2972 @pxref{Creating a buildslave}; to make a daemon,
2973 @pxref{Launching the daemons}).
2975 @item
2976 You may want to make an instance of the buildbot slave, configure it as a
2977 standard buildslave in the master (i.e., not as a latent slave), and test and
2978 debug it that way before you turn it into an AMI and convert to a latent
2979 slave in the master.
2980 @end itemize
2982 @node Configure the Master with an EC2LatentBuildSlave, , Create an AMI, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2983 @subsubsection Configure the Master with an EC2LatentBuildSlave
2985 Now let's assume you have an AMI that should work with the
2986 EC2LatentBuildSlave.  It's now time to set up your buildbot master
2987 configuration.
2989 You will need some information from your AWS account: the "Access Key Id" and
2990 the "Secret Access Key".  If you've built the AMI yourself, you probably
2991 already are familiar with these values.  If you have not, and someone has
2992 given you access to an AMI, these hints may help you find the necessary
2993 values:
2995 @itemize @bullet
2996 @item
2997 While logged into your AWS account, find the "Access Identifiers" link (either
2998 on the left, or via "Your Account" -> "Access Identifiers".
3000 @item
3001 On the page, you'll see alphanumeric values for "Your Access Key Id:" and
3002 "Your Secret Access Key:". Make a note of these. Later on, we'll call the
3003 first one your "identifier" and the second one your "secret_identifier."
3004 @end itemize
3006 When creating an EC2LatentBuildSlave in the buildbot master configuration,
3007 the first three arguments are required.  The name and password are the first
3008 two arguments, and work the same as with normal buildslaves.  The next
3009 argument specifies the type of the EC2 virtual machine (available options as
3010 of this writing include "m1.small", "m1.large", 'm1.xlarge", "c1.medium",
3011 and "c1.xlarge"; see the EC2 documentation for descriptions of these
3012 machines).
3014 Here is the simplest example of configuring an EC2 latent buildslave. It
3015 specifies all necessary remaining values explicitly in the instantiation.
3017 @example
3018 from buildbot.ec2buildslave import EC2LatentBuildSlave
3019 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3020                                    ami='ami-12345',
3021                                    identifier='publickey',
3022                                    secret_identifier='privatekey'
3023                                    )]
3024 @end example
3026 The "ami" argument specifies the AMI that the master should start.  The
3027 "identifier" argument specifies the AWS "Access Key Id," and the
3028 "secret_identifier" specifies the AWS "Secret Access Key." Both the AMI and
3029 the account information can be specified in alternate ways.
3031 Note that whoever has your identifier and secret_identifier values can request
3032 AWS work charged to your account, so these values need to be carefully
3033 protected. Another way to specify these access keys is to put them in a
3034 separate file. You can then make the access privileges stricter for this
3035 separate file, and potentially let more people read your main configuration
3036 file.
3038 By default, you can make an .ec2 directory in the home folder of the user
3039 running the buildbot master. In that directory, create a file called aws_id.
3040 The first line of that file should be your access key id; the second line
3041 should be your secret access key id. Then you can instantiate the build slave
3042 as follows.
3044 @example
3045 from buildbot.ec2buildslave import EC2LatentBuildSlave
3046 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3047                                    ami='ami-12345')]
3048 @end example
3050 If you want to put the key information in another file, use the
3051 "aws_id_file_path" initialization argument.
3053 Previous examples used a particular AMI.  If the Buildbot master will be
3054 deployed in a process-controlled environment, it may be convenient to
3055 specify the AMI more flexibly.  Rather than specifying an individual AMI,
3056 specify one or two AMI filters.
3058 In all cases, the AMI that sorts last by its location (the S3 bucket and
3059 manifest name) will be preferred.
3061 One available filter is to specify the acceptable AMI owners, by AWS account
3062 number (the 12 digit number, usually rendered in AWS with hyphens like
3063 "1234-5678-9012", should be entered as in integer).
3065 @example
3066 from buildbot.ec2buildslave import EC2LatentBuildSlave
3067 bot1 = EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3068                            valid_ami_owners=[11111111111,
3069                                              22222222222],
3070                            identifier='publickey',
3071                            secret_identifier='privatekey'
3072                            )
3073 @end example
3075 The other available filter is to provide a regular expression string that
3076 will be matched against each AMI's location (the S3 bucket and manifest name).
3078 @example
3079 from buildbot.ec2buildslave import EC2LatentBuildSlave
3080 bot1 = EC2LatentBuildSlave(
3081     'bot1', 'sekrit', 'm1.large',
3082     valid_ami_location_regex=r'buildbot\-.*/image.manifest.xml',
3083     identifier='publickey', secret_identifier='privatekey')
3084 @end example
3086 The regular expression can specify a group, which will be preferred for the
3087 sorting.  Only the first group is used; subsequent groups are ignored.
3089 @example
3090 from buildbot.ec2buildslave import EC2LatentBuildSlave
3091 bot1 = EC2LatentBuildSlave(
3092     'bot1', 'sekrit', 'm1.large',
3093     valid_ami_location_regex=r'buildbot\-.*\-(.*)/image.manifest.xml',
3094     identifier='publickey', secret_identifier='privatekey')
3095 @end example
3097 If the group can be cast to an integer, it will be.  This allows 10 to sort
3098 after 1, for instance.
3100 @example
3101 from buildbot.ec2buildslave import EC2LatentBuildSlave
3102 bot1 = EC2LatentBuildSlave(
3103     'bot1', 'sekrit', 'm1.large',
3104     valid_ami_location_regex=r'buildbot\-.*\-(\d+)/image.manifest.xml',
3105     identifier='publickey', secret_identifier='privatekey')
3106 @end example
3108 In addition to using the password as a handshake between the master and the
3109 slave, you may want to use a firewall to assert that only machines from a
3110 specific IP can connect as slaves.  This is possible with AWS EC2 by using
3111 the Elastic IP feature.  To configure, generate a Elastic IP in AWS, and then
3112 specify it in your configuration using the "elastic_ip" argument.
3114 @example
3115 from buildbot.ec2buildslave import EC2LatentBuildSlave
3116 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3117                                    'ami-12345',
3118                                    identifier='publickey',
3119                                    secret_identifier='privatekey',
3120                                    elastic_ip='208.77.188.166'
3121                                    )]
3122 @end example
3124 The EC2LatentBuildSlave supports all other configuration from the standard
3125 BuildSlave.  The "missing_timeout" and "notify_on_missing" specify how long
3126 to wait for an EC2 instance to attach before considering the attempt to have
3127 failed, and email addresses to alert, respectively.  "missing_timeout"
3128 defaults to 20 minutes.
3130 The "build_wait_timeout" allows you to specify how long an EC2LatentBuildSlave
3131 should wait after a build for another build before it shuts down the EC2
3132 instance.  It defaults to 10 minutes.
3134 "keypair_name" and "security_name" allow you to specify different names for
3135 these AWS EC2 values.  They both default to "latent_buildbot_slave".
3137 @node Dangers with Latent Buildslaves, Writing New Latent Buildslaves, Amazon Web Services Elastic Compute Cloud ("AWS EC2"), On-Demand ("Latent") Buildslaves
3138 @subsection Dangers with Latent Buildslaves
3140 Any latent build slave that interacts with a for-fee service, such as the
3141 EC2LatentBuildSlave, brings significant risks. As already identified, the
3142 configuraton will need access to account information that, if obtained by a
3143 criminal, can be used to charge services to your account. Also, bugs in the
3144 buildbot software may lead to unnecessary charges. In particular, if the
3145 master neglects to shut down an instance for some reason, a virtual machine
3146 may be running unnecessarily, charging against your account. Manual and/or
3147 automatic (e.g. nagios with a plugin using a library like boto)
3148 double-checking may be appropriate.
3150 A comparitively trivial note is that currently if two instances try to attach
3151 to the same latent buildslave, it is likely that the system will become
3152 confused.  This should not occur, unless, for instance, you configure a normal
3153 build slave to connect with the authentication of a latent buildbot.  If the
3154 situation occurs, stop all attached instances and restart the master.
3156 @node Writing New Latent Buildslaves, , Dangers with Latent Buildslaves, On-Demand ("Latent") Buildslaves
3157 @subsection Writing New Latent Buildslaves
3159 Writing a new latent buildslave should only require subclassing
3160 @code{buildbot.buildslave.AbstractLatentBuildSlave} and implementing
3161 start_instance and stop_instance.
3163 @example
3164 def start_instance(self):
3165     # responsible for starting instance that will try to connect with this
3166     # master. Should return deferred. Problems should use an errback. The
3167     # callback value can be None, or can be an iterable of short strings to
3168     # include in the "substantiate success" status message, such as
3169     # identifying the instance that started.
3170     raise NotImplementedError
3172 def stop_instance(self, fast=False):
3173     # responsible for shutting down instance. Return a deferred. If `fast`,
3174     # we're trying to shut the master down, so callback as soon as is safe.
3175     # Callback value is ignored.
3176     raise NotImplementedError
3177 @end example
3179 See @code{buildbot.ec2buildslave.EC2LatentBuildSlave} for an example, or see the
3180 test example @code{buildbot.test_slaves.FakeLatentBuildSlave}.
3182 @node Defining Global Properties, Defining Builders, On-Demand ("Latent") Buildslaves, Configuration
3183 @section Defining Global Properties
3184 @bcindex c['properties']
3185 @cindex Properties
3187 The @code{'properties'} configuration key defines a dictionary
3188 of properties that will be available to all builds started by the
3189 buildmaster:
3191 @example
3192 c['properties'] = @{
3193     'Widget-version' : '1.2',
3194     'release-stage' : 'alpha'
3196 @end example
3198 @node Defining Builders, Defining Status Targets, Defining Global Properties, Configuration
3199 @section Defining Builders
3201 @bcindex c['builders']
3203 The @code{c['builders']} key is a list of dictionaries which specify
3204 the Builders. The Buildmaster runs a collection of Builders, each of
3205 which handles a single type of build (e.g. full versus quick), on a
3206 single build slave. A Buildbot which makes sure that the latest code
3207 (``HEAD'') compiles correctly across four separate architecture will
3208 have four Builders, each performing the same build but on different
3209 slaves (one per platform).
3211 Each Builder gets a separate column in the waterfall display. In
3212 general, each Builder runs independently (although various kinds of
3213 interlocks can cause one Builder to have an effect on another).
3215 Each Builder specification dictionary has several required keys:
3217 @table @code
3218 @item name
3219 This specifies the Builder's name, which is used in status
3220 reports.
3222 @item slavename
3223 This specifies which buildslave will be used by this Builder.
3224 @code{slavename} must appear in the @code{c['slaves']} list. Each
3225 buildslave can accomodate multiple Builders.
3227 @item slavenames
3228 If you provide @code{slavenames} instead of @code{slavename}, you can
3229 give a list of buildslaves which are capable of running this Builder.
3230 If multiple buildslaves are available for any given Builder, you will
3231 have some measure of redundancy: in case one slave goes offline, the
3232 others can still keep the Builder working. In addition, multiple
3233 buildslaves will allow multiple simultaneous builds for the same
3234 Builder, which might be useful if you have a lot of forced or ``try''
3235 builds taking place.
3237 If you use this feature, it is important to make sure that the
3238 buildslaves are all, in fact, capable of running the given build. The
3239 slave hosts should be configured similarly, otherwise you will spend a
3240 lot of time trying (unsuccessfully) to reproduce a failure that only
3241 occurs on some of the buildslaves and not the others. Different
3242 platforms, operating systems, versions of major programs or libraries,
3243 all these things mean you should use separate Builders.
3245 @item builddir
3246 This specifies the name of a subdirectory (under the base directory)
3247 in which everything related to this builder will be placed. On the
3248 buildmaster, this holds build status information. On the buildslave,
3249 this is where checkouts, compiles, and tests are run.
3251 @item factory
3252 This is a @code{buildbot.process.factory.BuildFactory} instance which
3253 controls how the build is performed. Full details appear in their own
3254 chapter, @xref{Build Process}. Parameters like the location of the CVS
3255 repository and the compile-time options used for the build are
3256 generally provided as arguments to the factory's constructor.
3258 @end table
3260 Other optional keys may be set on each Builder:
3262 @table @code
3264 @item category
3265 If provided, this is a string that identifies a category for the
3266 builder to be a part of. Status clients can limit themselves to a
3267 subset of the available categories. A common use for this is to add
3268 new builders to your setup (for a new module, or for a new buildslave)
3269 that do not work correctly yet and allow you to integrate them with
3270 the active builders. You can put these new builders in a test
3271 category, make your main status clients ignore them, and have only
3272 private status clients pick them up. As soon as they work, you can
3273 move them over to the active category.
3275 @end table
3278 @node Defining Status Targets, Debug options, Defining Builders, Configuration
3279 @section Defining Status Targets
3281 The Buildmaster has a variety of ways to present build status to
3282 various users. Each such delivery method is a ``Status Target'' object
3283 in the configuration's @code{status} list. To add status targets, you
3284 just append more objects to this list:
3286 @bcindex c['status']
3288 @example
3289 c['status'] = []
3291 from buildbot.status import html
3292 c['status'].append(html.Waterfall(http_port=8010))
3294 from buildbot.status import mail
3295 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
3296                       extraRecipients=["builds@@lists.example.com"],
3297                       sendToInterestedUsers=False)
3298 c['status'].append(m)
3300 from buildbot.status import words
3301 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
3302                              channels=["#example"]))
3303 @end example
3305 Status delivery has its own chapter, @xref{Status Delivery}, in which
3306 all the built-in status targets are documented.
3309 @node Debug options,  , Defining Status Targets, Configuration
3310 @section Debug options
3313 @bcindex c['debugPassword']
3314 If you set @code{c['debugPassword']}, then you can connect to the
3315 buildmaster with the diagnostic tool launched by @code{buildbot
3316 debugclient MASTER:PORT}. From this tool, you can reload the config
3317 file, manually force builds, and inject changes, which may be useful
3318 for testing your buildmaster without actually commiting changes to
3319 your repository (or before you have the Change Sources set up). The
3320 debug tool uses the same port number as the slaves do:
3321 @code{c['slavePortnum']}, and is authenticated with this password.
3323 @example
3324 c['debugPassword'] = "debugpassword"
3325 @end example
3327 @bcindex c['manhole']
3328 If you set @code{c['manhole']} to an instance of one of the classes in
3329 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
3330 and get an interactive Python shell, which may be useful for debugging
3331 buildbot internals. It is probably only useful for buildbot
3332 developers. It exposes full access to the buildmaster's account
3333 (including the ability to modify and delete files), so it should not
3334 be enabled with a weak or easily guessable password.
3336 There are three separate @code{Manhole} classes. Two of them use SSH,
3337 one uses unencrypted telnet. Two of them use a username+password
3338 combination to grant access, one of them uses an SSH-style
3339 @file{authorized_keys} file which contains a list of ssh public keys.
3341 @table @code
3342 @item manhole.AuthorizedKeysManhole
3343 You construct this with the name of a file that contains one SSH
3344 public key per line, just like @file{~/.ssh/authorized_keys}. If you
3345 provide a non-absolute filename, it will be interpreted relative to
3346 the buildmaster's base directory.
3348 @item manhole.PasswordManhole
3349 This one accepts SSH connections but asks for a username and password
3350 when authenticating. It accepts only one such pair.
3353 @item manhole.TelnetManhole
3354 This accepts regular unencrypted telnet connections, and asks for a
3355 username/password pair before providing access. Because this
3356 username/password is transmitted in the clear, and because Manhole
3357 access to the buildmaster is equivalent to granting full shell
3358 privileges to both the buildmaster and all the buildslaves (and to all
3359 accounts which then run code produced by the buildslaves), it is
3360 highly recommended that you use one of the SSH manholes instead.
3362 @end table
3364 @example
3365 # some examples:
3366 from buildbot import manhole
3367 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
3368 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
3369 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
3370 @end example
3372 The @code{Manhole} instance can be configured to listen on a specific
3373 port. You may wish to have this listening port bind to the loopback
3374 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
3375 restrict access to clients which are running on the same host.
3377 @example
3378 from buildbot.manhole import PasswordManhole
3379 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
3380 @end example
3382 To have the @code{Manhole} listen on all interfaces, use
3383 @code{"tcp:9999"} or simply 9999. This port specification uses
3384 @code{twisted.application.strports}, so you can make it listen on SSL
3385 or even UNIX-domain sockets if you want.
3387 Note that using any Manhole requires that the TwistedConch package be
3388 installed, and that you be using Twisted version 2.0 or later.
3390 The buildmaster's SSH server will use a different host key than the
3391 normal sshd running on a typical unix host. This will cause the ssh
3392 client to complain about a ``host key mismatch'', because it does not
3393 realize there are two separate servers running on the same host. To
3394 avoid this, use a clause like the following in your @file{.ssh/config}
3395 file:
3397 @example
3398 Host remotehost-buildbot
3399  HostName remotehost
3400  HostKeyAlias remotehost-buildbot
3401  Port 9999
3402  # use 'user' if you use PasswordManhole and your name is not 'admin'.
3403  # if you use AuthorizedKeysManhole, this probably doesn't matter.
3404  User admin
3405 @end example
3408 @node Getting Source Code Changes, Build Process, Configuration, Top
3409 @chapter Getting Source Code Changes
3411 The most common way to use the Buildbot is centered around the idea of
3412 @code{Source Trees}: a directory tree filled with source code of some form
3413 which can be compiled and/or tested. Some projects use languages that don't
3414 involve any compilation step: nevertheless there may be a @code{build} phase
3415 where files are copied or rearranged into a form that is suitable for
3416 installation. Some projects do not have unit tests, and the Buildbot is
3417 merely helping to make sure that the sources can compile correctly. But in
3418 all of these cases, the thing-being-tested is a single source tree.
3420 A Version Control System mantains a source tree, and tells the
3421 buildmaster when it changes. The first step of each Build is typically
3422 to acquire a copy of some version of this tree.
3424 This chapter describes how the Buildbot learns about what Changes have
3425 occurred. For more information on VC systems and Changes, see
3426 @ref{Version Control Systems}.
3429 @menu
3430 * Change Sources::
3431 * Choosing ChangeSources::
3432 * CVSToys - PBService::
3433 * Mail-parsing ChangeSources::
3434 * PBChangeSource::
3435 * P4Source::
3436 * BonsaiPoller::
3437 * SVNPoller::
3438 * MercurialHook::
3439 * Bzr Hook::
3440 * Bzr Poller::
3441 @end menu
3445 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
3446 @section Change Sources
3448 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
3449 @c so narrow-minded anymore
3451 Each Buildmaster watches a single source tree. Changes can be provided
3452 by a variety of ChangeSource types, however any given project will
3453 typically have only a single ChangeSource active. This section
3454 provides a description of all available ChangeSource types and
3455 explains how to set up each of them.
3457 There are a variety of ChangeSources available, some of which are
3458 meant to be used in conjunction with other tools to deliver Change
3459 events from the VC repository to the buildmaster.
3461 @itemize @bullet
3463 @item CVSToys
3464 This ChangeSource opens a TCP connection from the buildmaster to a
3465 waiting FreshCVS daemon that lives on the repository machine, and
3466 subscribes to hear about Changes.
3468 @item MaildirSource
3469 This one watches a local maildir-format inbox for email sent out by
3470 the repository when a change is made. When a message arrives, it is
3471 parsed to create the Change object. A variety of parsing functions are
3472 available to accomodate different email-sending tools.
3474 @item PBChangeSource
3475 This ChangeSource listens on a local TCP socket for inbound
3476 connections from a separate tool. Usually, this tool would be run on
3477 the VC repository machine in a commit hook. It is expected to connect
3478 to the TCP socket and send a Change message over the network
3479 connection. The @command{buildbot sendchange} command is one example
3480 of a tool that knows how to send these messages, so you can write a
3481 commit script for your VC system that calls it to deliver the Change.
3482 There are other tools in the contrib/ directory that use the same
3483 protocol.
3485 @end itemize
3487 As a quick guide, here is a list of VC systems and the ChangeSources
3488 that might be useful with them. All of these ChangeSources are in the
3489 @code{buildbot.changes} module.
3491 @table @code
3492 @item CVS
3494 @itemize @bullet
3495 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
3496 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
3497 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
3498 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
3499 @item pb.PBChangeSource (listening for connections from @code{buildbot
3500 sendchange} run in a loginfo script)
3501 @item pb.PBChangeSource (listening for connections from a long-running
3502 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
3503 database directly
3504 @end itemize
3506 @item SVN
3507 @itemize @bullet
3508 @item pb.PBChangeSource (listening for connections from
3509 @code{contrib/svn_buildbot.py} run in a postcommit script)
3510 @item pb.PBChangeSource (listening for connections from a long-running
3511 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
3512 process
3513 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
3514 @item svnpoller.SVNPoller (polling the SVN repository)
3515 @end itemize
3517 @item Darcs
3518 @itemize @bullet
3519 @item pb.PBChangeSource (listening for connections from
3520 @code{contrib/darcs_buildbot.py} in a commit script
3521 @end itemize
3523 @item Mercurial
3524 @itemize @bullet
3525 @item pb.PBChangeSource (listening for connections from
3526 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
3527 @item pb.PBChangeSource (listening for connections from
3528 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
3529 hook)
3530 @end itemize
3532 @item Arch/Bazaar
3533 @itemize @bullet
3534 @item pb.PBChangeSource (listening for connections from
3535 @code{contrib/arch_buildbot.py} run in a commit hook)
3536 @end itemize
3538 @item Bzr (the newer Bazaar)
3539 @itemize @bullet
3540 @item pb.PBChangeSource (listening for connections from
3541 @code{contrib/bzr_buildbot.py} run in a post-change-branch-tip or commit hook)
3542 @item @code{contrib/bzr_buildbot.py}'s BzrPoller (polling the Bzr repository)
3543 @end itemize
3545 @item Git
3546 @itemize @bullet
3547 @item pb.PBChangeSource (listening for connections from
3548 @code{contrib/git_buildbot.py} run in the post-receive hook)
3549 @end itemize
3551 @end table
3553 All VC systems can be driven by a PBChangeSource and the
3554 @code{buildbot sendchange} tool run from some form of commit script.
3555 If you write an email parsing function, they can also all be driven by
3556 a suitable @code{MaildirSource}.
3559 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
3560 @section Choosing ChangeSources
3562 The @code{master.cfg} configuration file has a dictionary key named
3563 @code{BuildmasterConfig['change_source']}, which holds the active
3564 @code{IChangeSource} object. The config file will typically create an
3565 object from one of the classes described below and stuff it into this
3566 key.
3568 Each buildmaster typically has just a single ChangeSource, since it is
3569 only watching a single source tree. But if, for some reason, you need
3570 multiple sources, just set @code{c['change_source']} to a list of
3571 ChangeSources.. it will accept that too.
3573 @example
3574 s = FreshCVSSourceNewcred(host="host", port=4519,
3575                           user="alice", passwd="secret",
3576                           prefix="Twisted")
3577 BuildmasterConfig['change_source'] = [s]
3578 @end example
3580 Each source tree has a nominal @code{top}. Each Change has a list of
3581 filenames, which are all relative to this top location. The
3582 ChangeSource is responsible for doing whatever is necessary to
3583 accomplish this. Most sources have a @code{prefix} argument: a partial
3584 pathname which is stripped from the front of all filenames provided to
3585 that @code{ChangeSource}. Files which are outside this sub-tree are
3586 ignored by the changesource: it does not generate Changes for those
3587 files.
3590 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
3591 @section CVSToys - PBService
3593 @csindex buildbot.changes.freshcvs.FreshCVSSource
3595 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
3596 server which runs on the machine that hosts the CVS repository it
3597 watches. It has a variety of ways to distribute commit notifications,
3598 and offers a flexible regexp-based way to filter out uninteresting
3599 changes. One of the notification options is named @code{PBService} and
3600 works by listening on a TCP port for clients. These clients subscribe
3601 to hear about commit notifications.
3603 The buildmaster has a CVSToys-compatible @code{PBService} client built
3604 in. There are two versions of it, one for old versions of CVSToys
3605 (1.0.9 and earlier) which used the @code{oldcred} authentication
3606 framework, and one for newer versions (1.0.10 and later) which use
3607 @code{newcred}. Both are classes in the
3608 @code{buildbot.changes.freshcvs} package.
3610 @code{FreshCVSSourceNewcred} objects are created with the following
3611 parameters:
3613 @table @samp
3615 @item @code{host} and @code{port}
3616 these specify where the CVSToys server can be reached
3618 @item @code{user} and @code{passwd}
3619 these specify the login information for the CVSToys server
3620 (@code{freshcvs}). These must match the server's values, which are
3621 defined in the @code{freshCfg} configuration file (which lives in the
3622 CVSROOT directory of the repository).
3624 @item @code{prefix}
3625 this is the prefix to be found and stripped from filenames delivered
3626 by the CVSToys server. Most projects live in sub-directories of the
3627 main repository, as siblings of the CVSROOT sub-directory, so
3628 typically this prefix is set to that top sub-directory name.
3630 @end table
3632 @heading Example
3634 To set up the freshCVS server, add a statement like the following to
3635 your @file{freshCfg} file:
3637 @example
3638 pb = ConfigurationSet([
3639     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
3640     ])
3641 @end example
3643 This will announce all changes to a client which connects to port 4519
3644 using a username of 'foo' and a password of 'bar'.
3646 Then add a clause like this to your buildmaster's @file{master.cfg}:
3648 @example
3649 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
3650                                                     "foo", "bar",
3651                                                     prefix="glib/")
3652 @end example
3654 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
3655 "glib" is the top-level directory (relative to the repository's root) where
3656 all your source code lives. Most projects keep one or more projects in the
3657 same repository (along with CVSROOT/ to hold admin files like loginfo and
3658 freshCfg); the prefix= argument tells the buildmaster to ignore everything
3659 outside that directory, and to strip that common prefix from all pathnames
3660 it handles.
3663 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
3664 @section Mail-parsing ChangeSources
3666 Many projects publish information about changes to their source tree
3667 by sending an email message out to a mailing list, frequently named
3668 PROJECT-commits or PROJECT-changes. Each message usually contains a
3669 description of the change (who made the change, which files were
3670 affected) and sometimes a copy of the diff. Humans can subscribe to
3671 this list to stay informed about what's happening to the source tree.
3673 The Buildbot can also be subscribed to a -commits mailing list, and
3674 can trigger builds in response to Changes that it hears about. The
3675 buildmaster admin needs to arrange for these email messages to arrive
3676 in a place where the buildmaster can find them, and configure the
3677 buildmaster to parse the messages correctly. Once that is in place,
3678 the email parser will create Change objects and deliver them to the
3679 Schedulers (see @pxref{Change Sources and Schedulers}) just
3680 like any other ChangeSource.
3682 There are two components to setting up an email-based ChangeSource.
3683 The first is to route the email messages to the buildmaster, which is
3684 done by dropping them into a ``maildir''. The second is to actually
3685 parse the messages, which is highly dependent upon the tool that was
3686 used to create them. Each VC system has a collection of favorite
3687 change-emailing tools, and each has a slightly different format, so
3688 each has a different parsing function. There is a separate
3689 ChangeSource variant for each parsing function.
3691 Once you've chosen a maildir location and a parsing function, create
3692 the change source and put it in @code{c['change_source']}:
3694 @example
3695 from buildbot.changes.mail import SyncmailMaildirSource
3696 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
3697                                            prefix="/trunk/")
3698 @end example
3700 @menu
3701 * Subscribing the Buildmaster::
3702 * Using Maildirs::
3703 * Parsing Email Change Messages::
3704 @end menu
3706 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
3707 @subsection Subscribing the Buildmaster
3709 The recommended way to install the buildbot is to create a dedicated
3710 account for the buildmaster. If you do this, the account will probably
3711 have a distinct email address (perhaps
3712 @email{buildmaster@@example.org}). Then just arrange for this
3713 account's email to be delivered to a suitable maildir (described in
3714 the next section).
3716 If the buildbot does not have its own account, ``extension addresses''
3717 can be used to distinguish between email intended for the buildmaster
3718 and email intended for the rest of the account. In most modern MTAs,
3719 the e.g. @code{foo@@example.org} account has control over every email
3720 address at example.org which begins with "foo", such that email
3721 addressed to @email{account-foo@@example.org} can be delivered to a
3722 different destination than @email{account-bar@@example.org}. qmail
3723 does this by using separate .qmail files for the two destinations
3724 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
3725 controlling the base address and @file{.qmail-default} controlling all
3726 other extensions). Other MTAs have similar mechanisms.
3728 Thus you can assign an extension address like
3729 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
3730 @email{foo@@example.org} for your own use.
3733 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
3734 @subsection Using Maildirs
3736 A ``maildir'' is a simple directory structure originally developed for
3737 qmail that allows safe atomic update without locking. Create a base
3738 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
3739 When messages arrive, they are put into a uniquely-named file (using
3740 pids, timestamps, and random numbers) in ``tmp''. When the file is
3741 complete, it is atomically renamed into ``new''. Eventually the
3742 buildmaster notices the file in ``new'', reads and parses the
3743 contents, then moves it into ``cur''. A cronjob can be used to delete
3744 files in ``cur'' at leisure.
3746 Maildirs are frequently created with the @command{maildirmake} tool,
3747 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
3748 equivalent.
3750 Many modern MTAs can deliver directly to maildirs. The usual .forward
3751 or .procmailrc syntax is to name the base directory with a trailing
3752 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
3753 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
3754 Delivery Agent).
3756 For MTAs which cannot put files into maildirs directly, the
3757 ``safecat'' tool can be executed from a .forward file to accomplish
3758 the same thing.
3760 The Buildmaster uses the linux DNotify facility to receive immediate
3761 notification when the maildir's ``new'' directory has changed. When
3762 this facility is not available, it polls the directory for new
3763 messages, every 10 seconds by default.
3765 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
3766 @subsection Parsing Email Change Messages
3768 The second component to setting up an email-based ChangeSource is to
3769 parse the actual notices. This is highly dependent upon the VC system
3770 and commit script in use.
3772 A couple of common tools used to create these change emails are:
3774 @table @samp
3776 @item CVS
3777 @table @samp
3778 @item CVSToys MailNotifier
3779 @ref{FCMaildirSource}
3780 @item Bonsai notification
3781 @ref{BonsaiMaildirSource}
3782 @item syncmail
3783 @ref{SyncmailMaildirSource}
3784 @end table
3786 @item SVN
3787 @table @samp
3788 @item svnmailer
3789 http://opensource.perlig.de/en/svnmailer/
3790 @item commit-email.pl
3791 @ref{SVNCommitEmailMaildirSource}
3792 @end table
3794 @item Mercurial
3795 @table @samp
3796 @item NotifyExtension
3797 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
3798 @end table
3800 @item Git
3801 @table @samp
3802 @item post-receive-email
3803 http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email;hb=HEAD
3804 @end table
3806 @end table
3809 The following sections describe the parsers available for each of
3810 these tools.
3812 Most of these parsers accept a @code{prefix=} argument, which is used
3813 to limit the set of files that the buildmaster pays attention to. This
3814 is most useful for systems like CVS and SVN which put multiple
3815 projects in a single repository (or use repository names to indicate
3816 branches). Each filename that appears in the email is tested against
3817 the prefix: if the filename does not start with the prefix, the file
3818 is ignored. If the filename @emph{does} start with the prefix, that
3819 prefix is stripped from the filename before any further processing is
3820 done. Thus the prefix usually ends with a slash.
3822 @menu
3823 * FCMaildirSource::
3824 * SyncmailMaildirSource::
3825 * BonsaiMaildirSource::
3826 * SVNCommitEmailMaildirSource::
3827 @end menu
3829 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
3830 @subsubsection FCMaildirSource
3833 @csindex buildbot.changes.mail.FCMaildirSource
3835 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
3837 This parser works with the CVSToys @code{MailNotification} action,
3838 which will send email to a list of recipients for each commit. This
3839 tends to work better than using @code{/bin/mail} from within the
3840 CVSROOT/loginfo file directly, as CVSToys will batch together all
3841 files changed during the same CVS invocation, and can provide more
3842 information (like creating a ViewCVS URL for each file changed).
3844 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3845 messages and turn them into Change objects. It can be given two
3846 parameters: the directory name of the maildir root, and the prefix to
3847 strip.
3849 @example
3850 from buildbot.changes.mail import FCMaildirSource
3851 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3852 @end example
3854 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3855 @subsubsection SyncmailMaildirSource
3857 @csindex buildbot.changes.mail.SyncmailMaildirSource
3859 http://sourceforge.net/projects/cvs-syncmail
3861 @code{SyncmailMaildirSource} knows how to parse the message format used by
3862 the CVS ``syncmail'' script.
3864 @example
3865 from buildbot.changes.mail import SyncmailMaildirSource
3866 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3867 @end example
3869 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3870 @subsubsection BonsaiMaildirSource
3872 @csindex buildbot.changes.mail.BonsaiMaildirSource
3874 http://www.mozilla.org/bonsai.html
3876 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3877 tree-management system built by Mozilla.
3879 @example
3880 from buildbot.changes.mail import BonsaiMaildirSource
3881 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3882 @end example
3884 @node SVNCommitEmailMaildirSource,  , BonsaiMaildirSource, Parsing Email Change Messages
3885 @subsubsection SVNCommitEmailMaildirSource
3887 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3889 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3890 @code{commit-email.pl} script, which is included in the Subversion
3891 distribution.
3893 It does not currently handle branches: all of the Change objects that
3894 it creates will be associated with the default (i.e. trunk) branch.
3896 @example
3897 from buildbot.changes.mail import SVNCommitEmailMaildirSource
3898 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
3899 @end example
3902 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
3903 @section PBChangeSource
3905 @csindex buildbot.changes.pb.PBChangeSource
3907 The last kind of ChangeSource actually listens on a TCP port for
3908 clients to connect and push change notices @emph{into} the
3909 Buildmaster. This is used by the built-in @code{buildbot sendchange}
3910 notification tool, as well as the VC-specific
3911 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
3912 @file{contrib/hg_buildbot.py} tools, and the
3913 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
3914 repository (in a commit hook script), and connect to the buildmaster
3915 directly each time a file is comitted. This is also useful for
3916 creating new kinds of change sources that work on a @code{push} model
3917 instead of some kind of subscription scheme, for example a script
3918 which is run out of an email .forward file.
3920 This ChangeSource can be configured to listen on its own TCP port, or
3921 it can share the port that the buildmaster is already using for the
3922 buildslaves to connect. (This is possible because the
3923 @code{PBChangeSource} uses the same protocol as the buildslaves, and
3924 they can be distinguished by the @code{username} attribute used when
3925 the initial connection is established). It might be useful to have it
3926 listen on a different port if, for example, you wanted to establish
3927 different firewall rules for that port. You could allow only the SVN
3928 repository machine access to the @code{PBChangeSource} port, while
3929 allowing only the buildslave machines access to the slave port. Or you
3930 could just expose one port and run everything over it. @emph{Note:
3931 this feature is not yet implemented, the PBChangeSource will always
3932 share the slave port and will always have a @code{user} name of
3933 @code{change}, and a passwd of @code{changepw}. These limitations will
3934 be removed in the future.}.
3937 The @code{PBChangeSource} is created with the following arguments. All
3938 are optional.
3940 @table @samp
3941 @item @code{port}
3942 which port to listen on. If @code{None} (which is the default), it
3943 shares the port used for buildslave connections. @emph{Not
3944 Implemented, always set to @code{None}}.
3946 @item @code{user} and @code{passwd}
3947 The user/passwd account information that the client program must use
3948 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
3949 Implemented, @code{user} is currently always set to @code{change},
3950 @code{passwd} is always set to @code{changepw}}.
3952 @item @code{prefix}
3953 The prefix to be found and stripped from filenames delivered over the
3954 connection. Any filenames which do not start with this prefix will be
3955 removed. If all the filenames in a given Change are removed, the that
3956 whole Change will be dropped. This string should probably end with a
3957 directory separator.
3959 This is useful for changes coming from version control systems that
3960 represent branches as parent directories within the repository (like
3961 SVN and Perforce). Use a prefix of 'trunk/' or
3962 'project/branches/foobranch/' to only follow one branch and to get
3963 correct tree-relative filenames. Without a prefix, the PBChangeSource
3964 will probably deliver Changes with filenames like @file{trunk/foo.c}
3965 instead of just @file{foo.c}. Of course this also depends upon the
3966 tool sending the Changes in (like @command{buildbot sendchange}) and
3967 what filenames it is delivering: that tool may be filtering and
3968 stripping prefixes at the sending end.
3970 @end table
3972 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
3973 @section P4Source
3975 @csindex buildbot.changes.p4poller.P4Source
3977 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
3978 Perforce} depot for changes. It accepts the following arguments:
3980 @table @samp
3981 @item @code{p4base}
3982 The base depot path to watch, without the trailing '/...'.
3984 @item @code{p4port}
3985 The Perforce server to connect to (as host:port).
3987 @item @code{p4user}
3988 The Perforce user.
3990 @item @code{p4passwd}
3991 The Perforce password.
3993 @item @code{p4bin}
3994 An optional string parameter. Specify the location of the perforce command 
3995 line binary (p4).  You only need to do this if the perforce binary is not 
3996 in the path of the buildbot user.  Defaults to ``p4''.
3998 @item @code{split_file}
3999 A function that maps a pathname, without the leading @code{p4base}, to a
4000 (branch, filename) tuple. The default just returns (None, branchfile),
4001 which effectively disables branch support. You should supply a function
4002 which understands your repository structure.
4004 @item @code{pollinterval}
4005 How often to poll, in seconds. Defaults to 600 (10 minutes).
4007 @item @code{histmax}
4008 The maximum number of changes to inspect at a time. If more than this
4009 number occur since the last poll, older changes will be silently
4010 ignored.
4011 @end table
4013 @heading Example
4015 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
4016 specified in the buildmaster's environment. It watches a project in which the
4017 branch name is simply the next path component, and the file is all path
4018 components after.
4020 @example
4021 import buildbot.changes.p4poller
4022 s = p4poller.P4Source(p4base='//depot/project/',
4023                       split_file=lambda branchfile: branchfile.split('/',1),
4024                      )
4025 c['change_source'] = s
4026 @end example
4028 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
4029 @section BonsaiPoller
4031 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
4033 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
4034 CGI script accessed through a web server that provides information
4035 about a CVS tree, for example the Mozilla bonsai server at
4036 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
4037 humans and machines. In this case, the buildbot's change source forms
4038 a query which asks about any files in the specified branch which have
4039 changed since the last query.
4041 Please take a look at the BonsaiPoller docstring for details about the
4042 arguments it accepts.
4045 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
4046 @section SVNPoller
4048 @csindex buildbot.changes.svnpoller.SVNPoller
4050 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
4051 which periodically polls a @uref{http://subversion.tigris.org/,
4052 Subversion} repository for new revisions, by running the @code{svn
4053 log} command in a subshell. It can watch a single branch or multiple
4054 branches.
4056 @code{SVNPoller} accepts the following arguments:
4058 @table @code
4059 @item svnurl
4060 The base URL path to watch, like
4061 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
4062 @code{http://divmod.org/svn/Divmod/}, or even
4063 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
4064 include the access scheme, the location of the repository (both the
4065 hostname for remote ones, and any additional directory names necessary
4066 to get to the repository), and the sub-path within the repository's
4067 virtual filesystem for the project and branch of interest.
4069 The @code{SVNPoller} will only pay attention to files inside the
4070 subdirectory specified by the complete svnurl.
4072 @item split_file
4073 A function to convert pathnames into (branch, relative_pathname)
4074 tuples. Use this to explain your repository's branch-naming policy to
4075 @code{SVNPoller}. This function must accept a single string and return
4076 a two-entry tuple. There are a few utility functions in
4077 @code{buildbot.changes.svnpoller} that can be used as a
4078 @code{split_file} function, see below for details.
4080 The default value always returns (None, path), which indicates that
4081 all files are on the trunk.
4083 Subclasses of @code{SVNPoller} can override the @code{split_file}
4084 method instead of using the @code{split_file=} argument.
4086 @item svnuser
4087 An optional string parameter. If set, the @code{--user} argument will
4088 be added to all @code{svn} commands. Use this if you have to
4089 authenticate to the svn server before you can do @code{svn info} or
4090 @code{svn log} commands.
4092 @item svnpasswd
4093 Like @code{svnuser}, this will cause a @code{--password} argument to
4094 be passed to all svn commands.
4096 @item pollinterval
4097 How often to poll, in seconds. Defaults to 600 (checking once every 10
4098 minutes). Lower this if you want the buildbot to notice changes
4099 faster, raise it if you want to reduce the network and CPU load on
4100 your svn server. Please be considerate of public SVN repositories by
4101 using a large interval when polling them.
4103 @item histmax
4104 The maximum number of changes to inspect at a time. Every POLLINTERVAL
4105 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
4106 looks through them for any ones it does not already know about. If
4107 more than HISTMAX revisions have been committed since the last poll,
4108 older changes will be silently ignored. Larger values of histmax will
4109 cause more time and memory to be consumed on each poll attempt.
4110 @code{histmax} defaults to 100.
4112 @item svnbin
4113 This controls the @code{svn} executable to use. If subversion is
4114 installed in a weird place on your system (outside of the
4115 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
4116 to find it. The default value of ``svn'' will almost always be
4117 sufficient.
4119 @end table
4121 @heading Branches
4123 Each source file that is tracked by a Subversion repository has a
4124 fully-qualified SVN URL in the following form:
4125 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
4126 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
4127 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
4128 string. The @code{SVNPoller} is responsible for producing Changes that
4129 contain a branch name and a FILEPATH (which is relative to the top of
4130 a checked-out tree). The details of how these strings are split up
4131 depend upon how your repository names its branches.
4133 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
4135 One common layout is to have all the various projects that share a
4136 repository get a single top-level directory each. Then under a given
4137 project's directory, you get two subdirectories, one named ``trunk''
4138 and another named ``branches''. Under ``branches'' you have a bunch of
4139 other directories, one per branch, with names like ``1.5.x'' and
4140 ``testing''. It is also common to see directories like ``tags'' and
4141 ``releases'' next to ``branches'' and ``trunk''.
4143 For example, the Twisted project has a subversion server on
4144 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
4145 repository is available through a SCHEME of ``svn:''. The primary
4146 sub-project is Twisted, of course, with a repository root of
4147 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
4148 Informant, with a root of
4149 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
4150 checked-out Twisted tree, there is a file named bin/trial (which is
4151 used to run unit test suites).
4153 The trunk for Twisted is in
4154 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
4155 fully-qualified SVN URL for the trunk version of @code{trial} would be
4156 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
4157 SVNURL for that file on a branch named ``1.5.x'' would be
4158 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
4160 To set up a @code{SVNPoller} that watches the Twisted trunk (and
4161 nothing else), we would use the following:
4163 @example
4164 from buildbot.changes.svnpoller import SVNPoller
4165 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
4166 @end example
4168 In this case, every Change that our @code{SVNPoller} produces will
4169 have @code{.branch=None}, to indicate that the Change is on the trunk.
4170 No other sub-projects or branches will be tracked.
4172 If we want our ChangeSource to follow multiple branches, we have to do
4173 two things. First we have to change our @code{svnurl=} argument to
4174 watch more than just ``.../Twisted/trunk''. We will set it to
4175 ``.../Twisted'' so that we'll see both the trunk and all the branches.
4176 Second, we have to tell @code{SVNPoller} how to split the
4177 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
4178 out into (BRANCH) and (FILEPATH) pairs.
4180 We do the latter by providing a ``split_file'' function. This function
4181 is responsible for splitting something like
4182 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
4183 @code{filepath}=''bin/trial''. This function is always given a string
4184 that names a file relative to the subdirectory pointed to by the
4185 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
4186 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
4187 branch indicated), or None to indicate that the file is outside any
4188 project of interest.
4190 (note that we want to see ``branches/1.5.x'' rather than just
4191 ``1.5.x'' because when we perform the SVN checkout, we will probably
4192 append the branch name to the baseURL, which requires that we keep the
4193 ``branches'' component in there. Other VC schemes use a different
4194 approach towards branches and may not require this artifact.)
4196 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
4197 scheme, the following function will work:
4199 @example
4200 def split_file_branches(path):
4201     pieces = path.split('/')
4202     if pieces[0] == 'trunk':
4203         return (None, '/'.join(pieces[1:]))
4204     elif pieces[0] == 'branches':
4205         return ('/'.join(pieces[0:2]),
4206                 '/'.join(pieces[2:]))
4207     else:
4208         return None
4209 @end example
4211 This function is provided as
4212 @code{buildbot.changes.svnpoller.split_file_branches} for your
4213 convenience. So to have our Twisted-watching @code{SVNPoller} follow
4214 multiple branches, we would use this:
4216 @example
4217 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
4218 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
4219                                split_file=split_file_branches)
4220 @end example
4222 Changes for all sorts of branches (with names like ``branches/1.5.x'',
4223 and None to indicate the trunk) will be delivered to the Schedulers.
4224 Each Scheduler is then free to use or ignore each branch as it sees
4225 fit.
4227 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
4229 Another common way to organize a Subversion repository is to put the
4230 branch name at the top, and the projects underneath. This is
4231 especially frequent when there are a number of related sub-projects
4232 that all get released in a group.
4234 For example, Divmod.org hosts a project named ``Nevow'' as well as one
4235 named ``Quotient''. In a checked-out Nevow tree there is a directory
4236 named ``formless'' that contains a python source file named
4237 ``webform.py''. This repository is accessible via webdav (and thus
4238 uses an ``http:'' scheme) through the divmod.org hostname. There are
4239 many branches in this repository, and they use a
4240 (BRANCHNAME)/(PROJECT) naming policy.
4242 The fully-qualified SVN URL for the trunk version of webform.py is
4243 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
4244 You can do an @code{svn co} with that URL and get a copy of the latest
4245 version. The 1.5.x branch version of this file would have a URL of
4246 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
4247 The whole Nevow trunk would be checked out with
4248 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
4249 trunk would be checked out using
4250 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
4252 Now suppose we want to have an @code{SVNPoller} that only cares about
4253 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
4254 described earlier:
4256 @example
4257 from buildbot.changes.svnpoller import SVNPoller
4258 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
4259 @end example
4261 But what happens when we want to track multiple Nevow branches? We
4262 have to point our @code{svnurl=} high enough to see all those
4263 branches, but we also don't want to include Quotient changes (since
4264 we're only building Nevow). To accomplish this, we must rely upon the
4265 @code{split_file} function to help us tell the difference between
4266 files that belong to Nevow and those that belong to Quotient, as well
4267 as figuring out which branch each one is on.
4269 @example
4270 from buildbot.changes.svnpoller import SVNPoller
4271 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
4272                                split_file=my_file_splitter)
4273 @end example
4275 The @code{my_file_splitter} function will be called with
4276 repository-relative pathnames like:
4278 @table @code
4279 @item trunk/Nevow/formless/webform.py
4280 This is a Nevow file, on the trunk. We want the Change that includes this
4281 to see a filename of @code{formless/webform.py"}, and a branch of None
4283 @item branches/1.5.x/Nevow/formless/webform.py
4284 This is a Nevow file, on a branch. We want to get
4285 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
4287 @item trunk/Quotient/setup.py
4288 This is a Quotient file, so we want to ignore it by having
4289 @code{my_file_splitter} return None.
4291 @item branches/1.5.x/Quotient/setup.py
4292 This is also a Quotient file, which should be ignored.
4293 @end table
4295 The following definition for @code{my_file_splitter} will do the job:
4297 @example
4298 def my_file_splitter(path):
4299     pieces = path.split('/')
4300     if pieces[0] == 'trunk':
4301         branch = None
4302         pieces.pop(0) # remove 'trunk'
4303     elif pieces[0] == 'branches':
4304         pieces.pop(0) # remove 'branches'
4305         # grab branch name
4306         branch = 'branches/' + pieces.pop(0)
4307     else:
4308         return None # something weird
4309     projectname = pieces.pop(0)
4310     if projectname != 'Nevow':
4311         return None # wrong project
4312     return (branch, '/'.join(pieces))
4313 @end example
4315 @node MercurialHook,  Bzr Hook, SVNPoller, Getting Source Code Changes
4316 @section MercurialHook
4318 Since Mercurial is written in python, the hook script can invoke
4319 Buildbot's @code{sendchange} function directly, rather than having to
4320 spawn an external process. This function delivers the same sort of
4321 changes as @code{buildbot sendchange} and the various hook scripts in
4322 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
4323 buildmaster to receive these changes.
4325 To set this up, first choose a Mercurial repository that represents
4326 your central ``official'' source tree. This will be the same
4327 repository that your buildslaves will eventually pull from. Install
4328 Buildbot on the machine that hosts this repository, using the same
4329 version of python as Mercurial is using (so that the Mercurial hook
4330 can import code from buildbot). Then add the following to the
4331 @code{.hg/hgrc} file in that repository, replacing the buildmaster
4332 hostname/portnumber as appropriate for your buildbot:
4334 @example
4335 [hooks]
4336 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
4338 [hgbuildbot]
4339 master = buildmaster.example.org:9987
4340 @end example
4342 (Note that Mercurial lets you define multiple @code{changegroup} hooks
4343 by giving them distinct names, like @code{changegroup.foo} and
4344 @code{changegroup.bar}, which is why we use
4345 @code{changegroup.buildbot} in this example. There is nothing magical
4346 about the ``buildbot'' suffix in the hook name. The
4347 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
4348 only section that the buildbot hook pays attention to.)
4350 Also note that this runs as a @code{changegroup} hook, rather than as
4351 an @code{incoming} hook. The @code{changegroup} hook is run with
4352 multiple revisions at a time (say, if multiple revisions are being
4353 pushed to this repository in a single @command{hg push} command),
4354 whereas the @code{incoming} hook is run with just one revision at a
4355 time. The @code{hgbuildbot.hook} function will only work with the
4356 @code{changegroup} hook.
4358 The @code{[hgbuildbot]} section has two other parameters that you
4359 might specify, both of which control the name of the branch that is
4360 attached to the changes coming from this hook.
4362 One common branch naming policy for Mercurial repositories is to use
4363 it just like Darcs: each branch goes into a separate repository, and
4364 all the branches for a single project share a common parent directory.
4365 For example, you might have @file{/var/repos/PROJECT/trunk/} and
4366 @file{/var/repos/PROJECT/release}. To use this style, use the
4367 @code{branchtype = dirname} setting, which simply uses the last
4368 component of the repository's enclosing directory as the branch name:
4370 @example
4371 [hgbuildbot]
4372 master = buildmaster.example.org:9987
4373 branchtype = dirname
4374 @end example
4376 Another approach is to use Mercurial's built-in branches (the kind
4377 created with @command{hg branch} and listed with @command{hg
4378 branches}). This feature associates persistent names with particular
4379 lines of descent within a single repository. (note that the buildbot
4380 @code{source.Mercurial} checkout step does not yet support this kind
4381 of branch). To have the commit hook deliver this sort of branch name
4382 with the Change object, use @code{branchtype = inrepo}:
4384 @example
4385 [hgbuildbot]
4386 master = buildmaster.example.org:9987
4387 branchtype = inrepo
4388 @end example
4390 Finally, if you want to simply specify the branchname directly, for
4391 all changes, use @code{branch = BRANCHNAME}. This overrides
4392 @code{branchtype}:
4394 @example
4395 [hgbuildbot]
4396 master = buildmaster.example.org:9987
4397 branch = trunk
4398 @end example
4400 If you use @code{branch=} like this, you'll need to put a separate
4401 .hgrc in each repository. If you use @code{branchtype=}, you may be
4402 able to use the same .hgrc for all your repositories, stored in
4403 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
4406 @node Bzr Hook, Bzr Poller, MercurialHook, Getting Source Code Changes
4407 @section Bzr Hook
4409 Bzr is also written in Python, and the Bzr hook depends on Twisted to send the
4410 changes.
4412 To install, put @code{contrib/bzr_buildbot.py} in one of your plugins
4413 locations a bzr plugins directory (e.g.,
4414 @code{~/.bazaar/plugins}). Then, in one of your bazaar conf files (e.g.,
4415 @code{~/.bazaar/locations.conf}), set the location you want to connect with buildbot
4416 with these keys:
4418 @table @code
4419 @item buildbot_on
4420 one of 'commit', 'push, or 'change'. Turns the plugin on to report changes via
4421 commit, changes via push, or any changes to the trunk. 'change' is
4422 recommended.
4424 @item buildbot_server
4425 (required to send to a buildbot master) the URL of the buildbot master to
4426 which you will connect (as of this writing, the same server and port to which
4427 slaves connect).
4429 @item buildbot_port
4430 (optional, defaults to 9989) the port of the buildbot master to which you will
4431 connect (as of this writing, the same server and port to which slaves connect)
4433 @item buildbot_pqm
4434 (optional, defaults to not pqm) Normally, the user that commits the revision
4435 is the user that is responsible for the change. When run in a pqm (Patch Queue
4436 Manager, see https://launchpad.net/pqm) environment, the user that commits is
4437 the Patch Queue Manager, and the user that committed the *parent* revision is
4438 responsible for the change. To turn on the pqm mode, set this value to any of
4439 (case-insensitive) "Yes", "Y", "True", or "T".
4441 @item buildbot_dry_run
4442 (optional, defaults to not a dry run) Normally, the post-commit hook will
4443 attempt to communicate with the configured buildbot server and port. If this
4444 parameter is included and any of (case-insensitive) "Yes", "Y", "True", or
4445 "T", then the hook will simply print what it would have sent, but not attempt
4446 to contact the buildbot master.
4448 @item buildbot_send_branch_name
4449 (optional, defaults to not sending the branch name) If your buildbot's bzr
4450 source build step uses a repourl, do *not* turn this on. If your buildbot's
4451 bzr build step uses a baseURL, then you may set this value to any of
4452 (case-insensitive) "Yes", "Y", "True", or "T" to have the buildbot master
4453 append the branch name to the baseURL.
4455 @end table
4457 When buildbot no longer has a hardcoded password, it will be a configuration
4458 option here as well.
4460 Here's a simple example that you might have in your
4461 @code{~/.bazaar/locations.conf}.
4463 @example
4464 [chroot-*:///var/local/myrepo/mybranch]
4465 buildbot_on = change
4466 buildbot_server = localhost
4467 @end example
4469 @node Bzr Poller, , Bzr Hook, Getting Source Code Changes
4470 @section Bzr Poller
4472 If you cannot insert a Bzr hook in the server, you can use the Bzr Poller. To
4473 use, put @code{contrib/bzr_buildbot.py} somewhere that your buildbot
4474 configuration can import it. Even putting it in the same directory as the master.cfg
4475 should work. Install the poller in the buildbot configuration as with any
4476 other change source. Minimally, provide a URL that you want to poll (bzr://,
4477 bzr+ssh://, or lp:), though make sure the buildbot user has necessary
4478 privileges. You may also want to specify these optional values.
4480 @table @code
4481 @item poll_interval
4482 The number of seconds to wait between polls.  Defaults to 10 minutes.
4484 @item branch_name
4485 Any value to be used as the branch name. Defaults to None, or specify a
4486 string, or specify the constants from @code{bzr_buildbot.py} SHORT or FULL to
4487 get the short branch name or full branch address.
4489 @item blame_merge_author
4490 normally, the user that commits the revision is the user that is responsible
4491 for the change. When run in a pqm (Patch Queue Manager, see
4492 https://launchpad.net/pqm) environment, the user that commits is the Patch
4493 Queue Manager, and the user that committed the merged, *parent* revision is
4494 responsible for the change. set this value to True if this is pointed against
4495 a PQM-managed branch.
4496 @end table
4498 @node Build Process, Status Delivery, Getting Source Code Changes, Top
4499 @chapter Build Process
4501 A @code{Build} object is responsible for actually performing a build.
4502 It gets access to a remote @code{SlaveBuilder} where it may run
4503 commands, and a @code{BuildStatus} object where it must emit status
4504 events. The @code{Build} is created by the Builder's
4505 @code{BuildFactory}.
4507 The default @code{Build} class is made up of a fixed sequence of
4508 @code{BuildSteps}, executed one after another until all are complete
4509 (or one of them indicates that the build should be halted early). The
4510 default @code{BuildFactory} creates instances of this @code{Build}
4511 class with a list of @code{BuildSteps}, so the basic way to configure
4512 the build is to provide a list of @code{BuildSteps} to your
4513 @code{BuildFactory}.
4515 More complicated @code{Build} subclasses can make other decisions:
4516 execute some steps only if certain files were changed, or if certain
4517 previous steps passed or failed. The base class has been written to
4518 allow users to express basic control flow without writing code, but
4519 you can always subclass and customize to achieve more specialized
4520 behavior.
4522 @menu
4523 * Build Steps::
4524 * Interlocks::
4525 * Build Factories::
4526 @end menu
4528 @node Build Steps, Interlocks, Build Process, Build Process
4529 @section Build Steps
4531 @code{BuildStep}s are usually specified in the buildmaster's
4532 configuration file, in a list that goes into the @code{BuildFactory}.
4533 The @code{BuildStep} instances in this list are used as templates to
4534 construct new independent copies for each build (so that state can be
4535 kept on the @code{BuildStep} in one build without affecting a later
4536 build). Each @code{BuildFactory} can be created with a list of steps,
4537 or the factory can be created empty and then steps added to it using
4538 the @code{addStep} method:
4540 @example
4541 from buildbot.steps import source, shell
4542 from buildbot.process import factory
4544 f = factory.BuildFactory()
4545 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
4546 f.addStep(shell.ShellCommand(command=["make", "all"]))
4547 f.addStep(shell.ShellCommand(command=["make", "test"]))
4548 @end example
4550 In earlier versions (0.7.5 and older), these steps were specified with
4551 a tuple of (step_class, keyword_arguments). Steps can still be
4552 specified this way, but the preferred form is to pass actual
4553 @code{BuildStep} instances to @code{addStep}, because that gives the
4554 @code{BuildStep} class a chance to do some validation on the
4555 arguments.
4557 If you have a common set of steps which are used in several factories, the
4558 @code{addSteps} method may be handy.  It takes an iterable of @code{BuildStep}
4559 instances.
4561 @example
4562 setup_steps = [
4563     source.SVN(svnurl="http://svn.example.org/Trunk/")
4564     shell.ShellCommand(command="./setup")
4566 quick = factory.BuildFactory()
4567 quick.addSteps(setup_steps)
4568 quick.addStep(shell.shellCommand(command="make quick"))
4569 @end example
4571 The rest of this section lists all the standard BuildStep objects
4572 available for use in a Build, and the parameters which can be used to
4573 control each.
4575 @menu
4576 * Common Parameters::
4577 * Using Build Properties::
4578 * Source Checkout::
4579 * ShellCommand::
4580 * Simple ShellCommand Subclasses::
4581 * Python BuildSteps::
4582 * Transferring Files::
4583 * Steps That Run on the Master::
4584 * Triggering Schedulers::
4585 * Writing New BuildSteps::
4586 @end menu
4588 @node Common Parameters, Using Build Properties, Build Steps, Build Steps
4589 @subsection Common Parameters
4591 The standard @code{Build} runs a series of @code{BuildStep}s in order,
4592 only stopping when it runs out of steps or if one of them requests
4593 that the build be halted. It collects status information from each one
4594 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
4596 All BuildSteps accept some common parameters. Some of these control
4597 how their individual status affects the overall build. Others are used
4598 to specify which @code{Locks} (see @pxref{Interlocks}) should be
4599 acquired before allowing the step to run.
4601 Arguments common to all @code{BuildStep} subclasses:
4604 @table @code
4605 @item name
4606 the name used to describe the step on the status display. It is also
4607 used to give a name to any LogFiles created by this step.
4609 @item haltOnFailure
4610 if True, a FAILURE of this build step will cause the build to halt
4611 immediately. Steps with @code{alwaysRun=True} are still run. Generally
4612 speaking, haltOnFailure implies flunkOnFailure (the default for most
4613 BuildSteps). In some cases, particularly series of tests, it makes sense
4614 to haltOnFailure if something fails early on but not flunkOnFailure.
4615 This can be achieved with haltOnFailure=True, flunkOnFailure=False.
4617 @item flunkOnWarnings
4618 when True, a WARNINGS or FAILURE of this build step will mark the
4619 overall build as FAILURE. The remaining steps will still be executed.
4621 @item flunkOnFailure
4622 when True, a FAILURE of this build step will mark the overall build as
4623 a FAILURE. The remaining steps will still be executed.
4625 @item warnOnWarnings
4626 when True, a WARNINGS or FAILURE of this build step will mark the
4627 overall build as having WARNINGS. The remaining steps will still be
4628 executed.
4630 @item warnOnFailure
4631 when True, a FAILURE of this build step will mark the overall build as
4632 having WARNINGS. The remaining steps will still be executed.
4634 @item alwaysRun
4635 if True, this build step will always be run, even if a previous buildstep
4636 with @code{haltOnFailure=True} has failed.
4638 @item locks
4639 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
4640 @code{buildbot.locks.MasterLock}) that should be acquired before
4641 starting this Step. The Locks will be released when the step is
4642 complete. Note that this is a list of actual Lock instances, not
4643 names. Also note that all Locks must have unique names.
4645 @end table
4647 @node Using Build Properties, Source Checkout, Common Parameters, Build Steps
4648 @subsection Using Build Properties
4649 @cindex Properties
4651 Build properties are a generalized way to provide configuration
4652 information to build steps; see @ref{Build Properties}.
4654 Some build properties are inherited from external sources -- global
4655 properties, schedulers, or buildslaves.  Some build properties are
4656 set when the build starts, such as the SourceStamp information. Other
4657 properties can be set by BuildSteps as they run, for example the
4658 various Source steps will set the @code{got_revision} property to the
4659 source revision that was actually checked out (which can be useful
4660 when the SourceStamp in use merely requested the ``latest revision'':
4661 @code{got_revision} will tell you what was actually built).
4663 In custom BuildSteps, you can get and set the build properties with
4664 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4665 for the name of the property, and returns or accepts an
4666 arbitrary@footnote{Build properties are serialized along with the
4667 build results, so they must be serializable. For this reason, the
4668 value of any build property should be simple inert data: strings,
4669 numbers, lists, tuples, and dictionaries. They should not contain
4670 class instances.} object. For example:
4672 @example
4673 class MakeTarball(ShellCommand):
4674     def start(self):
4675         if self.getProperty("os") == "win":
4676             self.setCommand([ ... ]) # windows-only command
4677         else:
4678             self.setCommand([ ... ]) # equivalent for other systems
4679         ShellCommand.start(self)
4680 @end example
4682 @heading WithProperties
4683 @cindex WithProperties
4685 You can use build properties in ShellCommands by using the
4686 @code{WithProperties} wrapper when setting the arguments of
4687 the ShellCommand. This interpolates the named build properties
4688 into the generated shell command.  Most step parameters accept
4689 @code{WithProperties}.  Please file bugs for any parameters which
4690 do not.
4692 @example
4693 from buildbot.steps.shell import ShellCommand
4694 from buildbot.process.properties import WithProperties
4696 f.addStep(ShellCommand(
4697           command=["tar", "czf",
4698                    WithProperties("build-%s.tar.gz", "revision"),
4699                    "source"]))
4700 @end example
4702 If this BuildStep were used in a tree obtained from Subversion, it
4703 would create a tarball with a name like @file{build-1234.tar.gz}.
4705 The @code{WithProperties} function does @code{printf}-style string
4706 interpolation, using strings obtained by calling
4707 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4708 @code{%d}, etc), you must have exactly one additional argument to
4709 indicate which build property you want to insert.
4711 You can also use python dictionary-style string interpolation by using
4712 the @code{%(propname)s} syntax. In this form, the property name goes
4713 in the parentheses, and WithProperties takes @emph{no} additional
4714 arguments:
4716 @example
4717 f.addStep(ShellCommand(
4718           command=["tar", "czf",
4719                    WithProperties("build-%(revision)s.tar.gz"),
4720                    "source"]))
4721 @end example
4723 Don't forget the extra ``s'' after the closing parenthesis! This is
4724 the cause of many confusing errors.
4726 The dictionary-style interpolation supports a number of more advanced
4727 syntaxes, too.
4729 @table @code
4731 @item propname:-replacement
4732 If @code{propname} exists, substitute its value; otherwise,
4733 substitute @code{replacement}.  @code{replacement} may be empty
4734 (@code{%(propname:-)s})
4736 @item propname:+replacement
4737 If @code{propname} exists, substitute @code{replacement}; otherwise,
4738 substitute an empty string.
4740 @end table
4742 Although these are similar to shell substitutions, no other
4743 substitutions are currently supported, and @code{replacement} in the
4744 above cannot contain more substitutions.
4746 Note: like python, you can either do positional-argument interpolation
4747 @emph{or} keyword-argument interpolation, not both. Thus you cannot use
4748 a string like @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4750 @heading Common Build Properties
4752 The following build properties are set when the build is started, and
4753 are available to all steps.
4755 @table @code
4756 @item branch
4758 This comes from the build's SourceStamp, and describes which branch is
4759 being checked out. This will be @code{None} (which interpolates into
4760 @code{WithProperties} as an empty string) if the build is on the
4761 default branch, which is generally the trunk. Otherwise it will be a
4762 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4763 system being used.
4765 @item revision
4767 This also comes from the SourceStamp, and is the revision of the
4768 source code tree that was requested from the VC system. When a build
4769 is requested of a specific revision (as is generally the case when
4770 the build is triggered by Changes), this will contain the revision
4771 specification. The syntax depends upon the VC system in use: for SVN
4772 it is an integer, for Mercurial it is a short string, for Darcs it
4773 is a rather large string, etc.
4775 If the ``force build'' button was pressed, the revision will be
4776 @code{None}, which means to use the most recent revision available.
4777 This is a ``trunk build''. This will be interpolated as an empty
4778 string.
4780 @item got_revision
4782 This is set when a Source step checks out the source tree, and
4783 provides the revision that was actually obtained from the VC system.
4784 In general this should be the same as @code{revision}, except for
4785 trunk builds, where @code{got_revision} indicates what revision was
4786 current when the checkout was performed. This can be used to rebuild
4787 the same source code later.
4789 Note that for some VC systems (Darcs in particular), the revision is a
4790 large string containing newlines, and is not suitable for interpolation
4791 into a filename.
4793 @item buildername
4795 This is a string that indicates which Builder the build was a part of.
4796 The combination of buildername and buildnumber uniquely identify a
4797 build.
4799 @item buildnumber
4801 Each build gets a number, scoped to the Builder (so the first build
4802 performed on any given Builder will have a build number of 0). This
4803 integer property contains the build's number.
4805 @item slavename
4807 This is a string which identifies which buildslave the build is
4808 running on.
4810 @item scheduler
4812 If the build was started from a scheduler, then this property will
4813 contain the name of that scheduler.
4815 @end table
4818 @node Source Checkout, ShellCommand, Using Build Properties, Build Steps
4819 @subsection Source Checkout
4821 The first step of any build is typically to acquire the source code
4822 from which the build will be performed. There are several classes to
4823 handle this, one for each of the different source control system that
4824 Buildbot knows about. For a description of how Buildbot treats source
4825 control in general, see @ref{Version Control Systems}.
4827 All source checkout steps accept some common parameters to control how
4828 they get the sources and where they should be placed. The remaining
4829 per-VC-system parameters are mostly to specify where exactly the
4830 sources are coming from.
4832 @table @code
4833 @item mode
4835 a string describing the kind of VC operation that is desired. Defaults
4836 to @code{update}.
4838 @table @code
4839 @item update
4840 specifies that the CVS checkout/update should be performed directly
4841 into the workdir. Each build is performed in the same directory,
4842 allowing for incremental builds. This minimizes disk space, bandwidth,
4843 and CPU time. However, it may encounter problems if the build process
4844 does not handle dependencies properly (sometimes you must do a ``clean
4845 build'' to make sure everything gets compiled), or if source files are
4846 deleted but generated files can influence test behavior (e.g. python's
4847 .pyc files), or when source directories are deleted but generated
4848 files prevent CVS from removing them. Builds ought to be correct
4849 regardless of whether they are done ``from scratch'' or incrementally,
4850 but it is useful to test both kinds: this mode exercises the
4851 incremental-build style.
4853 @item copy
4854 specifies that the CVS workspace should be maintained in a separate
4855 directory (called the 'copydir'), using checkout or update as
4856 necessary. For each build, a new workdir is created with a copy of the
4857 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
4858 disk space required, but keeps the bandwidth low (update instead of a
4859 full checkout). A full 'clean' build is performed each time. This
4860 avoids any generated-file build problems, but is still occasionally
4861 vulnerable to CVS problems such as a repository being manually
4862 rearranged, causing CVS errors on update which are not an issue with a
4863 full checkout.
4865 @c TODO: something is screwy about this, revisit. Is it the source
4866 @c directory or the working directory that is deleted each time?
4868 @item clobber
4869 specifes that the working directory should be deleted each time,
4870 necessitating a full checkout for each build. This insures a clean
4871 build off a complete checkout, avoiding any of the problems described
4872 above. This mode exercises the ``from-scratch'' build style.
4874 @item export
4875 this is like @code{clobber}, except that the 'cvs export' command is
4876 used to create the working directory. This command removes all CVS
4877 metadata files (the CVS/ directories) from the tree, which is
4878 sometimes useful for creating source tarballs (to avoid including the
4879 metadata in the tar file).
4880 @end table
4882 @item workdir
4883 like all Steps, this indicates the directory where the build will take
4884 place. Source Steps are special in that they perform some operations
4885 outside of the workdir (like creating the workdir itself).
4887 @item alwaysUseLatest
4888 if True, bypass the usual ``update to the last Change'' behavior, and
4889 always update to the latest changes instead.
4891 @item retry
4892 If set, this specifies a tuple of @code{(delay, repeats)} which means
4893 that when a full VC checkout fails, it should be retried up to
4894 @var{repeats} times, waiting @var{delay} seconds between attempts. If
4895 you don't provide this, it defaults to @code{None}, which means VC
4896 operations should not be retried. This is provided to make life easier
4897 for buildslaves which are stuck behind poor network connections.
4899 @end table
4902 My habit as a developer is to do a @code{cvs update} and @code{make} each
4903 morning. Problems can occur, either because of bad code being checked in, or
4904 by incomplete dependencies causing a partial rebuild to fail where a
4905 complete from-scratch build might succeed. A quick Builder which emulates
4906 this incremental-build behavior would use the @code{mode='update'}
4907 setting.
4909 On the other hand, other kinds of dependency problems can cause a clean
4910 build to fail where a partial build might succeed. This frequently results
4911 from a link step that depends upon an object file that was removed from a
4912 later version of the tree: in the partial tree, the object file is still
4913 around (even though the Makefiles no longer know how to create it).
4915 ``official'' builds (traceable builds performed from a known set of
4916 source revisions) are always done as clean builds, to make sure it is
4917 not influenced by any uncontrolled factors (like leftover files from a
4918 previous build). A ``full'' Builder which behaves this way would want
4919 to use the @code{mode='clobber'} setting.
4921 Each VC system has a corresponding source checkout class: their
4922 arguments are described on the following pages.
4925 @menu
4926 * CVS::
4927 * SVN::
4928 * Darcs::
4929 * Mercurial::
4930 * Arch::
4931 * Bazaar::
4932 * Bzr::
4933 * P4::
4934 * Git::
4935 @end menu
4937 @node CVS, SVN, Source Checkout, Source Checkout
4938 @subsubsection CVS
4939 @cindex CVS Checkout
4940 @bsindex buildbot.steps.source.CVS
4943 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
4944 CVS} checkout or update. It takes the following arguments:
4946 @table @code
4947 @item cvsroot
4948 (required): specify the CVSROOT value, which points to a CVS
4949 repository, probably on a remote machine. For example, the cvsroot
4950 value you would use to get a copy of the Buildbot source code is
4951 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
4953 @item cvsmodule
4954 (required): specify the cvs @code{module}, which is generally a
4955 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
4956 code is @code{buildbot}.
4958 @item branch
4959 a string which will be used in a @code{-r} argument. This is most
4960 useful for specifying a branch to work on. Defaults to @code{HEAD}.
4962 @item global_options
4963 a list of flags to be put before the verb in the CVS command.
4965 @item checkoutDelay
4966 if set, the number of seconds to put between the timestamp of the last
4967 known Change and the value used for the @code{-D} option. Defaults to
4968 half of the parent Build's treeStableTimer.
4970 @end table
4973 @node SVN, Darcs, CVS, Source Checkout
4974 @subsubsection SVN
4976 @cindex SVN Checkout
4977 @bsindex buildbot.steps.source.SVN
4980 The @code{SVN} build step performs a
4981 @uref{http://subversion.tigris.org, Subversion} checkout or update.
4982 There are two basic ways of setting up the checkout step, depending
4983 upon whether you are using multiple branches or not.
4985 If all of your builds use the same branch, then you should create the
4986 @code{SVN} step with the @code{svnurl} argument:
4988 @table @code
4989 @item svnurl
4990 (required): this specifies the @code{URL} argument that will be given
4991 to the @code{svn checkout} command. It dictates both where the
4992 repository is located and which sub-tree should be extracted. In this
4993 respect, it is like a combination of the CVS @code{cvsroot} and
4994 @code{cvsmodule} arguments. For example, if you are using a remote
4995 Subversion repository which is accessible through HTTP at a URL of
4996 @code{http://svn.example.com/repos}, and you wanted to check out the
4997 @code{trunk/calc} sub-tree, you would use
4998 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
4999 to your @code{SVN} step.
5000 @end table
5002 If, on the other hand, you are building from multiple branches, then
5003 you should create the @code{SVN} step with the @code{baseURL} and
5004 @code{defaultBranch} arguments instead:
5006 @table @code
5007 @item baseURL
5008 (required): this specifies the base repository URL, to which a branch
5009 name will be appended. It should probably end in a slash.
5011 @item defaultBranch
5012 this specifies the name of the branch to use when a Build does not
5013 provide one of its own. This will be appended to @code{baseURL} to
5014 create the string that will be passed to the @code{svn checkout}
5015 command.
5016 @end table
5018 If you are using branches, you must also make sure your
5019 @code{ChangeSource} will report the correct branch names.
5021 @heading branch example
5023 Let's suppose that the ``MyProject'' repository uses branches for the
5024 trunk, for various users' individual development efforts, and for
5025 several new features that will require some amount of work (involving
5026 multiple developers) before they are ready to merge onto the trunk.
5027 Such a repository might be organized as follows:
5029 @example
5030 svn://svn.example.org/MyProject/trunk
5031 svn://svn.example.org/MyProject/branches/User1/foo
5032 svn://svn.example.org/MyProject/branches/User1/bar
5033 svn://svn.example.org/MyProject/branches/User2/baz
5034 svn://svn.example.org/MyProject/features/newthing
5035 svn://svn.example.org/MyProject/features/otherthing
5036 @end example
5038 Further assume that we want the Buildbot to run tests against the
5039 trunk and against all the feature branches (i.e., do a
5040 checkout/compile/build of branch X when a file has been changed on
5041 branch X, when X is in the set [trunk, features/newthing,
5042 features/otherthing]). We do not want the Buildbot to automatically
5043 build any of the user branches, but it should be willing to build a
5044 user branch when explicitly requested (most likely by the user who
5045 owns that branch).
5047 There are three things that need to be set up to accomodate this
5048 system. The first is a ChangeSource that is capable of identifying the
5049 branch which owns any given file. This depends upon a user-supplied
5050 function, in an external program that runs in the SVN commit hook and
5051 connects to the buildmaster's @code{PBChangeSource} over a TCP
5052 connection. (you can use the ``@code{buildbot sendchange}'' utility
5053 for this purpose, but you will still need an external program to
5054 decide what value should be passed to the @code{--branch=} argument).
5055 For example, a change to a file with the SVN url of
5056 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
5057 be broken down into a Change instance with
5058 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
5060 The second piece is an @code{AnyBranchScheduler} which will pay
5061 attention to the desired branches. It will not pay attention to the
5062 user branches, so it will not automatically start builds in response
5063 to changes there. The AnyBranchScheduler class requires you to
5064 explicitly list all the branches you want it to use, but it would not
5065 be difficult to write a subclass which used
5066 @code{branch.startswith('features/'} to remove the need for this
5067 explicit list. Or, if you want to build user branches too, you can use
5068 AnyBranchScheduler with @code{branches=None} to indicate that you want
5069 it to pay attention to all branches.
5071 The third piece is an @code{SVN} checkout step that is configured to
5072 handle the branches correctly, with a @code{baseURL} value that
5073 matches the way the ChangeSource splits each file's URL into base,
5074 branch, and file.
5076 @example
5077 from buildbot.changes.pb import PBChangeSource
5078 from buildbot.scheduler import AnyBranchScheduler
5079 from buildbot.process import source, factory
5080 from buildbot.steps import source, shell
5082 c['change_source'] = PBChangeSource()
5083 s1 = AnyBranchScheduler('main',
5084                         ['trunk', 'features/newthing', 'features/otherthing'],
5085                         10*60, ['test-i386', 'test-ppc'])
5086 c['schedulers'] = [s1]
5088 f = factory.BuildFactory()
5089 f.addStep(source.SVN(mode='update',
5090                      baseURL='svn://svn.example.org/MyProject/',
5091                      defaultBranch='trunk'))
5092 f.addStep(shell.Compile(command="make all"))
5093 f.addStep(shell.Test(command="make test"))
5095 c['builders'] = [
5096   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
5097                        'factory':f @},
5098   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
5099                       'factory':f @},
5101 @end example
5103 In this example, when a change arrives with a @code{branch} attribute
5104 of ``trunk'', the resulting build will have an SVN step that
5105 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
5106 ``trunk'' (the branch name) to get the correct svn command. If the
5107 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
5108 will concatenate ``svn://svn.example.org/MyProject/'' with
5109 ``features/newthing'' to get the svnurl for checkout.
5111 @node Darcs, Mercurial, SVN, Source Checkout
5112 @subsubsection Darcs
5114 @cindex Darcs Checkout
5115 @bsindex buildbot.steps.source.Darcs
5118 The @code{Darcs} build step performs a
5119 @uref{http://darcs.net/, Darcs} checkout or update.
5121 Like @xref{SVN}, this step can either be configured to always check
5122 out a specific tree, or set up to pull from a particular branch that
5123 gets specified separately for each build. Also like SVN, the
5124 repository URL given to Darcs is created by concatenating a
5125 @code{baseURL} with the branch name, and if no particular branch is
5126 requested, it uses a @code{defaultBranch}. The only difference in
5127 usage is that each potential Darcs repository URL must point to a
5128 fully-fledged repository, whereas SVN URLs usually point to sub-trees
5129 of the main Subversion repository. In other words, doing an SVN
5130 checkout of @code{baseURL} is legal, but silly, since you'd probably
5131 wind up with a copy of every single branch in the whole repository.
5132 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
5133 the parent directory of a collection of Darcs repositories is not
5134 itself a valid repository.
5136 The Darcs step takes the following arguments:
5138 @table @code
5139 @item repourl
5140 (required unless @code{baseURL} is provided): the URL at which the
5141 Darcs source repository is available.
5143 @item baseURL
5144 (required unless @code{repourl} is provided): the base repository URL,
5145 to which a branch name will be appended. It should probably end in a
5146 slash.
5148 @item defaultBranch
5149 (allowed if and only if @code{baseURL} is provided): this specifies
5150 the name of the branch to use when a Build does not provide one of its
5151 own. This will be appended to @code{baseURL} to create the string that
5152 will be passed to the @code{darcs get} command.
5153 @end table
5155 @node Mercurial, Arch, Darcs, Source Checkout
5156 @subsubsection Mercurial
5158 @cindex Mercurial Checkout
5159 @bsindex buildbot.steps.source.Mercurial
5162 The @code{Mercurial} build step performs a
5163 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
5164 or update.
5166 Branches are handled just like @xref{Darcs}.
5168 The Mercurial step takes the following arguments:
5170 @table @code
5171 @item repourl
5172 (required unless @code{baseURL} is provided): the URL at which the
5173 Mercurial source repository is available.
5175 @item baseURL
5176 (required unless @code{repourl} is provided): the base repository URL,
5177 to which a branch name will be appended. It should probably end in a
5178 slash.
5180 @item defaultBranch
5181 (allowed if and only if @code{baseURL} is provided): this specifies
5182 the name of the branch to use when a Build does not provide one of its
5183 own. This will be appended to @code{baseURL} to create the string that
5184 will be passed to the @code{hg clone} command.
5185 @end table
5188 @node Arch, Bazaar, Mercurial, Source Checkout
5189 @subsubsection Arch
5191 @cindex Arch Checkout
5192 @bsindex buildbot.steps.source.Arch
5195 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
5196 Arch} checkout or update using the @code{tla} client. It takes the
5197 following arguments:
5199 @table @code
5200 @item url
5201 (required): this specifies the URL at which the Arch source archive is
5202 available.
5204 @item version
5205 (required): this specifies which ``development line'' (like a branch)
5206 should be used. This provides the default branch name, but individual
5207 builds may specify a different one.
5209 @item archive
5210 (optional): Each repository knows its own archive name. If this
5211 parameter is provided, it must match the repository's archive name.
5212 The parameter is accepted for compatibility with the @code{Bazaar}
5213 step, below.
5215 @end table
5217 @node Bazaar, Bzr, Arch, Source Checkout
5218 @subsubsection Bazaar
5220 @cindex Bazaar Checkout
5221 @bsindex buildbot.steps.source.Bazaar
5224 @code{Bazaar} is an alternate implementation of the Arch VC system,
5225 which uses a client named @code{baz}. The checkout semantics are just
5226 different enough from @code{tla} that there is a separate BuildStep for
5229 It takes exactly the same arguments as @code{Arch}, except that the
5230 @code{archive=} parameter is required. (baz does not emit the archive
5231 name when you do @code{baz register-archive}, so we must provide it
5232 ourselves).
5235 @node Bzr, P4, Bazaar, Source Checkout
5236 @subsubsection Bzr
5238 @cindex Bzr Checkout
5239 @bsindex buildbot.steps.source.Bzr
5241 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
5242 as simply ``Bazaar''. The repository-vs-workspace model is similar to
5243 Darcs, but it uses a strictly linear sequence of revisions (one
5244 history per branch) like Arch. Branches are put in subdirectories.
5245 This makes it look very much like Mercurial, so it takes the same
5246 arguments:
5248 @table @code
5250 @item repourl
5251 (required unless @code{baseURL} is provided): the URL at which the
5252 Bzr source repository is available.
5254 @item baseURL
5255 (required unless @code{repourl} is provided): the base repository URL,
5256 to which a branch name will be appended. It should probably end in a
5257 slash.
5259 @item defaultBranch
5260 (allowed if and only if @code{baseURL} is provided): this specifies
5261 the name of the branch to use when a Build does not provide one of its
5262 own. This will be appended to @code{baseURL} to create the string that
5263 will be passed to the @code{bzr checkout} command.
5264 @end table
5268 @node P4, Git, Bzr, Source Checkout
5269 @subsubsection P4
5271 @cindex Perforce Update
5272 @bsindex buildbot.steps.source.P4
5273 @c TODO @bsindex buildbot.steps.source.P4Sync
5276 The @code{P4} build step creates a @uref{http://www.perforce.com/,
5277 Perforce} client specification and performs an update.
5279 @table @code
5280 @item p4base
5281 A view into the Perforce depot without branch name or trailing "...".
5282 Typically "//depot/proj/".
5283 @item defaultBranch
5284 A branch name to append on build requests if none is specified.
5285 Typically "trunk".
5286 @item p4port
5287 (optional): the host:port string describing how to get to the P4 Depot
5288 (repository), used as the -p argument for all p4 commands.
5289 @item p4user
5290 (optional): the Perforce user, used as the -u argument to all p4
5291 commands.
5292 @item p4passwd
5293 (optional): the Perforce password, used as the -p argument to all p4
5294 commands.
5295 @item p4extra_views
5296 (optional): a list of (depotpath, clientpath) tuples containing extra
5297 views to be mapped into the client specification. Both will have
5298 "/..." appended automatically. The client name and source directory
5299 will be prepended to the client path.
5300 @item p4client
5301 (optional): The name of the client to use. In mode='copy' and
5302 mode='update', it's particularly important that a unique name is used
5303 for each checkout directory to avoid incorrect synchronization. For
5304 this reason, Python percent substitution will be performed on this value
5305 to replace %(slave)s with the slave name and %(builder)s with the
5306 builder name. The default is "buildbot_%(slave)s_%(build)s".
5307 @end table
5310 @node Git,  , P4, Source Checkout
5311 @subsubsection Git
5313 @cindex Git Checkout
5314 @bsindex buildbot.steps.source.Git
5316 The @code{Git} build step clones or updates a @uref{http://git.or.cz/,
5317 Git} repository and checks out the specified branch or revision. Note
5318 that the buildbot supports Git version 1.2.0 and later: earlier
5319 versions (such as the one shipped in Ubuntu 'Dapper') do not support
5320 the @command{git init} command that the buildbot uses.
5322 The Git step takes the following arguments:
5324 @table @code
5325 @item repourl
5326 (required): the URL of the upstream Git repository.
5328 @item branch
5329 (optional): this specifies the name of the branch to use when a Build
5330 does not provide one of its own. If this this parameter is not
5331 specified, and the Build does not provide a branch, the ``master''
5332 branch will be used.
5333 @end table
5336 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
5337 @subsection ShellCommand
5339 @bsindex buildbot.steps.shell.ShellCommand
5340 @c TODO @bsindex buildbot.steps.shell.TreeSize
5342 This is a useful base class for just about everything you might want
5343 to do during a build (except for the initial source checkout). It runs
5344 a single command in a child shell on the buildslave. All stdout/stderr
5345 is recorded into a LogFile. The step finishes with a status of FAILURE
5346 if the command's exit code is non-zero, otherwise it has a status of
5347 SUCCESS.
5349 The preferred way to specify the command is with a list of argv strings,
5350 since this allows for spaces in filenames and avoids doing any fragile
5351 shell-escaping. You can also specify the command with a single string, in
5352 which case the string is given to '/bin/sh -c COMMAND' for parsing.
5354 On Windows, commands are run via @code{cmd.exe /c} which works well. However,
5355 if you're running a batch file, the error level does not get propagated
5356 correctly unless you add 'call' before your batch file's name:
5357 @code{cmd=['call', 'myfile.bat', ...]}.
5359 All ShellCommands are run by default in the ``workdir'', which
5360 defaults to the ``@file{build}'' subdirectory of the slave builder's
5361 base directory. The absolute path of the workdir will thus be the
5362 slave's basedir (set as an option to @code{buildbot create-slave},
5363 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
5364 builder's @code{c['builddir']} key in master.cfg) plus the workdir
5365 itself (a class-level attribute of the BuildFactory, defaults to
5366 ``@file{build}'').
5368 @code{ShellCommand} arguments:
5370 @table @code
5371 @item command
5372 a list of strings (preferred) or single string (discouraged) which
5373 specifies the command to be run. A list of strings is preferred
5374 because it can be used directly as an argv array. Using a single
5375 string (with embedded spaces) requires the buildslave to pass the
5376 string to /bin/sh for interpretation, which raises all sorts of
5377 difficult questions about how to escape or interpret shell
5378 metacharacters.
5380 @item env
5381 a dictionary of environment strings which will be added to the child
5382 command's environment. For example, to run tests with a different i18n
5383 language setting, you might use
5385 @example
5386 f.addStep(ShellCommand(command=["make", "test"],
5387                        env=@{'LANG': 'fr_FR'@}))
5388 @end example
5390 These variable settings will override any existing ones in the
5391 buildslave's environment or the environment specified in the
5392 Builder. The exception is PYTHONPATH, which is merged
5393 with (actually prepended to) any existing $PYTHONPATH setting. The
5394 value is treated as a list of directories to prepend, and a single
5395 string is treated like a one-item list. For example, to prepend both
5396 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
5397 to any existing $PYTHONPATH setting, you would do something like the
5398 following:
5400 @example
5401 f.addStep(ShellCommand(
5402               command=["make", "test"],
5403               env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
5404                                    "/home/buildbot/lib/python"] @}))
5405 @end example
5407 @item want_stdout
5408 if False, stdout from the child process is discarded rather than being
5409 sent to the buildmaster for inclusion in the step's LogFile.
5411 @item want_stderr
5412 like @code{want_stdout} but for stderr. Note that commands run through
5413 a PTY do not have separate stdout/stderr streams: both are merged into
5414 stdout.
5416 @item logfiles
5417 Sometimes commands will log interesting data to a local file, rather
5418 than emitting everything to stdout or stderr. For example, Twisted's
5419 ``trial'' command (which runs unit tests) only presents summary
5420 information to stdout, and puts the rest into a file named
5421 @file{_trial_temp/test.log}. It is often useful to watch these files
5422 as the command runs, rather than using @command{/bin/cat} to dump
5423 their contents afterwards.
5425 The @code{logfiles=} argument allows you to collect data from these
5426 secondary logfiles in near-real-time, as the step is running. It
5427 accepts a dictionary which maps from a local Log name (which is how
5428 the log data is presented in the build results) to a remote filename
5429 (interpreted relative to the build's working directory). Each named
5430 file will be polled on a regular basis (every couple of seconds) as
5431 the build runs, and any new text will be sent over to the buildmaster.
5433 @example
5434 f.addStep(ShellCommand(
5435               command=["make", "test"],
5436               logfiles=@{"triallog": "_trial_temp/test.log"@}))
5437 @end example
5440 @item timeout
5441 if the command fails to produce any output for this many seconds, it
5442 is assumed to be locked up and will be killed.
5444 @item description
5445 This will be used to describe the command (on the Waterfall display)
5446 while the command is still running. It should be a single
5447 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
5448 form is a list of short strings, which allows the HTML Waterfall
5449 display to create narrower columns by emitting a <br> tag between each
5450 word. You may also provide a single string.
5452 @item descriptionDone
5453 This will be used to describe the command once it has finished. A
5454 simple noun like ``compile'' or ``tests'' should be used. Like
5455 @code{description}, this may either be a list of short strings or a
5456 single string.
5458 If neither @code{description} nor @code{descriptionDone} are set, the
5459 actual command arguments will be used to construct the description.
5460 This may be a bit too wide to fit comfortably on the Waterfall
5461 display.
5463 @example
5464 f.addStep(ShellCommand(command=["make", "test"],
5465                        description=["testing"],
5466                        descriptionDone=["tests"]))
5467 @end example
5469 @end table
5471 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
5472 @subsection Simple ShellCommand Subclasses
5474 Several subclasses of ShellCommand are provided as starting points for
5475 common build steps. These are all very simple: they just override a few
5476 parameters so you don't have to specify them yourself, making the master.cfg
5477 file less verbose.
5479 @menu
5480 * Configure::
5481 * Compile::
5482 * Test::
5483 * TreeSize::
5484 * PerlModuleTest::
5485 * SetProperty::
5486 @end menu
5488 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
5489 @subsubsection Configure
5491 @bsindex buildbot.steps.shell.Configure
5493 This is intended to handle the @code{./configure} step from
5494 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
5495 MakeMaker.pm-style modules. The default command is @code{./configure}
5496 but you can change this by providing a @code{command=} parameter.
5498 @node Compile, Test, Configure, Simple ShellCommand Subclasses
5499 @subsubsection Compile
5501 @bsindex buildbot.steps.shell.Compile
5503 This is meant to handle compiling or building a project written in C.
5504 The default command is @code{make all}. When the compile is finished,
5505 the log file is scanned for GCC warning messages, a summary log is
5506 created with any problems that were seen, and the step is marked as
5507 WARNINGS if any were discovered. The number of warnings is stored in a
5508 Build Property named ``warnings-count'', which is accumulated over all
5509 Compile steps (so if two warnings are found in one step, and three are
5510 found in another step, the overall build will have a
5511 ``warnings-count'' property of 5.
5513 The default regular expression used to detect a warning is
5514 @code{'.*warning[: ].*'} , which is fairly liberal and may cause
5515 false-positives. To use a different regexp, provide a
5516 @code{warningPattern=} argument, or use a subclass which sets the
5517 @code{warningPattern} attribute:
5519 @example
5520 f.addStep(Compile(command=["make", "test"],
5521                   warningPattern="^Warning: "))
5522 @end example
5524 The @code{warningPattern=} can also be a pre-compiled python regexp
5525 object: this makes it possible to add flags like @code{re.I} (to use
5526 case-insensitive matching).
5528 (TODO: this step needs to be extended to look for GCC error messages
5529 as well, and collect them into a separate logfile, along with the
5530 source code filenames involved).
5533 @node Test, TreeSize, Compile, Simple ShellCommand Subclasses
5534 @subsubsection Test
5536 @bsindex buildbot.steps.shell.Test
5538 This is meant to handle unit tests. The default command is @code{make
5539 test}, and the @code{warnOnFailure} flag is set.
5541 @node TreeSize, PerlModuleTest, Test, Simple ShellCommand Subclasses
5542 @subsubsection TreeSize
5544 @bsindex buildbot.steps.shell.TreeSize
5546 This is a simple command that uses the 'du' tool to measure the size
5547 of the code tree. It puts the size (as a count of 1024-byte blocks,
5548 aka 'KiB' or 'kibibytes') on the step's status text, and sets a build
5549 property named 'tree-size-KiB' with the same value.
5551 @node PerlModuleTest, SetProperty, TreeSize, Simple ShellCommand Subclasses
5552 @subsubsection PerlModuleTest
5554 @bsindex buildbot.steps.shell.PerlModuleTest
5556 This is a simple command that knows how to run tests of perl modules.
5557 It parses the output to determine the number of tests passed and
5558 failed and total number executed, saving the results for later query.
5560 @node SetProperty,  , PerlModuleTest, Simple ShellCommand Subclasses
5561 @subsubsection SetProperty
5563 @bsindex buildbot.steps.shell.SetProperty
5565 This buildstep is similar to ShellCommand, except that it captures the
5566 output of the command into a property.  It is usually used like this:
5568 @example
5569 f.addStep(SetProperty(command="uname -a", property="uname"))
5570 @end example
5572 This runs @code{uname -a} and captures its stdout, stripped of leading
5573 and trailing whitespace, in the property "uname".  To avoid stripping,
5574 add @code{strip=False}.  The @code{property} argument can be specified
5575 as a @code{WithProperties} object.
5577 The more advanced usage allows you to specify a function to extract
5578 properties from the command output.  Here you can use regular
5579 expressions, string interpolation, or whatever you would like.
5580 The function is called with three arguments: the exit status of the
5581 command, its standard output as a string, and its standard error as
5582 a string.  It should return a dictionary containing all new properties.
5584 @example
5585 def glob2list(rc, stdout, stderr):
5586     jpgs = [ l.strip() for l in stdout.split('\n') ]
5587     return @{ 'jpgs' : jpgs @}
5588 f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
5589 @end example
5591 Note that any ordering relationship of the contents of stdout and
5592 stderr is lost.  For example, given
5594 @example
5595 f.addStep(SetProperty(
5596     command="echo output1; echo error >&2; echo output2",
5597     extract_fn=my_extract))
5598 @end example
5600 Then @code{my_extract} will see @code{stdout="output1\noutput2\n"}
5601 and @code{stderr="error\n"}.
5603 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
5604 @subsection Python BuildSteps
5606 Here are some BuildSteps that are specifcally useful for projects
5607 implemented in Python.
5609 @menu
5610 * BuildEPYDoc::
5611 * PyFlakes::
5612 @end menu
5614 @node BuildEPYDoc, PyFlakes, Python BuildSteps, Python BuildSteps
5615 @subsubsection BuildEPYDoc
5617 @bsindex buildbot.steps.python.BuildEPYDoc
5619 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
5620 API documentation for Python modules from their docstrings. It reads
5621 all the .py files from your source tree, processes the docstrings
5622 therein, and creates a large tree of .html files (or a single .pdf
5623 file).
5625 The @code{buildbot.steps.python.BuildEPYDoc} step will run
5626 @command{epydoc} to produce this API documentation, and will count the
5627 errors and warnings from its output.
5629 You must supply the command line to be used. The default is
5630 @command{make epydocs}, which assumes that your project has a Makefile
5631 with an ``epydocs'' target. You might wish to use something like
5632 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
5633 to add @command{--pdf} to generate a PDF file instead of a large tree
5634 of HTML files.
5636 The API docs are generated in-place in the build tree (under the
5637 workdir, in the subdirectory controlled by the ``-o'' argument). To
5638 make them useful, you will probably have to copy them to somewhere
5639 they can be read. A command like @command{rsync -ad apiref/
5640 dev.example.com:~public_html/current-apiref/} might be useful. You
5641 might instead want to bundle them into a tarball and publish it in the
5642 same place where the generated install tarball is placed.
5644 @example
5645 from buildbot.steps.python import BuildEPYDoc
5648 f.addStep(BuildEPYDoc(command=["epydoc", "-o", "apiref", "source/mypkg"]))
5649 @end example
5652 @node PyFlakes,  , BuildEPYDoc, Python BuildSteps
5653 @subsubsection PyFlakes
5655 @bsindex buildbot.steps.python.PyFlakes
5657 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
5658 to perform basic static analysis of Python code to look for simple
5659 errors, like missing imports and references of undefined names. It is
5660 like a fast and simple form of the C ``lint'' program. Other tools
5661 (like pychecker) provide more detailed results but take longer to run.
5663 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
5664 count the various kinds of errors and warnings it detects.
5666 You must supply the command line to be used. The default is
5667 @command{make pyflakes}, which assumes you have a top-level Makefile
5668 with a ``pyflakes'' target. You might want to use something like
5669 @command{pyflakes .} or @command{pyflakes src}.
5671 @example
5672 from buildbot.steps.python import PyFlakes
5675 f.addStep(PyFlakes(command=["pyflakes", "src"]))
5676 @end example
5679 @node Transferring Files
5680 @subsection Transferring Files
5682 @cindex File Transfer
5683 @bsindex buildbot.steps.transfer.FileUpload
5684 @bsindex buildbot.steps.transfer.FileDownload
5685 @bsindex buildbot.steps.transfer.DirectoryUpload
5687 Most of the work involved in a build will take place on the
5688 buildslave. But occasionally it is useful to do some work on the
5689 buildmaster side. The most basic way to involve the buildmaster is
5690 simply to move a file from the slave to the master, or vice versa.
5691 There are a pair of BuildSteps named @code{FileUpload} and
5692 @code{FileDownload} to provide this functionality. @code{FileUpload}
5693 moves a file @emph{up to} the master, while @code{FileDownload} moves
5694 a file @emph{down from} the master.
5696 As an example, let's assume that there is a step which produces an
5697 HTML file within the source tree that contains some sort of generated
5698 project documentation. We want to move this file to the buildmaster,
5699 into a @file{~/public_html} directory, so it can be visible to
5700 developers. This file will wind up in the slave-side working directory
5701 under the name @file{docs/reference.html}. We want to put it into the
5702 master-side @file{~/public_html/ref.html}.
5704 @example
5705 from buildbot.steps.shell import ShellCommand
5706 from buildbot.steps.transfer import FileUpload
5708 f.addStep(ShellCommand(command=["make", "docs"]))
5709 f.addStep(FileUpload(slavesrc="docs/reference.html",
5710                      masterdest="~/public_html/ref.html"))
5711 @end example
5713 The @code{masterdest=} argument will be passed to os.path.expanduser,
5714 so things like ``~'' will be expanded properly. Non-absolute paths
5715 will be interpreted relative to the buildmaster's base directory.
5716 Likewise, the @code{slavesrc=} argument will be expanded and
5717 interpreted relative to the builder's working directory.
5720 To move a file from the master to the slave, use the
5721 @code{FileDownload} command. For example, let's assume that some step
5722 requires a configuration file that, for whatever reason, could not be
5723 recorded in the source code repository or generated on the buildslave
5724 side:
5726 @example
5727 from buildbot.steps.shell import ShellCommand
5728 from buildbot.steps.transfer import FileUpload
5730 f.addStep(FileDownload(mastersrc="~/todays_build_config.txt",
5731                        slavedest="build_config.txt"))
5732 f.addStep(ShellCommand(command=["make", "config"]))
5733 @end example
5735 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
5736 relative to the buildmaster's base directory, and the
5737 @code{slavedest=} argument is relative to the builder's working
5738 directory. If the buildslave is running in @file{~buildslave}, and the
5739 builder's ``builddir'' is something like @file{tests-i386}, then the
5740 workdir is going to be @file{~buildslave/tests-i386/build}, and a
5741 @code{slavedest=} of @file{foo/bar.html} will get put in
5742 @file{~buildslave/tests-i386/build/foo/bar.html}. Both of these commands
5743 will create any missing intervening directories.
5745 @subheading Other Parameters
5747 The @code{maxsize=} argument lets you set a maximum size for the file
5748 to be transferred. This may help to avoid surprises: transferring a
5749 100MB coredump when you were expecting to move a 10kB status file
5750 might take an awfully long time. The @code{blocksize=} argument
5751 controls how the file is sent over the network: larger blocksizes are
5752 slightly more efficient but also consume more memory on each end, and
5753 there is a hard-coded limit of about 640kB.
5755 The @code{mode=} argument allows you to control the access permissions
5756 of the target file, traditionally expressed as an octal integer. The
5757 most common value is probably 0755, which sets the ``x'' executable
5758 bit on the file (useful for shell scripts and the like). The default
5759 value for @code{mode=} is None, which means the permission bits will
5760 default to whatever the umask of the writing process is. The default
5761 umask tends to be fairly restrictive, but at least on the buildslave
5762 you can make it less restrictive with a --umask command-line option at
5763 creation time (@pxref{Buildslave Options}).
5765 @subheading Transfering Directories
5767 To transfer complete directories from the buildslave to the master, there
5768 is a BuildStep named @code{DirectoryUpload}. It works like @code{FileUpload},
5769 just for directories. However it does not support the @code{maxsize},
5770 @code{blocksize} and @code{mode} arguments. As an example, let's assume an
5771 generated project documentation, which consists of many files (like the output
5772 of doxygen or epydoc). We want to move the entire documentation to the
5773 buildmaster, into a @code{~/public_html/docs} directory. On the slave-side
5774 the directory can be found under @code{docs}:
5776 @example
5777 from buildbot.steps.shell import ShellCommand
5778 from buildbot.steps.transfer import DirectoryUpload
5780 f.addStep(ShellCommand(command=["make", "docs"]))
5781 f.addStep(DirectoryUpload(slavesrc="docs",
5782                                 masterdest="~/public_html/docs"))
5783 @end example
5785 The DirectoryUpload step will create all necessary directories and
5786 transfers empty directories, too.
5788 @node Steps That Run on the Master
5789 @subsection Steps That Run on the Master
5791 Occasionally, it is useful to execute some task on the master, for example to
5792 create a directory, deploy a build result, or trigger some other centralized
5793 processing.  This is possible, in a limited fashion, with the
5794 @code{MasterShellCommand} step.
5796 This step operates similarly to a regular @code{ShellCommand}, but executes on
5797 the master, instead of the slave.  To be clear, the enclosing @code{Build}
5798 object must still have a slave object, just as for any other step -- only, in
5799 this step, the slave does not do anything.
5801 In this example, the step renames a tarball based on the day of the week.
5803 @example
5804 from buildbot.steps.transfer import FileUpload
5805 from buildbot.steps.master import MasterShellCommand
5807 f.addStep(FileUpload(slavesrc="widgetsoft.tar.gz",
5808                      masterdest="/var/buildoutputs/widgetsoft-new.tar.gz"))
5809 f.addStep(MasterShellCommand(command="""
5810     cd /var/buildoutputs;
5811     mv widgetsoft-new.tar.gz widgetsoft-`date +%a`.tar.gz"""))
5812 @end example
5814 @node Triggering Schedulers
5815 @subsection Triggering Schedulers
5817 The counterpart to the Triggerable described in section
5818 @pxref{Triggerable Scheduler} is the Trigger BuildStep.
5820 @example
5821 from buildbot.steps.trigger import Trigger
5822 f.addStep(Trigger(schedulerNames=['build-prep'],
5823                   waitForFinish=True,
5824                   updateSourceStamp=True))
5825 @end example
5827 The @code{schedulerNames=} argument lists the Triggerables
5828 that should be triggered when this step is executed.  Note that
5829 it is possible, but not advisable, to create a cycle where a build
5830 continually triggers itself, because the schedulers are specified
5831 by name.
5833 If @code{waitForFinish} is True, then the step will not finish until
5834 all of the builds from the triggered schedulers have finished. If this
5835 argument is False (the default) or not given, then the buildstep
5836 succeeds immediately after triggering the schedulers.
5838 If @code{updateSourceStamp} is True (the default), then step updates
5839 the SourceStamp given to the Triggerables to include
5840 @code{got_revision} (the revision actually used in this build) as
5841 @code{revision} (the revision to use in the triggered builds). This is
5842 useful to ensure that all of the builds use exactly the same
5843 SourceStamp, even if other Changes have occurred while the build was
5844 running.
5846 @node Writing New BuildSteps
5847 @subsection Writing New BuildSteps
5849 While it is a good idea to keep your build process self-contained in
5850 the source code tree, sometimes it is convenient to put more
5851 intelligence into your Buildbot configuration. One way to do this is
5852 to write a custom BuildStep. Once written, this Step can be used in
5853 the @file{master.cfg} file.
5855 The best reason for writing a custom BuildStep is to better parse the
5856 results of the command being run. For example, a BuildStep that knows
5857 about JUnit could look at the logfiles to determine which tests had
5858 been run, how many passed and how many failed, and then report more
5859 detailed information than a simple @code{rc==0} -based ``good/bad''
5860 decision.
5862 TODO: add more description of BuildSteps.
5864 @menu
5865 * BuildStep LogFiles::
5866 * Reading Logfiles::
5867 * Adding LogObservers::
5868 * BuildStep URLs::
5869 @end menu
5871 @node BuildStep LogFiles, Reading Logfiles, Writing New BuildSteps, Writing New BuildSteps
5872 @subsubsection BuildStep LogFiles
5874 Each BuildStep has a collection of ``logfiles''. Each one has a short
5875 name, like ``stdio'' or ``warnings''. Each LogFile contains an
5876 arbitrary amount of text, usually the contents of some output file
5877 generated during a build or test step, or a record of everything that
5878 was printed to stdout/stderr during the execution of some command.
5880 These LogFiles are stored to disk, so they can be retrieved later.
5882 Each can contain multiple ``channels'', generally limited to three
5883 basic ones: stdout, stderr, and ``headers''. For example, when a
5884 ShellCommand runs, it writes a few lines to the ``headers'' channel to
5885 indicate the exact argv strings being run, which directory the command
5886 is being executed in, and the contents of the current environment
5887 variables. Then, as the command runs, it adds a lot of ``stdout'' and
5888 ``stderr'' messages. When the command finishes, a final ``header''
5889 line is added with the exit code of the process.
5891 Status display plugins can format these different channels in
5892 different ways. For example, the web page shows LogFiles as text/html,
5893 with header lines in blue text, stdout in black, and stderr in red. A
5894 different URL is available which provides a text/plain format, in
5895 which stdout and stderr are collapsed together, and header lines are
5896 stripped completely. This latter option makes it easy to save the
5897 results to a file and run @command{grep} or whatever against the
5898 output.
5900 Each BuildStep contains a mapping (implemented in a python dictionary)
5901 from LogFile name to the actual LogFile objects. Status plugins can
5902 get a list of LogFiles to display, for example, a list of HREF links
5903 that, when clicked, provide the full contents of the LogFile.
5905 @heading Using LogFiles in custom BuildSteps
5907 The most common way for a custom BuildStep to use a LogFile is to
5908 summarize the results of a ShellCommand (after the command has
5909 finished running). For example, a compile step with thousands of lines
5910 of output might want to create a summary of just the warning messages.
5911 If you were doing this from a shell, you would use something like:
5913 @example
5914 grep "warning:" output.log >warnings.log
5915 @end example
5917 In a custom BuildStep, you could instead create a ``warnings'' LogFile
5918 that contained the same text. To do this, you would add code to your
5919 @code{createSummary} method that pulls lines from the main output log
5920 and creates a new LogFile with the results:
5922 @example
5923     def createSummary(self, log):
5924         warnings = []
5925         for line in log.readlines():
5926             if "warning:" in line:
5927                 warnings.append()
5928         self.addCompleteLog('warnings', "".join(warnings))
5929 @end example
5931 This example uses the @code{addCompleteLog} method, which creates a
5932 new LogFile, puts some text in it, and then ``closes'' it, meaning
5933 that no further contents will be added. This LogFile will appear in
5934 the HTML display under an HREF with the name ``warnings'', since that
5935 is the name of the LogFile.
5937 You can also use @code{addHTMLLog} to create a complete (closed)
5938 LogFile that contains HTML instead of plain text. The normal LogFile
5939 will be HTML-escaped if presented through a web page, but the HTML
5940 LogFile will not. At the moment this is only used to present a pretty
5941 HTML representation of an otherwise ugly exception traceback when
5942 something goes badly wrong during the BuildStep.
5944 In contrast, you might want to create a new LogFile at the beginning
5945 of the step, and add text to it as the command runs. You can create
5946 the LogFile and attach it to the build by calling @code{addLog}, which
5947 returns the LogFile object. You then add text to this LogFile by
5948 calling methods like @code{addStdout} and @code{addHeader}. When you
5949 are done, you must call the @code{finish} method so the LogFile can be
5950 closed. It may be useful to create and populate a LogFile like this
5951 from a LogObserver method @xref{Adding LogObservers}.
5953 The @code{logfiles=} argument to @code{ShellCommand} (see
5954 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
5955 by asking the buildslave to watch a actual file on disk. The
5956 buildslave will look for additions in the target file and report them
5957 back to the BuildStep. These additions will be added to the LogFile by
5958 calling @code{addStdout}. These secondary LogFiles can be used as the
5959 source of a LogObserver just like the normal ``stdio'' LogFile.
5961 @node Reading Logfiles, Adding LogObservers, BuildStep LogFiles, Writing New BuildSteps
5962 @subsubsection Reading Logfiles
5964 Once a LogFile has been added to a BuildStep with @code{addLog()},
5965 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
5966 your BuildStep can retrieve it by using @code{getLog()}:
5968 @example
5969 class MyBuildStep(ShellCommand):
5970     logfiles = @{ "nodelog": "_test/node.log" @}
5972     def evaluateCommand(self, cmd):
5973         nodelog = self.getLog("nodelog")
5974         if "STARTED" in nodelog.getText():
5975             return SUCCESS
5976         else:
5977             return FAILURE
5978 @end example
5980 For a complete list of the methods you can call on a LogFile, please
5981 see the docstrings on the @code{IStatusLog} class in
5982 @file{buildbot/interfaces.py}.
5985 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
5986 @subsubsection Adding LogObservers
5988 @cindex LogObserver
5989 @cindex LogLineObserver
5991 Most shell commands emit messages to stdout or stderr as they operate,
5992 especially if you ask them nicely with a @code{--verbose} flag of some
5993 sort. They may also write text to a log file while they run. Your
5994 BuildStep can watch this output as it arrives, to keep track of how
5995 much progress the command has made. You can get a better measure of
5996 progress by counting the number of source files compiled or test cases
5997 run than by merely tracking the number of bytes that have been written
5998 to stdout. This improves the accuracy and the smoothness of the ETA
5999 display.
6001 To accomplish this, you will need to attach a @code{LogObserver} to
6002 one of the log channels, most commonly to the ``stdio'' channel but
6003 perhaps to another one which tracks a log file. This observer is given
6004 all text as it is emitted from the command, and has the opportunity to
6005 parse that output incrementally. Once the observer has decided that
6006 some event has occurred (like a source file being compiled), it can
6007 use the @code{setProgress} method to tell the BuildStep about the
6008 progress that this event represents.
6010 There are a number of pre-built @code{LogObserver} classes that you
6011 can choose from (defined in @code{buildbot.process.buildstep}, and of
6012 course you can subclass them to add further customization. The
6013 @code{LogLineObserver} class handles the grunt work of buffering and
6014 scanning for end-of-line delimiters, allowing your parser to operate
6015 on complete stdout/stderr lines. (Lines longer than a set maximum
6016 length are dropped; the maximum defaults to 16384 bytes, but you can
6017 change it by calling @code{setMaxLineLength()} on your
6018 @code{LogLineObserver} instance.  Use @code{sys.maxint} for effective
6019 infinity.)
6021 For example, let's take a look at the @code{TrialTestCaseCounter},
6022 which is used by the Trial step to count test cases as they are run.
6023 As Trial executes, it emits lines like the following:
6025 @example
6026 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
6027 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
6028 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
6029 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
6030 @end example
6032 When the tests are finished, trial emits a long line of ``======'' and
6033 then some lines which summarize the tests that failed. We want to
6034 avoid parsing these trailing lines, because their format is less
6035 well-defined than the ``[OK]'' lines.
6037 The parser class looks like this:
6039 @example
6040 from buildbot.process.buildstep import LogLineObserver
6042 class TrialTestCaseCounter(LogLineObserver):
6043     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
6044     numTests = 0
6045     finished = False
6047     def outLineReceived(self, line):
6048         if self.finished:
6049             return
6050         if line.startswith("=" * 40):
6051             self.finished = True
6052             return
6054         m = self._line_re.search(line.strip())
6055         if m:
6056             testname, result = m.groups()
6057             self.numTests += 1
6058             self.step.setProgress('tests', self.numTests)
6059 @end example
6061 This parser only pays attention to stdout, since that's where trial
6062 writes the progress lines. It has a mode flag named @code{finished} to
6063 ignore everything after the ``===='' marker, and a scary-looking
6064 regular expression to match each line while hopefully ignoring other
6065 messages that might get displayed as the test runs.
6067 Each time it identifies a test has been completed, it increments its
6068 counter and delivers the new progress value to the step with
6069 @code{self.step.setProgress}. This class is specifically measuring
6070 progress along the ``tests'' metric, in units of test cases (as
6071 opposed to other kinds of progress like the ``output'' metric, which
6072 measures in units of bytes). The Progress-tracking code uses each
6073 progress metric separately to come up with an overall completion
6074 percentage and an ETA value.
6076 To connect this parser into the @code{Trial} BuildStep,
6077 @code{Trial.__init__} ends with the following clause:
6079 @example
6080         # this counter will feed Progress along the 'test cases' metric
6081         counter = TrialTestCaseCounter()
6082         self.addLogObserver('stdio', counter)
6083         self.progressMetrics += ('tests',)
6084 @end example
6086 This creates a TrialTestCaseCounter and tells the step that the
6087 counter wants to watch the ``stdio'' log. The observer is
6088 automatically given a reference to the step in its @code{.step}
6089 attribute.
6091 @subheading A Somewhat Whimsical Example
6093 Let's say that we've got some snazzy new unit-test framework called
6094 Framboozle. It's the hottest thing since sliced bread. It slices, it
6095 dices, it runs unit tests like there's no tomorrow. Plus if your unit
6096 tests fail, you can use its name for a Web 2.1 startup company, make
6097 millions of dollars, and hire engineers to fix the bugs for you, while
6098 you spend your afternoons lazily hang-gliding along a scenic pacific
6099 beach, blissfully unconcerned about the state of your
6100 tests.@footnote{framboozle.com is still available. Remember, I get 10%
6101 :).}
6103 To run a Framboozle-enabled test suite, you just run the 'framboozler'
6104 command from the top of your source code tree. The 'framboozler'
6105 command emits a bunch of stuff to stdout, but the most interesting bit
6106 is that it emits the line "FNURRRGH!" every time it finishes running a
6107 test case@footnote{Framboozle gets very excited about running unit
6108 tests.}. You'd like to have a test-case counting LogObserver that
6109 watches for these lines and counts them, because counting them will
6110 help the buildbot more accurately calculate how long the build will
6111 take, and this will let you know exactly how long you can sneak out of
6112 the office for your hang-gliding lessons without anyone noticing that
6113 you're gone.
6115 This will involve writing a new BuildStep (probably named
6116 "Framboozle") which inherits from ShellCommand. The BuildStep class
6117 definition itself will look something like this:
6119 @example
6120 # START
6121 from buildbot.steps.shell import ShellCommand
6122 from buildbot.process.buildstep import LogLineObserver
6124 class FNURRRGHCounter(LogLineObserver):
6125     numTests = 0
6126     def outLineReceived(self, line):
6127         if "FNURRRGH!" in line:
6128             self.numTests += 1
6129             self.step.setProgress('tests', self.numTests)
6131 class Framboozle(ShellCommand):
6132     command = ["framboozler"]
6134     def __init__(self, **kwargs):
6135         ShellCommand.__init__(self, **kwargs)   # always upcall!
6136         counter = FNURRRGHCounter())
6137         self.addLogObserver('stdio', counter)
6138         self.progressMetrics += ('tests',)
6139 # FINISH
6140 @end example
6142 So that's the code that we want to wind up using. How do we actually
6143 deploy it?
6145 You have a couple of different options.
6147 Option 1: The simplest technique is to simply put this text
6148 (everything from START to FINISH) in your master.cfg file, somewhere
6149 before the BuildFactory definition where you actually use it in a
6150 clause like:
6152 @example
6153 f = BuildFactory()
6154 f.addStep(SVN(svnurl="stuff"))
6155 f.addStep(Framboozle())
6156 @end example
6158 Remember that master.cfg is secretly just a python program with one
6159 job: populating the BuildmasterConfig dictionary. And python programs
6160 are allowed to define as many classes as they like. So you can define
6161 classes and use them in the same file, just as long as the class is
6162 defined before some other code tries to use it.
6164 This is easy, and it keeps the point of definition very close to the
6165 point of use, and whoever replaces you after that unfortunate
6166 hang-gliding accident will appreciate being able to easily figure out
6167 what the heck this stupid "Framboozle" step is doing anyways. The
6168 downside is that every time you reload the config file, the Framboozle
6169 class will get redefined, which means that the buildmaster will think
6170 that you've reconfigured all the Builders that use it, even though
6171 nothing changed. Bleh.
6173 Option 2: Instead, we can put this code in a separate file, and import
6174 it into the master.cfg file just like we would the normal buildsteps
6175 like ShellCommand and SVN.
6177 Create a directory named ~/lib/python, put everything from START to
6178 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
6180 @example
6181  PYTHONPATH=~/lib/python buildbot start MASTERDIR
6182 @end example
6184 or use the @file{Makefile.buildbot} to control the way
6185 @command{buildbot start} works. Or add something like this to
6186 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
6188 @example
6189  export PYTHONPATH=~/lib/python
6190 @end example
6192 Once we've done this, our master.cfg can look like:
6194 @example
6195 from framboozle import Framboozle
6196 f = BuildFactory()
6197 f.addStep(SVN(svnurl="stuff"))
6198 f.addStep(Framboozle())
6199 @end example
6203 @example
6204 import framboozle
6205 f = BuildFactory()
6206 f.addStep(SVN(svnurl="stuff"))
6207 f.addStep(framboozle.Framboozle())
6208 @end example
6210 (check out the python docs for details about how "import" and "from A
6211 import B" work).
6213 What we've done here is to tell python that every time it handles an
6214 "import" statement for some named module, it should look in our
6215 ~/lib/python/ for that module before it looks anywhere else. After our
6216 directories, it will try in a bunch of standard directories too
6217 (including the one where buildbot is installed). By setting the
6218 PYTHONPATH environment variable, you can add directories to the front
6219 of this search list.
6221 Python knows that once it "import"s a file, it doesn't need to
6222 re-import it again. This means that reconfiguring the buildmaster
6223 (with "buildbot reconfig", for example) won't make it think the
6224 Framboozle class has changed every time, so the Builders that use it
6225 will not be spuriously restarted. On the other hand, you either have
6226 to start your buildmaster in a slightly weird way, or you have to
6227 modify your environment to set the PYTHONPATH variable.
6230 Option 3: Install this code into a standard python library directory
6232 Find out what your python's standard include path is by asking it:
6234 @example
6235 80:warner@@luther% python
6236 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46)
6237 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
6238 Type "help", "copyright", "credits" or "license" for more information.
6239 >>> import sys
6240 >>> import pprint
6241 >>> pprint.pprint(sys.path)
6242 ['',
6243  '/usr/lib/python24.zip',
6244  '/usr/lib/python2.4',
6245  '/usr/lib/python2.4/plat-linux2',
6246  '/usr/lib/python2.4/lib-tk',
6247  '/usr/lib/python2.4/lib-dynload',
6248  '/usr/local/lib/python2.4/site-packages',
6249  '/usr/lib/python2.4/site-packages',
6250  '/usr/lib/python2.4/site-packages/Numeric',
6251  '/var/lib/python-support/python2.4',
6252  '/usr/lib/site-python']
6253 @end example
6255 In this case, putting the code into
6256 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
6257 fine. We can use the same master.cfg "import framboozle" statement as
6258 in Option 2. By putting it in a standard include directory (instead of
6259 the decidedly non-standard ~/lib/python), we don't even have to set
6260 PYTHONPATH to anything special. The downside is that you probably have
6261 to be root to write to one of those standard include directories.
6264 Option 4: Submit the code for inclusion in the Buildbot distribution
6266 Contribute the code in an Enhancement Request on SourceForge, via
6267 http://buildbot.sf.net . Lobby, convince, coerce, bribe, badger,
6268 harass, threaten, or otherwise encourage the author to accept the
6269 patch. This lets you do something like:
6271 @example
6272 from buildbot.steps import framboozle
6273 f = BuildFactory()
6274 f.addStep(SVN(svnurl="stuff"))
6275 f.addStep(framboozle.Framboozle())
6276 @end example
6278 And then you don't even have to install framboozle.py anywhere on your
6279 system, since it will ship with Buildbot. You don't have to be root,
6280 you don't have to set PYTHONPATH. But you do have to make a good case
6281 for Framboozle being worth going into the main distribution, you'll
6282 probably have to provide docs and some unit test cases, you'll need to
6283 figure out what kind of beer the author likes, and then you'll have to
6284 wait until the next release. But in some environments, all this is
6285 easier than getting root on your buildmaster box, so the tradeoffs may
6286 actually be worth it.
6290 Putting the code in master.cfg (1) makes it available to that
6291 buildmaster instance. Putting it in a file in a personal library
6292 directory (2) makes it available for any buildmasters you might be
6293 running. Putting it in a file in a system-wide shared library
6294 directory (3) makes it available for any buildmasters that anyone on
6295 that system might be running. Getting it into the buildbot's upstream
6296 repository (4) makes it available for any buildmasters that anyone in
6297 the world might be running. It's all a matter of how widely you want
6298 to deploy that new class.
6302 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
6303 @subsubsection BuildStep URLs
6305 @cindex links
6306 @cindex BuildStep URLs
6307 @cindex addURL
6309 Each BuildStep has a collection of ``links''. Like its collection of
6310 LogFiles, each link has a name and a target URL. The web status page
6311 creates HREFs for each link in the same box as it does for LogFiles,
6312 except that the target of the link is the external URL instead of an
6313 internal link to a page that shows the contents of the LogFile.
6315 These external links can be used to point at build information hosted
6316 on other servers. For example, the test process might produce an
6317 intricate description of which tests passed and failed, or some sort
6318 of code coverage data in HTML form, or a PNG or GIF image with a graph
6319 of memory usage over time. The external link can provide an easy way
6320 for users to navigate from the buildbot's status page to these
6321 external web sites or file servers. Note that the step itself is
6322 responsible for insuring that there will be a document available at
6323 the given URL (perhaps by using @command{scp} to copy the HTML output
6324 to a @file{~/public_html/} directory on a remote web server). Calling
6325 @code{addURL} does not magically populate a web server.
6327 To set one of these links, the BuildStep should call the @code{addURL}
6328 method with the name of the link and the target URL. Multiple URLs can
6329 be set.
6331 In this example, we assume that the @command{make test} command causes
6332 a collection of HTML files to be created and put somewhere on the
6333 coverage.example.org web server, in a filename that incorporates the
6334 build number.
6336 @example
6337 class TestWithCodeCoverage(BuildStep):
6338     command = ["make", "test",
6339                WithProperties("buildnum=%s" % "buildnumber")]
6341     def createSummary(self, log):
6342         buildnumber = self.getProperty("buildnumber")
6343         url = "http://coverage.example.org/builds/%s.html" % buildnumber
6344         self.addURL("coverage", url)
6345 @end example
6347 You might also want to extract the URL from some special message
6348 output by the build process itself:
6350 @example
6351 class TestWithCodeCoverage(BuildStep):
6352     command = ["make", "test",
6353                WithProperties("buildnum=%s" % "buildnumber")]
6355     def createSummary(self, log):
6356         output = StringIO(log.getText())
6357         for line in output.readlines():
6358             if line.startswith("coverage-url:"):
6359                 url = line[len("coverage-url:"):].strip()
6360                 self.addURL("coverage", url)
6361                 return
6362 @end example
6364 Note that a build process which emits both stdout and stderr might
6365 cause this line to be split or interleaved between other lines. It
6366 might be necessary to restrict the getText() call to only stdout with
6367 something like this:
6369 @example
6370         output = StringIO("".join([c[1]
6371                                    for c in log.getChunks()
6372                                    if c[0] == LOG_CHANNEL_STDOUT]))
6373 @end example
6375 Of course if the build is run under a PTY, then stdout and stderr will
6376 be merged before the buildbot ever sees them, so such interleaving
6377 will be unavoidable.
6380 @node Interlocks, Build Factories, Build Steps, Build Process
6381 @section Interlocks
6383 @cindex locks
6384 @slindex buildbot.locks.MasterLock
6385 @slindex buildbot.locks.SlaveLock
6386 @slindex buildbot.locks.LockAccess
6388 Until now, we assumed that a master can run builds at any slave whenever
6389 needed or desired.  Some times, you want to enforce additional constraints on
6390 builds. For reasons like limited network bandwidth, old slave machines, or a
6391 self-willed data base server, you may want to limit the number of builds (or
6392 build steps) that can access a resource.
6394 The mechanism used by Buildbot is known as the read/write lock.@footnote{See
6395 http://en.wikipedia.org/wiki/Read/write_lock_pattern for more information.} It
6396 allows either many readers or a single writer but not a combination of readers
6397 and writers. The general lock has been modified and extended for use in
6398 Buildbot. Firstly, the general lock allows an infinite number of readers. In
6399 Buildbot, we often want to put an upper limit on the number of readers, for
6400 example allowing two out of five possible builds at the same time. To do this,
6401 the lock counts the number of active readers. Secondly, the terms @emph{read
6402 mode} and @emph{write mode} are confusing in Buildbot context. They have been
6403 replaced by @emph{counting mode} (since the lock counts them) and @emph{exclusive
6404 mode}.  As a result of these changes, locks in Buildbot allow a number of
6405 builds (upto some fixed number) in counting mode, or they allow one build in
6406 exclusive mode.
6408 Often, not all slaves are equal. To allow for this situation, Buildbot allows
6409 to have a separate upper limit on the count for each slave. In this way, you
6410 can have at most 3 concurrent builds at a fast slave, 2 at a slightly older
6411 slave, and 1 at all other slaves.
6413 The final thing you can specify when you introduce a new lock is its scope.
6414 Some constraints are global -- they must be enforced over all slaves. Other
6415 constraints are local to each slave.  A @emph{master lock} is used for the
6416 global constraints. You can ensure for example that at most one build (of all
6417 builds running at all slaves) accesses the data base server. With a
6418 @emph{slave lock} you can add a limit local to each slave. With such a lock,
6419 you can for example enforce an upper limit to the number of active builds at a
6420 slave, like above.
6422 Time for a few examples. Below a master lock is defined to protect a data base,
6423 and a slave lock is created to limit the number of builds at each slave.
6425 @example
6426 from buildbot import locks
6428 db_lock = locks.MasterLock("database")
6429 build_lock = locks.SlaveLock("slave_builds",
6430                              maxCount = 1,
6431                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6432 @end example
6434 After importing locks from buildbot, @code{db_lock} is defined to be a master
6435 lock. The @code{"database"} string is used for uniquely identifying the lock.
6436 At the next line, a slave lock called @code{build_lock} is created. It is
6437 identified by the @code{"slave_builds"} string. Since the requirements of the
6438 lock are a bit more complicated, two optional arguments are also specified. The
6439 @code{maxCount} parameter sets the default limit for builds in counting mode to
6440 @code{1}. For the slave called @code{'fast'} however, we want to have at most
6441 three builds, and for the slave called @code{'new'} the upper limit is two
6442 builds running at the same time.
6444 The next step is using the locks in builds.  Buildbot allows a lock to be used
6445 during an entire build (from beginning to end), or only during a single build
6446 step. In the latter case, the lock is claimed for use just before the step
6447 starts, and released again when the step ends. To prevent
6448 deadlocks,@footnote{Deadlock is the situation where two or more slaves each
6449 hold a lock in exclusive mode, and in addition want to claim the lock held by
6450 the other slave exclusively as well. Since locks allow at most one exclusive
6451 user, both slaves will wait forever.} it is not possible to claim or release
6452 locks at other times.
6454 To use locks, you should add them with a @code{locks} argument.
6455 Each use of a lock is either in counting mode (that is, possibly shared with
6456 other builds) or in exclusive mode. A build or build step proceeds only when it
6457 has acquired all locks. If a build or step needs a lot of locks, it may be
6458 starved@footnote{Starving is the situation that only a few locks are available,
6459 and they are immediately grabbed by another build. As a result, it may take a
6460 long time before all locks needed by the starved build are free at the same
6461 time.} by other builds that need fewer locks.
6463 To illustrate use of locks, a few examples.
6465 @example
6466 from buildbot import locks
6467 from buildbot.steps import source, shell
6468 from buildbot.process import factory
6470 db_lock = locks.MasterLock("database")
6471 build_lock = locks.SlaveLock("slave_builds",
6472                              maxCount = 1,
6473                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6475 f = factory.BuildFactory()
6476 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
6477 f.addStep(shell.ShellCommand(command="make all"))
6478 f.addStep(shell.ShellCommand(command="make test",
6479                              locks=[db_lock.access('exclusive')]))
6481 b1 = @{'name': 'full1', 'slavename': 'fast',  'builddir': 'f1', 'factory': f,
6482        'locks': [build_lock.access('counting')] @}
6484 b2 = @{'name': 'full2', 'slavename': 'new',   'builddir': 'f2', 'factory': f.
6485        'locks': [build_lock.access('counting')] @}
6487 b3 = @{'name': 'full3', 'slavename': 'old',   'builddir': 'f3', 'factory': f.
6488        'locks': [build_lock.access('counting')] @}
6490 b4 = @{'name': 'full4', 'slavename': 'other', 'builddir': 'f4', 'factory': f.
6491        'locks': [build_lock.access('counting')] @}
6493 c['builders'] = [b1, b2, b3, b4]
6494 @end example
6496 Here we have four slaves @code{b1}, @code{b2}, @code{b3}, and @code{b4}. Each
6497 slave performs the same checkout, make, and test build step sequence.
6498 We want to enforce that at most one test step is executed between all slaves due
6499 to restrictions with the data base server. This is done by adding the
6500 @code{locks=} parameter with the third step. It takes a list of locks with their
6501 access mode. In this case only the @code{db_lock} is needed. The exclusive
6502 access mode is used to ensure there is at most one slave that executes the test
6503 step.
6505 In addition to exclusive accessing the data base, we also want slaves to stay
6506 responsive even under the load of a large number of builds being triggered.
6507 For this purpose, the slave lock called @code{build_lock} is defined. Since
6508 the restraint holds for entire builds, the lock is specified in the builder
6509 with @code{'locks': [build_lock.access('counting')]}.
6510 @node Build Factories,  , Interlocks, Build Process
6511 @section Build Factories
6514 Each Builder is equipped with a ``build factory'', which is
6515 responsible for producing the actual @code{Build} objects that perform
6516 each build. This factory is created in the configuration file, and
6517 attached to a Builder through the @code{factory} element of its
6518 dictionary.
6520 The standard @code{BuildFactory} object creates @code{Build} objects
6521 by default. These Builds will each execute a collection of BuildSteps
6522 in a fixed sequence. Each step can affect the results of the build,
6523 but in general there is little intelligence to tie the different steps
6524 together. You can create subclasses of @code{Build} to implement more
6525 sophisticated build processes, and then use a subclass of
6526 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
6527 create instances of your new Build subclass.
6530 @menu
6531 * BuildStep Objects::
6532 * BuildFactory::
6533 * Process-Specific build factories::
6534 @end menu
6536 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
6537 @subsection BuildStep Objects
6539 The steps used by these builds are all subclasses of @code{BuildStep}.
6540 The standard ones provided with Buildbot are documented later,
6541 @xref{Build Steps}. You can also write your own subclasses to use in
6542 builds.
6544 The basic behavior for a @code{BuildStep} is to:
6546 @itemize @bullet
6547 @item
6548 run for a while, then stop
6549 @item
6550 possibly invoke some RemoteCommands on the attached build slave
6551 @item
6552 possibly produce a set of log files
6553 @item
6554 finish with a status described by one of four values defined in
6555 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
6556 @item
6557 provide a list of short strings to describe the step
6558 @item
6559 define a color (generally green, orange, or red) with which the
6560 step should be displayed
6561 @end itemize
6564 More sophisticated steps may produce additional information and
6565 provide it to later build steps, or store it in the factory to provide
6566 to later builds.
6569 @menu
6570 * BuildFactory Attributes::
6571 * Quick builds::
6572 @end menu
6574 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
6575 @subsection BuildFactory
6577 @bfindex buildbot.process.factory.BuildFactory
6578 @bfindex buildbot.process.factory.BasicBuildFactory
6579 @c TODO: what is BasicSVN anyway?
6580 @bfindex buildbot.process.factory.BasicSVN
6582 The default @code{BuildFactory}, provided in the
6583 @code{buildbot.process.factory} module, contains an internal list of
6584 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
6585 tuples for each. These specification tuples are constructed when the
6586 config file is read, by asking the instances passed to @code{addStep}
6587 for their subclass and arguments.
6589 When asked to create a Build, the @code{BuildFactory} puts a copy of
6590 the list of step specifications into the new Build object. When the
6591 Build is actually started, these step specifications are used to
6592 create the actual set of BuildSteps, which are then executed one at a
6593 time. This serves to give each Build an independent copy of each step.
6594 For example, a build which consists of a CVS checkout followed by a
6595 @code{make build} would be constructed as follows:
6597 @example
6598 from buildbot.steps import source, shell
6599 from buildbot.process import factory
6601 f = factory.BuildFactory()
6602 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
6603 f.addStep(shell.Compile(command=["make", "build"]))
6604 @end example
6606 (To support config files from buildbot-0.7.5 and earlier,
6607 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
6608 command=["make","build"])} form, although its use is discouraged
6609 because then the @code{Compile} step doesn't get to validate or
6610 complain about its arguments until build time. The modern
6611 pass-by-instance approach allows this validation to occur while the
6612 config file is being loaded, where the admin has a better chance of
6613 noticing problems).
6615 It is also possible to pass a list of steps into the
6616 @code{BuildFactory} when it is created. Using @code{addStep} is
6617 usually simpler, but there are cases where is is more convenient to
6618 create the list of steps ahead of time.:
6620 @example
6621 from buildbot.steps import source, shell
6622 from buildbot.process import factory
6624 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
6625              shell.Compile(command=["make", "build"]),
6626             ]
6627 f = factory.BuildFactory(all_steps)
6628 @end example
6631 Each step can affect the build process in the following ways:
6633 @itemize @bullet
6634 @item
6635 If the step's @code{haltOnFailure} attribute is True, then a failure
6636 in the step (i.e. if it completes with a result of FAILURE) will cause
6637 the whole build to be terminated immediately: no further steps will be
6638 executed, with the exception of steps with @code{alwaysRun} set to
6639 True. @code{haltOnFailure} is useful for setup steps upon which the
6640 rest of the build depends: if the CVS checkout or @code{./configure}
6641 process fails, there is no point in trying to compile or test the
6642 resulting tree.
6644 @item
6645 If the step's @code{alwaysRun} attribute is True, then it will always
6646 be run, regardless of if previous steps have failed. This is useful
6647 for cleanup steps that should always be run to return the build
6648 directory or build slave into a good state.
6650 @item
6651 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
6652 then a result of FAILURE or WARNINGS will mark the build as a whole as
6653 FAILED. However, the remaining steps will still be executed. This is
6654 appropriate for things like multiple testing steps: a failure in any
6655 one of them will indicate that the build has failed, however it is
6656 still useful to run them all to completion.
6658 @item
6659 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
6660 is set, then a result of FAILURE or WARNINGS will mark the build as
6661 having WARNINGS, and the remaining steps will still be executed. This
6662 may be appropriate for certain kinds of optional build or test steps.
6663 For example, a failure experienced while building documentation files
6664 should be made visible with a WARNINGS result but not be serious
6665 enough to warrant marking the whole build with a FAILURE.
6667 @end itemize
6669 In addition, each Step produces its own results, may create logfiles,
6670 etc. However only the flags described above have any effect on the
6671 build as a whole.
6673 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
6674 reasonably appropriate flags set on them already. For example, without
6675 a source tree there is no point in continuing the build, so the
6676 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
6677 in @file{buildbot/steps/*.py} to see how the other Steps are
6678 marked.
6680 Each Step is created with an additional @code{workdir} argument that
6681 indicates where its actions should take place. This is specified as a
6682 subdirectory of the slave builder's base directory, with a default
6683 value of @code{build}. This is only implemented as a step argument (as
6684 opposed to simply being a part of the base directory) because the
6685 CVS/SVN steps need to perform their checkouts from the parent
6686 directory.
6688 @menu
6689 * BuildFactory Attributes::
6690 * Quick builds::
6691 @end menu
6693 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
6694 @subsubsection BuildFactory Attributes
6696 Some attributes from the BuildFactory are copied into each Build.
6698 @cindex treeStableTimer
6700 @table @code
6701 @item useProgress
6702 (defaults to True): if True, the buildmaster keeps track of how long
6703 each step takes, so it can provide estimates of how long future builds
6704 will take. If builds are not expected to take a consistent amount of
6705 time (such as incremental builds in which a random set of files are
6706 recompiled or tested each time), this should be set to False to
6707 inhibit progress-tracking.
6709 @end table
6712 @node Quick builds,  , BuildFactory Attributes, BuildFactory
6713 @subsubsection Quick builds
6715 @bfindex buildbot.process.factory.QuickBuildFactory
6717 The difference between a ``full build'' and a ``quick build'' is that
6718 quick builds are generally done incrementally, starting with the tree
6719 where the previous build was performed. That simply means that the
6720 source-checkout step should be given a @code{mode='update'} flag, to
6721 do the source update in-place.
6723 In addition to that, the @code{useProgress} flag should be set to
6724 False. Incremental builds will (or at least the ought to) compile as
6725 few files as necessary, so they will take an unpredictable amount of
6726 time to run. Therefore it would be misleading to claim to predict how
6727 long the build will take.
6730 @node Process-Specific build factories,  , BuildFactory, Build Factories
6731 @subsection Process-Specific build factories
6733 Many projects use one of a few popular build frameworks to simplify
6734 the creation and maintenance of Makefiles or other compilation
6735 structures. Buildbot provides several pre-configured BuildFactory
6736 subclasses which let you build these projects with a minimum of fuss.
6738 @menu
6739 * GNUAutoconf::
6740 * CPAN::
6741 * Python distutils::
6742 * Python/Twisted/trial projects::
6743 @end menu
6745 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
6746 @subsubsection GNUAutoconf
6748 @bfindex buildbot.process.factory.GNUAutoconf
6750 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
6751 software portability tool, intended to make it possible to write
6752 programs in C (and other languages) which will run on a variety of
6753 UNIX-like systems. Most GNU software is built using autoconf. It is
6754 frequently used in combination with GNU automake. These tools both
6755 encourage a build process which usually looks like this:
6757 @example
6758 % CONFIG_ENV=foo ./configure --with-flags
6759 % make all
6760 % make check
6761 # make install
6762 @end example
6764 (except of course the Buildbot always skips the @code{make install}
6765 part).
6767 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
6768 designed to build projects which use GNU autoconf and/or automake. The
6769 configuration environment variables, the configure flags, and command
6770 lines used for the compile and test are all configurable, in general
6771 the default values will be suitable.
6773 Example:
6775 @example
6776 # use the s() convenience function defined earlier
6777 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
6778                         flags=["--disable-nls"])
6779 @end example
6781 Required Arguments:
6783 @table @code
6784 @item source
6785 This argument must be a step specification tuple that provides a
6786 BuildStep to generate the source tree.
6787 @end table
6789 Optional Arguments:
6791 @table @code
6792 @item configure
6793 The command used to configure the tree. Defaults to
6794 @code{./configure}. Accepts either a string or a list of shell argv
6795 elements.
6797 @item configureEnv
6798 The environment used for the initial configuration step. This accepts
6799 a dictionary which will be merged into the buildslave's normal
6800 environment. This is commonly used to provide things like
6801 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
6802 Defaults to an empty dictionary.
6804 @item configureFlags
6805 A list of flags to be appended to the argument list of the configure
6806 command. This is commonly used to enable or disable specific features
6807 of the autoconf-controlled package, like @code{["--without-x"]} to
6808 disable windowing support. Defaults to an empty list.
6810 @item compile
6811 this is a shell command or list of argv values which is used to
6812 actually compile the tree. It defaults to @code{make all}. If set to
6813 None, the compile step is skipped.
6815 @item test
6816 this is a shell command or list of argv values which is used to run
6817 the tree's self-tests. It defaults to @code{make check}. If set to
6818 None, the test step is skipped.
6820 @end table
6823 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
6824 @subsubsection CPAN
6826 @bfindex buildbot.process.factory.CPAN
6828 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
6829 archive use the @code{MakeMaker} module to provide configuration,
6830 build, and test services. The standard build routine for these modules
6831 looks like:
6833 @example
6834 % perl Makefile.PL
6835 % make
6836 % make test
6837 # make install
6838 @end example
6840 (except again Buildbot skips the install step)
6842 Buildbot provides a @code{CPAN} factory to compile and test these
6843 projects.
6846 Arguments:
6847 @table @code
6848 @item source
6849 (required): A step specification tuple, like that used by GNUAutoconf.
6851 @item perl
6852 A string which specifies the @code{perl} executable to use. Defaults
6853 to just @code{perl}.
6855 @end table
6858 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
6859 @subsubsection Python distutils
6861 @bfindex buildbot.process.factory.Distutils
6863 Most Python modules use the @code{distutils} package to provide
6864 configuration and build services. The standard build process looks
6865 like:
6867 @example
6868 % python ./setup.py build
6869 % python ./setup.py install
6870 @end example
6872 Unfortunately, although Python provides a standard unit-test framework
6873 named @code{unittest}, to the best of my knowledge @code{distutils}
6874 does not provide a standardized target to run such unit tests. (Please
6875 let me know if I'm wrong, and I will update this factory.)
6877 The @code{Distutils} factory provides support for running the build
6878 part of this process. It accepts the same @code{source=} parameter as
6879 the other build factories.
6882 Arguments:
6883 @table @code
6884 @item source
6885 (required): A step specification tuple, like that used by GNUAutoconf.
6887 @item python
6888 A string which specifies the @code{python} executable to use. Defaults
6889 to just @code{python}.
6891 @item test
6892 Provides a shell command which runs unit tests. This accepts either a
6893 string or a list. The default value is None, which disables the test
6894 step (since there is no common default command to run unit tests in
6895 distutils modules).
6897 @end table
6900 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
6901 @subsubsection Python/Twisted/trial projects
6903 @bfindex buildbot.process.factory.Trial
6904 @c TODO: document these steps better
6905 @bsindex buildbot.steps.python_twisted.HLint
6906 @bsindex buildbot.steps.python_twisted.Trial
6907 @bsindex buildbot.steps.python_twisted.ProcessDocs
6908 @bsindex buildbot.steps.python_twisted.BuildDebs
6909 @bsindex buildbot.steps.python_twisted.RemovePYCs
6911 Twisted provides a unit test tool named @code{trial} which provides a
6912 few improvements over Python's built-in @code{unittest} module. Many
6913 python projects which use Twisted for their networking or application
6914 services also use trial for their unit tests. These modules are
6915 usually built and tested with something like the following:
6917 @example
6918 % python ./setup.py build
6919 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
6920 % python ./setup.py install
6921 @end example
6923 Unfortunately, the @file{build/lib} directory into which the
6924 built/copied .py files are placed is actually architecture-dependent,
6925 and I do not yet know of a simple way to calculate its value. For many
6926 projects it is sufficient to import their libraries ``in place'' from
6927 the tree's base directory (@code{PYTHONPATH=.}).
6929 In addition, the @var{PROJECTNAME} value where the test files are
6930 located is project-dependent: it is usually just the project's
6931 top-level library directory, as common practice suggests the unit test
6932 files are put in the @code{test} sub-module. This value cannot be
6933 guessed, the @code{Trial} class must be told where to find the test
6934 files.
6936 The @code{Trial} class provides support for building and testing
6937 projects which use distutils and trial. If the test module name is
6938 specified, trial will be invoked. The library path used for testing
6939 can also be set.
6941 One advantage of trial is that the Buildbot happens to know how to
6942 parse trial output, letting it identify which tests passed and which
6943 ones failed. The Buildbot can then provide fine-grained reports about
6944 how many tests have failed, when individual tests fail when they had
6945 been passing previously, etc.
6947 Another feature of trial is that you can give it a series of source
6948 .py files, and it will search them for special @code{test-case-name}
6949 tags that indicate which test cases provide coverage for that file.
6950 Trial can then run just the appropriate tests. This is useful for
6951 quick builds, where you want to only run the test cases that cover the
6952 changed functionality.
6954 Arguments:
6955 @table @code
6956 @item source
6957 (required): A step specification tuple, like that used by GNUAutoconf.
6959 @item buildpython
6960 A list (argv array) of strings which specifies the @code{python}
6961 executable to use when building the package. Defaults to just
6962 @code{['python']}. It may be useful to add flags here, to supress
6963 warnings during compilation of extension modules. This list is
6964 extended with @code{['./setup.py', 'build']} and then executed in a
6965 ShellCommand.
6967 @item testpath
6968 Provides a directory to add to @code{PYTHONPATH} when running the unit
6969 tests, if tests are being run. Defaults to @code{.} to include the
6970 project files in-place. The generated build library is frequently
6971 architecture-dependent, but may simply be @file{build/lib} for
6972 pure-python modules.
6974 @item trialpython
6975 Another list of strings used to build the command that actually runs
6976 trial. This is prepended to the contents of the @code{trial} argument
6977 below. It may be useful to add @code{-W} flags here to supress
6978 warnings that occur while tests are being run. Defaults to an empty
6979 list, meaning @code{trial} will be run without an explicit
6980 interpreter, which is generally what you want if you're using
6981 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
6982 lives in the Twisted source tree.
6984 @item trial
6985 provides the name of the @code{trial} command. It is occasionally
6986 useful to use an alternate executable, such as @code{trial2.2} which
6987 might run the tests under an older version of Python. Defaults to
6988 @code{trial}.
6990 @item tests
6991 Provides a module name or names which contain the unit tests for this
6992 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
6993 list of strings. Defaults to None, indicating that no tests should be
6994 run. You must either set this or @code{useTestCaseNames} to do anyting
6995 useful with the Trial factory.
6997 @item useTestCaseNames
6998 Tells the Step to provide the names of all changed .py files to trial,
6999 so it can look for test-case-name tags and run just the matching test
7000 cases. Suitable for use in quick builds. Defaults to False.
7002 @item randomly
7003 If @code{True}, tells Trial (with the @code{--random=0} argument) to
7004 run the test cases in random order, which sometimes catches subtle
7005 inter-test dependency bugs. Defaults to @code{False}.
7007 @item recurse
7008 If @code{True}, tells Trial (with the @code{--recurse} argument) to
7009 look in all subdirectories for additional test cases. It isn't clear
7010 to me how this works, but it may be useful to deal with the
7011 unknown-PROJECTNAME problem described above, and is currently used in
7012 the Twisted buildbot to accomodate the fact that test cases are now
7013 distributed through multiple twisted.SUBPROJECT.test directories.
7015 @end table
7017 Unless one of @code{trialModule} or @code{useTestCaseNames}
7018 are set, no tests will be run.
7020 Some quick examples follow. Most of these examples assume that the
7021 target python code (the ``code under test'') can be reached directly
7022 from the root of the target tree, rather than being in a @file{lib/}
7023 subdirectory.
7025 @example
7026 #  Trial(source, tests="toplevel.test") does:
7027 #   python ./setup.py build
7028 #   PYTHONPATH=. trial -to toplevel.test
7030 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
7031 #   python ./setup.py build
7032 #   PYTHONPATH=. trial -to toplevel.test other.test
7034 #  Trial(source, useTestCaseNames=True) does:
7035 #   python ./setup.py build
7036 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
7038 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
7039 #   python2.3 -Wall ./setup.py build
7040 #   PYTHONPATH=. trial -to foo.tests
7042 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
7043 #        tests="foo.tests") does:
7044 #   python2.3 -Wall ./setup.py build
7045 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
7047 # For running trial out of the tree being tested (only useful when the
7048 # tree being built is Twisted itself):
7049 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
7050 #        tests="foo.tests") does:
7051 #   python2.3 -Wall ./setup.py build
7052 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
7053 @end example
7055 If the output directory of @code{./setup.py build} is known, you can
7056 pull the python code from the built location instead of the source
7057 directories. This should be able to handle variations in where the
7058 source comes from, as well as accomodating binary extension modules:
7060 @example
7061 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
7062 # does:
7063 #  python ./setup.py build
7064 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
7065 @end example
7068 @node Status Delivery, Command-line tool, Build Process, Top
7069 @chapter Status Delivery
7071 More details are available in the docstrings for each class, use a
7072 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
7073 Most status delivery objects take a @code{categories=} argument, which
7074 can contain a list of ``category'' names: in this case, it will only
7075 show status for Builders that are in one of the named categories.
7077 (implementor's note: each of these objects should be a
7078 service.MultiService which will be attached to the BuildMaster object
7079 when the configuration is processed. They should use
7080 @code{self.parent.getStatus()} to get access to the top-level IStatus
7081 object, either inside @code{startService} or later. They may call
7082 @code{status.subscribe()} in @code{startService} to receive
7083 notifications of builder events, in which case they must define
7084 @code{builderAdded} and related methods. See the docstrings in
7085 @file{buildbot/interfaces.py} for full details.)
7087 @menu
7088 * WebStatus::
7089 * MailNotifier::
7090 * IRC Bot::
7091 * PBListener::
7092 * Writing New Status Plugins::
7093 @end menu
7095 @c @node Email Delivery,  , Status Delivery, Status Delivery
7096 @c @subsection Email Delivery
7098 @c DOCUMENT THIS
7101 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
7102 @section WebStatus
7104 @cindex WebStatus
7105 @stindex buildbot.status.web.baseweb.WebStatus
7107 The @code{buildbot.status.html.WebStatus} status target runs a small
7108 web server inside the buildmaster. You can point a browser at this web
7109 server and retrieve information about every build the buildbot knows
7110 about, as well as find out what the buildbot is currently working on.
7112 The first page you will see is the ``Welcome Page'', which contains
7113 links to all the other useful pages. This page is simply served from
7114 the @file{public_html/index.html} file in the buildmaster's base
7115 directory, where it is created by the @command{buildbot create-master}
7116 command along with the rest of the buildmaster.
7118 The most complex resource provided by @code{WebStatus} is the
7119 ``Waterfall Display'', which shows a time-based chart of events. This
7120 somewhat-busy display provides detailed information about all steps of
7121 all recent builds, and provides hyperlinks to look at individual build
7122 logs and source changes. By simply reloading this page on a regular
7123 basis, you will see a complete description of everything the buildbot
7124 is currently working on.
7126 There are also pages with more specialized information. For example,
7127 there is a page which shows the last 20 builds performed by the
7128 buildbot, one line each. Each line is a link to detailed information
7129 about that build. By adding query arguments to the URL used to reach
7130 this page, you can narrow the display to builds that involved certain
7131 branches, or which ran on certain Builders. These pages are described
7132 in great detail below.
7135 When the buildmaster is created, a subdirectory named
7136 @file{public_html/} is created in its base directory. By default, @code{WebStatus}
7137 will serve files from this directory: for example, when a user points
7138 their browser at the buildbot's @code{WebStatus} URL, they will see
7139 the contents of the @file{public_html/index.html} file. Likewise,
7140 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
7141 @file{public_html/favicon.ico} are all useful things to have in there.
7142 The first time a buildmaster is created, the @file{public_html}
7143 directory is populated with some sample files, which you will probably
7144 want to customize for your own project. These files are all static:
7145 the buildbot does not modify them in any way as it serves them to HTTP
7146 clients.
7148 @example
7149 from buildbot.status.html import WebStatus
7150 c['status'].append(WebStatus(8080))
7151 @end example
7153 Note that the initial robots.txt file has Disallow lines for all of
7154 the dynamically-generated buildbot pages, to discourage web spiders
7155 and search engines from consuming a lot of CPU time as they crawl
7156 through the entire history of your buildbot. If you are running the
7157 buildbot behind a reverse proxy, you'll probably need to put the
7158 robots.txt file somewhere else (at the top level of the parent web
7159 server), and replace the URL prefixes in it with more suitable values.
7161 If you would like to use an alternative root directory, add the
7162 @code{public_html=..} option to the @code{WebStatus} creation:
7164 @example
7165 c['status'].append(WebStatus(8080, public_html="/var/www/buildbot"))
7166 @end example
7168 In addition, if you are familiar with twisted.web @emph{Resource
7169 Trees}, you can write code to add additional pages at places inside
7170 this web space. Just use @code{webstatus.putChild} to place these
7171 resources.
7173 The following section describes the special URLs and the status views
7174 they provide.
7177 @menu
7178 * WebStatus Configuration Parameters::
7179 * Buildbot Web Resources::
7180 * XMLRPC server::
7181 * HTML Waterfall::
7182 @end menu
7184 @node WebStatus Configuration Parameters, Buildbot Web Resources, WebStatus, WebStatus
7185 @subsection WebStatus Configuration Parameters
7187 The most common way to run a @code{WebStatus} is on a regular TCP
7188 port. To do this, just pass in the TCP port number when you create the
7189 @code{WebStatus} instance; this is called the @code{http_port} argument:
7191 @example
7192 from buildbot.status.html import WebStatus
7193 c['status'].append(WebStatus(8080))
7194 @end example
7196 The @code{http_port} argument is actually a ``strports specification''
7197 for the port that the web server should listen on. This can be a
7198 simple port number, or a string like
7199 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
7200 loopback interface, and therefore to clients running on the same
7201 host)@footnote{It may even be possible to provide SSL access by using
7202 a specification like
7203 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
7204 completely untested}.
7206 If instead (or in addition) you provide the @code{distrib_port}
7207 argument, a twisted.web distributed server will be started either on a
7208 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
7209 likely on a UNIX socket (if @code{distrib_port} is like
7210 @code{"unix:/path/to/socket"}).
7212 The @code{distrib_port} option means that, on a host with a
7213 suitably-configured twisted-web server, you do not need to consume a
7214 separate TCP port for the buildmaster's status web page. When the web
7215 server is constructed with @code{mktap web --user}, URLs that point to
7216 @code{http://host/~username/} are dispatched to a sub-server that is
7217 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
7218 such a system, it is convenient to create a dedicated @code{buildbot}
7219 user, then set @code{distrib_port} to
7220 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
7221 configuration will make the HTML status page available at
7222 @code{http://host/~buildbot/} . Suitable URL remapping can make it
7223 appear at @code{http://host/buildbot/}, and the right virtual host
7224 setup can even place it at @code{http://buildbot.host/} .
7226 The other @code{WebStatus} argument is @code{allowForce}. If set to
7227 True, then the web page will provide a ``Force Build'' button that
7228 allows visitors to manually trigger builds. This is useful for
7229 developers to re-run builds that have failed because of intermittent
7230 problems in the test suite, or because of libraries that were not
7231 installed at the time of the previous build. You may not wish to allow
7232 strangers to cause a build to run: in that case, set this to False to
7233 remove these buttons. The default value is False.
7237 @node Buildbot Web Resources, XMLRPC server, WebStatus Configuration Parameters, WebStatus
7238 @subsection Buildbot Web Resources
7240 Certain URLs are ``magic'', and the pages they serve are created by
7241 code in various classes in the @file{buildbot.status.web} package
7242 instead of being read from disk. The most common way to access these
7243 pages is for the buildmaster admin to write or modify the
7244 @file{index.html} page to contain links to them. Of course other
7245 project web pages can contain links to these buildbot pages as well.
7247 Many pages can be modified by adding query arguments to the URL. For
7248 example, a page which shows the results of the most recent build
7249 normally does this for all builders at once. But by appending
7250 ``?builder=i386'' to the end of the URL, the page will show only the
7251 results for the ``i386'' builder. When used in this way, you can add
7252 multiple ``builder='' arguments to see multiple builders. Remembering
7253 that URL query arguments are separated @emph{from each other} with
7254 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
7255 show builds for just those two Builders.
7257 The @code{branch=} query argument can be used on some pages. This
7258 filters the information displayed by that page down to only the builds
7259 or changes which involved the given branch. Use @code{branch=trunk} to
7260 reference the trunk: if you aren't intentionally using branches,
7261 you're probably using trunk. Multiple @code{branch=} arguments can be
7262 used to examine multiple branches at once (so appending
7263 @code{?branch=foo&branch=bar} to the URL will show builds involving
7264 either branch). No @code{branch=} arguments means to show builds and
7265 changes for all branches.
7267 Some pages may include the Builder name or the build number in the
7268 main part of the URL itself. For example, a page that describes Build
7269 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
7271 The table below lists all of the internal pages and the URLs that can
7272 be used to access them.
7274 NOTE: of the pages described here, @code{/slave_status_timeline} and
7275 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
7276 has only a few methods so far. Future releases will improve this.
7278 @table @code
7280 @item /waterfall
7282 This provides a chronologically-oriented display of the activity of
7283 all builders. It is the same display used by the Waterfall display.
7285 By adding one or more ``builder='' query arguments, the Waterfall is
7286 restricted to only showing information about the given Builders. By
7287 adding one or more ``branch='' query arguments, the display is
7288 restricted to showing information about the given branches. In
7289 addition, adding one or more ``category='' query arguments to the URL
7290 will limit the display to Builders that were defined with one of the
7291 given categories.
7293 A 'show_events=true' query argument causes the display to include
7294 non-Build events, like slaves attaching and detaching, as well as
7295 reconfiguration events. 'show_events=false' hides these events. The
7296 default is to show them.
7298 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
7299 arguments will control what interval of time is displayed. The default
7300 is to show the latest events, but these can be used to look at earlier
7301 periods in history. The @code{num_events=} argument also provides a
7302 limit on the size of the displayed page.
7304 The Waterfall has references to resources many of the other portions
7305 of the URL space: @file{/builders} for access to individual builds,
7306 @file{/changes} for access to information about source code changes,
7307 etc.
7309 @item /rss
7311 This provides a rss feed summarizing all failed builds. The same
7312 query-arguments used by 'waterfall' can be added to filter the
7313 feed output.
7315 @item /atom
7317 This provides an atom feed summarizing all failed builds. The same
7318 query-arguments used by 'waterfall' can be added to filter the feed
7319 output.
7321 @item /builders/$BUILDERNAME
7323 This describes the given Builder, and provides buttons to force a build.
7325 @item /builders/$BUILDERNAME/builds/$BUILDNUM
7327 This describes a specific Build.
7329 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
7331 This describes a specific BuildStep.
7333 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
7335 This provides an HTML representation of a specific logfile.
7337 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
7339 This returns the logfile as plain text, without any HTML coloring
7340 markup. It also removes the ``headers'', which are the lines that
7341 describe what command was run and what the environment variable
7342 settings were like. This maybe be useful for saving to disk and
7343 feeding to tools like 'grep'.
7345 @item /changes
7347 This provides a brief description of the ChangeSource in use
7348 (@pxref{Change Sources}).
7350 @item /changes/NN
7352 This shows detailed information about the numbered Change: who was the
7353 author, what files were changed, what revision number was represented,
7354 etc.
7356 @item /buildslaves
7358 This summarizes each BuildSlave, including which Builders are
7359 configured to use it, whether the buildslave is currently connected or
7360 not, and host information retrieved from the buildslave itself.
7362 @item /one_line_per_build
7364 This page shows one line of text for each build, merging information
7365 from all Builders@footnote{Apparently this is the same way
7366 http://buildd.debian.org displays build status}. Each line specifies
7367 the name of the Builder, the number of the Build, what revision it
7368 used, and a summary of the results. Successful builds are in green,
7369 while failing builds are in red. The date and time of the build are
7370 added to the right-hand edge of the line. The lines are ordered by
7371 build finish timestamp.
7373 One or more @code{builder=} or @code{branch=} arguments can be used to
7374 restrict the list. In addition, a @code{numbuilds=} argument will
7375 control how many lines are displayed (20 by default).
7377 @item /one_box_per_builder
7379 This page shows a small table, with one box for each Builder,
7380 containing the results of the most recent Build. It does not show the
7381 individual steps, or the current status. This is a simple summary of
7382 buildbot status: if this page is green, then all tests are passing.
7384 As with @code{/one_line_per_build}, this page will also honor
7385 @code{builder=} and @code{branch=} arguments.
7387 @item /about
7389 This page gives a brief summary of the Buildbot itself: software
7390 version, versions of some libraries that the Buildbot depends upon,
7391 etc. It also contains a link to the buildbot.net home page.
7393 @item /slave_status_timeline
7395 (note: this page has not yet been implemented)
7397 This provides a chronological display of configuration and operational
7398 events: master startup/shutdown, slave connect/disconnect, and
7399 config-file changes. When a config-file reload is abandoned because of
7400 an error in the config file, the error is displayed on this page.
7402 This page does not show any builds.
7404 @item /last_build/$BUILDERNAME/status.png
7406 This returns a PNG image that describes the results of the most recent
7407 build, which can be referenced in an IMG tag by other pages, perhaps
7408 from a completely different site. Use it as you would a webcounter.
7410 @end table
7412 There are also a set of web-status resources that are intended for use
7413 by other programs, rather than humans.
7415 @table @code
7417 @item /xmlrpc
7419 This runs an XML-RPC server which can be used to query status
7420 information about various builds. See @ref{XMLRPC server} for more
7421 details.
7423 @end table
7425 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
7426 @subsection XMLRPC server
7428 When using WebStatus, the buildbot runs an XML-RPC server at
7429 @file{/xmlrpc} that can be used by other programs to query build
7430 status. The following table lists the methods that can be invoked
7431 using this interface.
7433 @table @code
7434 @item getAllBuildsInInterval(start, stop)
7436 Return a list of builds that have completed after the 'start'
7437 timestamp and before the 'stop' timestamp. This looks at all Builders.
7439 The timestamps are integers, interpreted as standard unix timestamps
7440 (seconds since epoch).
7442 Each Build is returned as a tuple in the form: @code{(buildername,
7443 buildnumber, build_end, branchname, revision, results, text)}
7445 The buildnumber is an integer. 'build_end' is an integer (seconds
7446 since epoch) specifying when the build finished.
7448 The branchname is a string, which may be an empty string to indicate
7449 None (i.e. the default branch). The revision is a string whose meaning
7450 is specific to the VC system in use, and comes from the 'got_revision'
7451 build property. The results are expressed as a string, one of
7452 ('success', 'warnings', 'failure', 'exception'). The text is a list of
7453 short strings that ought to be joined by spaces and include slightly
7454 more data about the results of the build.
7456 @item getBuild(builder_name, build_number)
7458 Return information about a specific build.
7460 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
7461 complete information about the build. It does not include the contents
7462 of the log files, but it has just about everything else.
7464 @end table
7466 @node HTML Waterfall,  , XMLRPC server, WebStatus
7467 @subsection HTML Waterfall
7469 @cindex Waterfall
7470 @stindex buildbot.status.html.Waterfall
7472 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
7473 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
7474 This section (and the @code{Waterfall} class itself) will be removed
7475 from a future release.
7477 @example
7478 from buildbot.status import html
7479 w = html.WebStatus(http_port=8080)
7480 c['status'].append(w)
7481 @end example
7485 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
7486 @section MailNotifier
7488 @cindex email
7489 @cindex mail
7490 @stindex buildbot.status.mail.MailNotifier
7492 The buildbot can also send email when builds finish. The most common
7493 use of this is to tell developers when their change has caused the
7494 build to fail. It is also quite common to send a message to a mailing
7495 list (usually named ``builds'' or similar) about every build.
7497 The @code{MailNotifier} status target is used to accomplish this. You
7498 configure it by specifying who mail should be sent to, under what
7499 circumstances mail should be sent, and how to deliver the mail. It can
7500 be configured to only send out mail for certain builders, and only
7501 send messages when the build fails, or when the builder transitions
7502 from success to failure. It can also be configured to include various
7503 build logs in each message.
7506 By default, the message will be sent to the Interested Users list
7507 (@pxref{Doing Things With Users}), which includes all developers who
7508 made changes in the build. You can add additional recipients with the
7509 extraRecipients argument.
7511 Each MailNotifier sends mail to a single set of recipients. To send
7512 different kinds of mail to different recipients, use multiple
7513 MailNotifiers.
7515 The following simple example will send an email upon the completion of
7516 each build, to just those developers whose Changes were included in
7517 the build. The email contains a description of the Build, its results,
7518 and URLs where more information can be obtained.
7520 @example
7521 from buildbot.status.mail import MailNotifier
7522 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
7523 c['status'].append(mn)
7524 @end example
7526 To get a simple one-message-per-build (say, for a mailing list), use
7527 the following form instead. This form does not send mail to individual
7528 developers (and thus does not need the @code{lookup=} argument,
7529 explained below), instead it only ever sends mail to the ``extra
7530 recipients'' named in the arguments:
7532 @example
7533 mn = MailNotifier(fromaddr="buildbot@@example.org",
7534                   sendToInterestedUsers=False,
7535                   extraRecipients=['listaddr@@example.org'])
7536 @end example
7538 In some cases it is desirable to have different information then what
7539 is provided in a standard MailNotifier message. For this purpose 
7540 MailNotifier provides the argument customMesg (a function) which allows 
7541 for the creation of messages with unique content.
7543 For example it can be useful to display the last few lines of a log file 
7544 and recent changes when a builder fails:
7546 @example
7547 def message(attrs):
7548     logLines = 10
7549     text = list()
7550     text.append("STATUS: %s" % attrs['result'].title())
7551     text.append("")
7552     text.extend([c.asText() for c in attrs['changes']])
7553     text.append("")
7554     name, url, lines = attrs['logs'][-1]
7555     text.append("Last %d lines of '%s':" % (logLines, name))
7556     text.extend(["\t%s\n" % line for line in lines[len(lines)-logLines:]])
7557     text.append("")
7558     text.append("-buildbot")
7559     return ("\n".join(text), 'plain')
7561 mn = MailNotifier(fromaddr="buildbot@@example.org",
7562                   sendToInterestedUsers=False,
7563                   mode='problem',
7564                   extraRecipients=['listaddr@@example.org'],
7565                   customMesg=message)
7566 @end example
7568 A customMesg function takes a single dict argument (see below) and returns a 
7569 tuple of strings. The first string is the complete text of the message and the
7570 second is the message type ('plain' or 'html'). The 'html' type should be used
7571 when generating an HTML message: 
7573 @example
7574 def message(attrs):
7575     logLines = 10
7576     text = list()
7577     text.append('<h4>Build status %s.</h4>' % (attrs['result'].title()))
7578     if attrs['changes']:
7579         text.append('<h4>Recent Changes:</h4>')
7580         text.extend([c.asHTML() for c in attrs['changes']])
7581     name, url, lines = attrs['logs'][-1]
7582     text.append('<h4>Last %d lines of "%s":</h4>' % (logLines, name))
7583     text.append('<p>')
7584     text.append('<br>'.join([line for line in lines[len(lines)-logLines:]]))
7585     text.append('</p>')
7586     text.append('<br><br>')
7587     text.append('Full log at: %s' % url)
7588     text.append('<br><br>')
7589     text.append('<b>-buildbot</b>')
7590     return ('\n'.join(text), 'html')
7591 @end example 
7593 @heading MailNotifier arguments
7595 @table @code
7596 @item fromaddr
7597 The email address to be used in the 'From' header.
7599 @item sendToInterestedUsers
7600 (boolean). If True (the default), send mail to all of the Interested
7601 Users. If False, only send mail to the extraRecipients list.
7603 @item extraRecipients
7604 (tuple of strings). A list of email addresses to which messages should
7605 be sent (in addition to the InterestedUsers list, which includes any
7606 developers who made Changes that went into this build). It is a good
7607 idea to create a small mailing list and deliver to that, then let
7608 subscribers come and go as they please.
7610 @item subject
7611 (string). A string to be used as the subject line of the message.
7612 @code{%(builder)s} will be replaced with the name of the builder which
7613 provoked the message.
7615 @item mode
7616 (string). Default to 'all'. One of:
7617 @table @code
7618 @item all
7619 Send mail about all builds, bothpassing and failing
7620 @item failing
7621 Only send mail about builds which fail
7622 @item problem
7623 Only send mail about a build which failed when the previous build has passed.
7624 If your builds usually pass, then this will only send mail when a problem
7625 occurs.
7626 @end table
7628 @item builders
7629 (list of strings). A list of builder names for which mail should be
7630 sent. Defaults to None (send mail for all builds). Use either builders
7631 or categories, but not both.
7633 @item categories
7634 (list of strings). A list of category names to serve status
7635 information for. Defaults to None (all categories). Use either
7636 builders or categories, but not both.
7638 @item addLogs
7639 (boolean). If True, include all build logs as attachments to the
7640 messages. These can be quite large. This can also be set to a list of
7641 log names, to send a subset of the logs. Defaults to False.
7643 @item relayhost
7644 (string). The host to which the outbound SMTP connection should be
7645 made. Defaults to 'localhost'
7647 @item lookup
7648 (implementor of @code{IEmailLookup}). Object which provides
7649 IEmailLookup, which is responsible for mapping User names (which come
7650 from the VC system) into valid email addresses. If not provided, the
7651 notifier will only be able to send mail to the addresses in the
7652 extraRecipients list. Most of the time you can use a simple Domain
7653 instance. As a shortcut, you can pass as string: this will be treated
7654 as if you had provided Domain(str). For example,
7655 lookup='twistedmatrix.com' will allow mail to be sent to all
7656 developers whose SVN usernames match their twistedmatrix.com account
7657 names. See buildbot/status/mail.py for more details.
7659 @item customMesg
7660 This is a optional function that can be used to generate a custom mail 
7661 message. The customMesg function takes a single dict and must return a 
7662 tuple containing the message text and type ('html' or 'plain'). Below is a list 
7663 of availale keys in the dict passed to customMesg:
7665 @table @code
7666 @item builderName 
7667 (str) Name of the builder that generated this event.
7668 @item projectName 
7669 (str) Name of the project.
7670 @item mode 
7671 (str) Mode set in MailNotifier. (failing, passing, problem).
7672 @item result 
7673 (str) Builder result as a string. 'success', 'warnings', 'failure', 'skipped', or 'exception'
7674 @item buildURL 
7675 (str) URL to build page.
7676 @item buildbotURL 
7677 (str) URL to buildbot main page.
7678 @item buildText 
7679 (str) Build text from build.getText().
7680 @item slavename 
7681 (str) Slavename.
7682 @item reason 
7683 (str) Build reason from build.getReason().
7684 @item responsibleUsers 
7685 (List of str) List of responsible users.
7686 @item branch 
7687 (str) Name of branch used. If no SourceStamp exists branch
7688 is an empty string.
7689 @item revision 
7690 (str) Name of revision used. If no SourceStamp exists revision
7691 is an empty string.
7692 @item patch 
7693 (str) Name of patch used. If no SourceStamp exists patch
7694 is an empty string.
7695 @item changes
7696 (list of objs) List of change objects from SourceStamp. A change
7697 object has the following useful information:
7698 @table @code
7699 @item who
7700 (str) who made this change
7701 @item revision 
7702 (str) what VC revision is this change
7703 @item branch 
7704 (str) on what branch did this change occur
7705 @item when 
7706 (str) when did this change occur
7707 @item files 
7708 (list of str) what files were affected in this change
7709 @item comments 
7710 (str) comments reguarding the change.
7711 @end table
7712 The functions asText and asHTML return a list of strings with
7713 the above information formatted. 
7714 @item logs
7715 (List of Tuples) List of tuples where each tuple contains the log name, log url,
7716 and log contents as a list of strings.
7717 @end table
7718 @end table
7720 @node IRC Bot, PBListener, MailNotifier, Status Delivery
7721 @section IRC Bot
7723 @cindex IRC
7724 @stindex buildbot.status.words.IRC
7727 The @code{buildbot.status.words.IRC} status target creates an IRC bot
7728 which will attach to certain channels and be available for status
7729 queries. It can also be asked to announce builds as they occur, or be
7730 told to shut up.
7732 @example
7733 from buildbot.status import words
7734 irc = words.IRC("irc.example.org", "botnickname",
7735                 channels=["channel1", "channel2"],
7736                 password="mysecretpassword",
7737                 notify_events={
7738                   'exception': 1,
7739                   'successToFailure': 1,
7740                   'failureToSuccess': 1,
7741                 })
7742 c['status'].append(irc)
7743 @end example
7745 Take a look at the docstring for @code{words.IRC} for more details on
7746 configuring this service. The @code{password} argument, if provided,
7747 will be sent to Nickserv to claim the nickname: some IRC servers will
7748 not allow clients to send private messages until they have logged in
7749 with a password.
7751 To use the service, you address messages at the buildbot, either
7752 normally (@code{botnickname: status}) or with private messages
7753 (@code{/msg botnickname status}). The buildbot will respond in kind.
7755 Some of the commands currently available:
7757 @table @code
7759 @item list builders
7760 Emit a list of all configured builders
7761 @item status BUILDER
7762 Announce the status of a specific Builder: what it is doing right now.
7763 @item status all
7764 Announce the status of all Builders
7765 @item watch BUILDER
7766 If the given Builder is currently running, wait until the Build is
7767 finished and then announce the results.
7768 @item last BUILDER
7769 Return the results of the last build to run on the given Builder.
7770 @item join CHANNEL
7771 Join the given IRC channel
7772 @item leave CHANNEL
7773 Leave the given IRC channel
7774 @item notify on|off|list EVENT
7775 Report events relating to builds.  If the command is issued as a
7776 private message, then the report will be sent back as a private
7777 message to the user who issued the command.  Otherwise, the report
7778 will be sent to the channel.  Available events to be notified are:
7780 @table @code
7781 @item started
7782 A build has started
7783 @item finished
7784 A build has finished
7785 @item success
7786 A build finished successfully
7787 @item failed
7788 A build failed
7789 @item exception
7790 A build generated and exception
7791 @item xToY
7792 The previous build was x, but this one is Y, where x and Y are each
7793 one of success, warnings, failure, exception (except Y is
7794 capitalized).  For example: successToFailure will notify if the
7795 previous build was successful, but this one failed
7796 @end table
7798 @item help COMMAND
7799 Describe a command. Use @code{help commands} to get a list of known
7800 commands.
7801 @item source
7802 Announce the URL of the Buildbot's home page.
7803 @item version
7804 Announce the version of this Buildbot.
7805 @end table
7807 Additionally, the config file may specify default notification options
7808 as shown in the example earlier.
7810 If the @code{allowForce=True} option was used, some addtional commands
7811 will be available:
7813 @table @code
7814 @item force build BUILDER REASON
7815 Tell the given Builder to start a build of the latest code. The user
7816 requesting the build and REASON are recorded in the Build status. The
7817 buildbot will announce the build's status when it finishes.
7819 @item stop build BUILDER REASON
7820 Terminate any running build in the given Builder. REASON will be added
7821 to the build status to explain why it was stopped. You might use this
7822 if you committed a bug, corrected it right away, and don't want to
7823 wait for the first build (which is destined to fail) to complete
7824 before starting the second (hopefully fixed) build.
7825 @end table
7827 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
7828 @section PBListener
7830 @cindex PBListener
7831 @stindex buildbot.status.client.PBListener
7834 @example
7835 import buildbot.status.client
7836 pbl = buildbot.status.client.PBListener(port=int, user=str,
7837                                         passwd=str)
7838 c['status'].append(pbl)
7839 @end example
7841 This sets up a PB listener on the given TCP port, to which a PB-based
7842 status client can connect and retrieve status information.
7843 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
7844 status client. The @code{port} argument can also be a strports
7845 specification string.
7847 @node Writing New Status Plugins,  , PBListener, Status Delivery
7848 @section Writing New Status Plugins
7850 TODO: this needs a lot more examples
7852 Each status plugin is an object which provides the
7853 @code{twisted.application.service.IService} interface, which creates a
7854 tree of Services with the buildmaster at the top [not strictly true].
7855 The status plugins are all children of an object which implements
7856 @code{buildbot.interfaces.IStatus}, the main status object. From this
7857 object, the plugin can retrieve anything it wants about current and
7858 past builds. It can also subscribe to hear about new and upcoming
7859 builds.
7861 Status plugins which only react to human queries (like the Waterfall
7862 display) never need to subscribe to anything: they are idle until
7863 someone asks a question, then wake up and extract the information they
7864 need to answer it, then they go back to sleep. Plugins which need to
7865 act spontaneously when builds complete (like the MailNotifier plugin)
7866 need to subscribe to hear about new builds.
7868 If the status plugin needs to run network services (like the HTTP
7869 server used by the Waterfall plugin), they can be attached as Service
7870 children of the plugin itself, using the @code{IServiceCollection}
7871 interface.
7875 @node Command-line tool, Resources, Status Delivery, Top
7876 @chapter Command-line tool
7878 The @command{buildbot} command-line tool can be used to start or stop a
7879 buildmaster or buildbot, and to interact with a running buildmaster.
7880 Some of its subcommands are intended for buildmaster admins, while
7881 some are for developers who are editing the code that the buildbot is
7882 monitoring.
7884 @menu
7885 * Administrator Tools::
7886 * Developer Tools::
7887 * Other Tools::
7888 * .buildbot config directory::
7889 @end menu
7891 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
7892 @section Administrator Tools
7894 The following @command{buildbot} sub-commands are intended for
7895 buildmaster administrators:
7897 @heading create-master
7899 This creates a new directory and populates it with files that allow it
7900 to be used as a buildmaster's base directory.
7902 @example
7903 buildbot create-master BASEDIR
7904 @end example
7906 @heading create-slave
7908 This creates a new directory and populates it with files that let it
7909 be used as a buildslave's base directory. You must provide several
7910 arguments, which are used to create the initial @file{buildbot.tac}
7911 file.
7913 @example
7914 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
7915 @end example
7917 @heading start
7919 This starts a buildmaster or buildslave which was already created in
7920 the given base directory. The daemon is launched in the background,
7921 with events logged to a file named @file{twistd.log}.
7923 @example
7924 buildbot start BASEDIR
7925 @end example
7927 @heading stop
7929 This terminates the daemon (either buildmaster or buildslave) running
7930 in the given directory.
7932 @example
7933 buildbot stop BASEDIR
7934 @end example
7936 @heading sighup
7938 This sends a SIGHUP to the buildmaster running in the given directory,
7939 which causes it to re-read its @file{master.cfg} file.
7941 @example
7942 buildbot sighup BASEDIR
7943 @end example
7945 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
7946 @section Developer Tools
7948 These tools are provided for use by the developers who are working on
7949 the code that the buildbot is monitoring.
7951 @menu
7952 * statuslog::
7953 * statusgui::
7954 * try::
7955 @end menu
7957 @node statuslog, statusgui, Developer Tools, Developer Tools
7958 @subsection statuslog
7960 @example
7961 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
7962 @end example
7964 This command starts a simple text-based status client, one which just
7965 prints out a new line each time an event occurs on the buildmaster.
7967 The @option{--master} option provides the location of the
7968 @code{buildbot.status.client.PBListener} status port, used to deliver
7969 build information to realtime status clients. The option is always in
7970 the form of a string, with hostname and port number separated by a
7971 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
7972 same as the slaveport (although a future version may allow the same
7973 port number to be used for both purposes). If you get an error message
7974 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
7975 this may indicate that you are connecting to the slaveport rather than
7976 a @code{PBListener} port.
7978 The @option{--master} option can also be provided by the
7979 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
7980 config directory}).
7982 @node statusgui, try, statuslog, Developer Tools
7983 @subsection statusgui
7985 @cindex statusgui
7987 If you have set up a PBListener (@pxref{PBListener}), you will be able
7988 to monitor your Buildbot using a simple Gtk+ application invoked with
7989 the @code{buildbot statusgui} command:
7991 @example
7992 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
7993 @end example
7995 This command starts a simple Gtk+-based status client, which contains
7996 a few boxes for each Builder that change color as events occur. It
7997 uses the same @option{--master} argument as the @command{buildbot
7998 statuslog} command (@pxref{statuslog}).
8000 @node try,  , statusgui, Developer Tools
8001 @subsection try
8003 This lets a developer to ask the question ``What would happen if I
8004 committed this patch right now?''. It runs the unit test suite (across
8005 multiple build platforms) on the developer's current code, allowing
8006 them to make sure they will not break the tree when they finally
8007 commit their changes.
8009 The @command{buildbot try} command is meant to be run from within a
8010 developer's local tree, and starts by figuring out the base revision
8011 of that tree (what revision was current the last time the tree was
8012 updated), and a patch that can be applied to that revision of the tree
8013 to make it match the developer's copy. This (revision, patch) pair is
8014 then sent to the buildmaster, which runs a build with that
8015 SourceStamp. If you want, the tool will emit status messages as the
8016 builds run, and will not terminate until the first failure has been
8017 detected (or the last success).
8019 There is an alternate form which accepts a pre-made patch file
8020 (typically the output of a command like 'svn diff'). This ``--diff''
8021 form does not require a local tree to run from. See @xref{try --diff}.
8023 For this command to work, several pieces must be in place:
8026 @heading TryScheduler
8028 @slindex buildbot.scheduler.Try_Jobdir
8029 @slindex buildbot.scheduler.Try_Userpass
8031 The buildmaster must have a @code{scheduler.Try} instance in
8032 the config file's @code{c['schedulers']} list. This lets the
8033 administrator control who may initiate these ``trial'' builds, which
8034 branches are eligible for trial builds, and which Builders should be
8035 used for them.
8037 The @code{TryScheduler} has various means to accept build requests:
8038 all of them enforce more security than the usual buildmaster ports do.
8039 Any source code being built can be used to compromise the buildslave
8040 accounts, but in general that code must be checked out from the VC
8041 repository first, so only people with commit privileges can get
8042 control of the buildslaves. The usual force-build control channels can
8043 waste buildslave time but do not allow arbitrary commands to be
8044 executed by people who don't have those commit privileges. However,
8045 the source code patch that is provided with the trial build does not
8046 have to go through the VC system first, so it is important to make
8047 sure these builds cannot be abused by a non-committer to acquire as
8048 much control over the buildslaves as a committer has. Ideally, only
8049 developers who have commit access to the VC repository would be able
8050 to start trial builds, but unfortunately the buildmaster does not, in
8051 general, have access to VC system's user list.
8053 As a result, the @code{TryScheduler} requires a bit more
8054 configuration. There are currently two ways to set this up:
8056 @table @strong
8057 @item jobdir (ssh)
8059 This approach creates a command queue directory, called the
8060 ``jobdir'', in the buildmaster's working directory. The buildmaster
8061 admin sets the ownership and permissions of this directory to only
8062 grant write access to the desired set of developers, all of whom must
8063 have accounts on the machine. The @code{buildbot try} command creates
8064 a special file containing the source stamp information and drops it in
8065 the jobdir, just like a standard maildir. When the buildmaster notices
8066 the new file, it unpacks the information inside and starts the builds.
8068 The config file entries used by 'buildbot try' either specify a local
8069 queuedir (for which write and mv are used) or a remote one (using scp
8070 and ssh).
8072 The advantage of this scheme is that it is quite secure, the
8073 disadvantage is that it requires fiddling outside the buildmaster
8074 config (to set the permissions on the jobdir correctly). If the
8075 buildmaster machine happens to also house the VC repository, then it
8076 can be fairly easy to keep the VC userlist in sync with the
8077 trial-build userlist. If they are on different machines, this will be
8078 much more of a hassle. It may also involve granting developer accounts
8079 on a machine that would not otherwise require them.
8081 To implement this, the buildslave invokes 'ssh -l username host
8082 buildbot tryserver ARGS', passing the patch contents over stdin. The
8083 arguments must include the inlet directory and the revision
8084 information.
8086 @item user+password (PB)
8088 In this approach, each developer gets a username/password pair, which
8089 are all listed in the buildmaster's configuration file. When the
8090 developer runs @code{buildbot try}, their machine connects to the
8091 buildmaster via PB and authenticates themselves using that username
8092 and password, then sends a PB command to start the trial build.
8094 The advantage of this scheme is that the entire configuration is
8095 performed inside the buildmaster's config file. The disadvantages are
8096 that it is less secure (while the ``cred'' authentication system does
8097 not expose the password in plaintext over the wire, it does not offer
8098 most of the other security properties that SSH does). In addition, the
8099 buildmaster admin is responsible for maintaining the username/password
8100 list, adding and deleting entries as developers come and go.
8102 @end table
8105 For example, to set up the ``jobdir'' style of trial build, using a
8106 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
8107 all your project developers were members of the @code{developers} unix
8108 group), you would first create that directory (with @command{mkdir
8109 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
8110 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
8111 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
8112 MASTERDIR/jobdir/*}), and then use the following scheduler in the
8113 buildmaster's config file:
8115 @example
8116 from buildbot.scheduler import Try_Jobdir
8117 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
8118                jobdir="jobdir")
8119 c['schedulers'] = [s]
8120 @end example
8122 Note that you must create the jobdir before telling the buildmaster to
8123 use this configuration, otherwise you will get an error. Also remember
8124 that the buildmaster must be able to read and write to the jobdir as
8125 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
8126 as you start using the jobdir, to make sure the buildmaster is happy
8127 with it.
8129 To use the username/password form of authentication, create a
8130 @code{Try_Userpass} instance instead. It takes the same
8131 @code{builderNames} argument as the @code{Try_Jobdir} form, but
8132 accepts an addtional @code{port} argument (to specify the TCP port to
8133 listen on) and a @code{userpass} list of username/password pairs to
8134 accept. Remember to use good passwords for this: the security of the
8135 buildslave accounts depends upon it:
8137 @example
8138 from buildbot.scheduler import Try_Userpass
8139 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
8140                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
8141 c['schedulers'] = [s]
8142 @end example
8144 Like most places in the buildbot, the @code{port} argument takes a
8145 strports specification. See @code{twisted.application.strports} for
8146 details.
8149 @heading locating the master
8151 The @command{try} command needs to be told how to connect to the
8152 @code{TryScheduler}, and must know which of the authentication
8153 approaches described above is in use by the buildmaster. You specify
8154 the approach by using @option{--connect=ssh} or @option{--connect=pb}
8155 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
8156 @file{.buildbot/options}).
8158 For the PB approach, the command must be given a @option{--master}
8159 argument (in the form HOST:PORT) that points to TCP port that you
8160 picked in the @code{Try_Userpass} scheduler. It also takes a
8161 @option{--username} and @option{--passwd} pair of arguments that match
8162 one of the entries in the buildmaster's @code{userpass} list. These
8163 arguments can also be provided as @code{try_master},
8164 @code{try_username}, and @code{try_password} entries in the
8165 @file{.buildbot/options} file.
8167 For the SSH approach, the command must be given @option{--tryhost},
8168 @option{--username}, and optionally @option{--password} (TODO:
8169 really?) to get to the buildmaster host. It must also be given
8170 @option{--trydir}, which points to the inlet directory configured
8171 above. The trydir can be relative to the user's home directory, but
8172 most of the time you will use an explicit path like
8173 @file{~buildbot/project/trydir}. These arguments can be provided in
8174 @file{.buildbot/options} as @code{try_host}, @code{try_username},
8175 @code{try_password}, and @code{try_dir}.
8177 In addition, the SSH approach needs to connect to a PBListener status
8178 port, so it can retrieve and report the results of the build (the PB
8179 approach uses the existing connection to retrieve status information,
8180 so this step is not necessary). This requires a @option{--master}
8181 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
8182 in the form of a HOSTNAME:PORT string.
8185 @heading choosing the Builders
8187 A trial build is performed on multiple Builders at the same time, and
8188 the developer gets to choose which Builders are used (limited to a set
8189 selected by the buildmaster admin with the TryScheduler's
8190 @code{builderNames=} argument). The set you choose will depend upon
8191 what your goals are: if you are concerned about cross-platform
8192 compatibility, you should use multiple Builders, one from each
8193 platform of interest. You might use just one builder if that platform
8194 has libraries or other facilities that allow better test coverage than
8195 what you can accomplish on your own machine, or faster test runs.
8197 The set of Builders to use can be specified with multiple
8198 @option{--builder} arguments on the command line. It can also be
8199 specified with a single @code{try_builders} option in
8200 @file{.buildbot/options} that uses a list of strings to specify all
8201 the Builder names:
8203 @example
8204 try_builders = ["full-OSX", "full-win32", "full-linux"]
8205 @end example
8207 @heading specifying the VC system
8209 The @command{try} command also needs to know how to take the
8210 developer's current tree and extract the (revision, patch)
8211 source-stamp pair. Each VC system uses a different process, so you
8212 start by telling the @command{try} command which VC system you are
8213 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
8214 This can also be provided as @code{try_vc} in
8215 @file{.buildbot/options}.
8217 The following names are recognized: @code{cvs} @code{svn} @code{baz}
8218 @code{tla} @code{hg} @code{darcs}
8221 @heading finding the top of the tree
8223 Some VC systems (notably CVS and SVN) track each directory
8224 more-or-less independently, which means the @command{try} command
8225 needs to move up to the top of the project tree before it will be able
8226 to construct a proper full-tree patch. To accomplish this, the
8227 @command{try} command will crawl up through the parent directories
8228 until it finds a marker file. The default name for this marker file is
8229 @file{.buildbot-top}, so when you are using CVS or SVN you should
8230 @code{touch .buildbot-top} from the top of your tree before running
8231 @command{buildbot try}. Alternatively, you can use a filename like
8232 @file{ChangeLog} or @file{README}, since many projects put one of
8233 these files in their top-most directory (and nowhere else). To set
8234 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
8235 options file with @code{try_topfile = 'ChangeLog'}.
8237 You can also manually set the top of the tree with
8238 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
8239 '~/trees/mytree'}. If you use @code{try_topdir}, in a
8240 @file{.buildbot/options} file, you will need a separate options file
8241 for each tree you use, so it may be more convenient to use the
8242 @code{try_topfile} approach instead.
8244 Other VC systems which work on full projects instead of individual
8245 directories (tla, baz, darcs, monotone, mercurial, git) do not require
8246 @command{try} to know the top directory, so the @option{--try-topfile}
8247 and @option{--try-topdir} arguments will be ignored.
8248 @c is this true? I think I currently require topdirs all the time.
8250 If the @command{try} command cannot find the top directory, it will
8251 abort with an error message.
8253 @heading determining the branch name
8255 Some VC systems record the branch information in a way that ``try''
8256 can locate it, in particular Arch (both @command{tla} and
8257 @command{baz}). For the others, if you are using something other than
8258 the default branch, you will have to tell the buildbot which branch
8259 your tree is using. You can do this with either the @option{--branch}
8260 argument, or a @option{try_branch} entry in the
8261 @file{.buildbot/options} file.
8263 @heading determining the revision and patch
8265 Each VC system has a separate approach for determining the tree's base
8266 revision and computing a patch.
8268 @table @code
8270 @item CVS
8272 @command{try} pretends that the tree is up to date. It converts the
8273 current time into a @code{-D} time specification, uses it as the base
8274 revision, and computes the diff between the upstream tree as of that
8275 point in time versus the current contents. This works, more or less,
8276 but requires that the local clock be in reasonably good sync with the
8277 repository.
8279 @item SVN
8280 @command{try} does a @code{svn status -u} to find the latest
8281 repository revision number (emitted on the last line in the ``Status
8282 against revision: NN'' message). It then performs an @code{svn diff
8283 -rNN} to find out how your tree differs from the repository version,
8284 and sends the resulting patch to the buildmaster. If your tree is not
8285 up to date, this will result in the ``try'' tree being created with
8286 the latest revision, then @emph{backwards} patches applied to bring it
8287 ``back'' to the version you actually checked out (plus your actual
8288 code changes), but this will still result in the correct tree being
8289 used for the build.
8291 @item baz
8292 @command{try} does a @code{baz tree-id} to determine the
8293 fully-qualified version and patch identifier for the tree
8294 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
8295 as the base revision. It then does a @code{baz diff} to obtain the
8296 patch.
8298 @item tla
8299 @command{try} does a @code{tla tree-version} to get the
8300 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
8301 first line of @code{tla logs --reverse} to figure out the base
8302 revision. Then it does @code{tla changes --diffs} to obtain the patch.
8304 @item Darcs
8305 @code{darcs changes --context} emits a text file that contains a list
8306 of all patches back to and including the last tag was made. This text
8307 file (plus the location of a repository that contains all these
8308 patches) is sufficient to re-create the tree. Therefore the contents
8309 of this ``context'' file @emph{are} the revision stamp for a
8310 Darcs-controlled source tree.
8312 So @command{try} does a @code{darcs changes --context} to determine
8313 what your tree's base revision is, and then does a @code{darcs diff
8314 -u} to compute the patch relative to that revision.
8316 @item Mercurial
8317 @code{hg identify} emits a short revision ID (basically a truncated
8318 SHA1 hash of the current revision's contents), which is used as the
8319 base revision. @code{hg diff} then provides the patch relative to that
8320 revision. For @command{try} to work, your working directory must only
8321 have patches that are available from the same remotely-available
8322 repository that the build process' @code{step.Mercurial} will use.
8324 @item Git
8325 @code{git branch -v} lists all the branches available in the local
8326 repository along with the revision ID it points to and a short summary
8327 of the last commit. The line containing the currently checked out
8328 branch begins with '* ' (star and space) while all the others start
8329 with '  ' (two spaces). @command{try} scans for this line and extracts
8330 the branch name and revision from it. Then it generates a diff against
8331 the base revision.
8332 @c TODO: I'm not sure if this actually works the way it's intended
8333 @c since the extracted base revision might not actually exist in the
8334 @c upstream repository. Perhaps we need to add a --remote option to
8335 @c specify the remote tracking branch to generate a diff against.
8337 @c TODO: monotone
8338 @end table
8340 @heading waiting for results
8342 If you provide the @option{--wait} option (or @code{try_wait = True}
8343 in @file{.buildbot/options}), the @command{buildbot try} command will
8344 wait until your changes have either been proven good or bad before
8345 exiting. Unless you use the @option{--quiet} option (or
8346 @code{try_quiet=True}), it will emit a progress message every 60
8347 seconds until the builds have completed.
8349 @menu
8350 * try --diff::
8351 @end menu
8353 @node try --diff,  , try, try
8354 @subsubsection try --diff
8356 Sometimes you might have a patch from someone else that you want to
8357 submit to the buildbot. For example, a user may have created a patch
8358 to fix some specific bug and sent it to you by email. You've inspected
8359 the patch and suspect that it might do the job (and have at least
8360 confirmed that it doesn't do anything evil). Now you want to test it
8361 out.
8363 One approach would be to check out a new local tree, apply the patch,
8364 run your local tests, then use ``buildbot try'' to run the tests on
8365 other platforms. An alternate approach is to use the @command{buildbot
8366 try --diff} form to have the buildbot test the patch without using a
8367 local tree.
8369 This form takes a @option{--diff} argument which points to a file that
8370 contains the patch you want to apply. By default this patch will be
8371 applied to the TRUNK revision, but if you give the optional
8372 @option{--baserev} argument, a tree of the given revision will be used
8373 as a starting point instead of TRUNK.
8375 You can also use @command{buildbot try --diff=-} to read the patch
8376 from stdin.
8378 Each patch has a ``patchlevel'' associated with it. This indicates the
8379 number of slashes (and preceding pathnames) that should be stripped
8380 before applying the diff. This exactly corresponds to the @option{-p}
8381 or @option{--strip} argument to the @command{patch} utility. By
8382 default @command{buildbot try --diff} uses a patchlevel of 0, but you
8383 can override this with the @option{-p} argument.
8385 When you use @option{--diff}, you do not need to use any of the other
8386 options that relate to a local tree, specifically @option{--vc},
8387 @option{--try-topfile}, or @option{--try-topdir}. These options will
8388 be ignored. Of course you must still specify how to get to the
8389 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
8392 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
8393 @section Other Tools
8395 These tools are generally used by buildmaster administrators.
8397 @menu
8398 * sendchange::
8399 * debugclient::
8400 @end menu
8402 @node sendchange, debugclient, Other Tools, Other Tools
8403 @subsection sendchange
8405 This command is used to tell the buildmaster about source changes. It
8406 is intended to be used from within a commit script, installed on the
8407 VC server. It requires that you have a PBChangeSource
8408 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
8409 @code{c['change_source']}).
8412 @example
8413 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
8414 @end example
8416 There are other (optional) arguments which can influence the
8417 @code{Change} that gets submitted:
8419 @table @code
8420 @item --branch
8421 This provides the (string) branch specifier. If omitted, it defaults
8422 to None, indicating the ``default branch''. All files included in this
8423 Change must be on the same branch.
8425 @item --category
8426 This provides the (string) category specifier. If omitted, it defaults
8427 to None, indicating ``no category''. The category property is used
8428 by Schedulers to filter what changes they listen to.
8430 @item --revision_number
8431 This provides a (numeric) revision number for the change, used for VC systems
8432 that use numeric transaction numbers (like Subversion).
8434 @item --revision
8435 This provides a (string) revision specifier, for VC systems that use
8436 strings (Arch would use something like patch-42 etc).
8438 @item --revision_file
8439 This provides a filename which will be opened and the contents used as
8440 the revision specifier. This is specifically for Darcs, which uses the
8441 output of @command{darcs changes --context} as a revision specifier.
8442 This context file can be a couple of kilobytes long, spanning a couple
8443 lines per patch, and would be a hassle to pass as a command-line
8444 argument.
8446 @item --comments
8447 This provides the change comments as a single argument. You may want
8448 to use @option{--logfile} instead.
8450 @item --logfile
8451 This instructs the tool to read the change comments from the given
8452 file. If you use @code{-} as the filename, the tool will read the
8453 change comments from stdin.
8454 @end table
8457 @node debugclient,  , sendchange, Other Tools
8458 @subsection debugclient
8460 @example
8461 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
8462 @end example
8464 This launches a small Gtk+/Glade-based debug tool, connecting to the
8465 buildmaster's ``debug port''. This debug port shares the same port
8466 number as the slaveport (@pxref{Setting the slaveport}), but the
8467 @code{debugPort} is only enabled if you set a debug password in the
8468 buildmaster's config file (@pxref{Debug options}). The
8469 @option{--passwd} option must match the @code{c['debugPassword']}
8470 value.
8472 @option{--master} can also be provided in @file{.debug/options} by the
8473 @code{master} key. @option{--passwd} can be provided by the
8474 @code{debugPassword} key.
8476 The @code{Connect} button must be pressed before any of the other
8477 buttons will be active. This establishes the connection to the
8478 buildmaster. The other sections of the tool are as follows:
8480 @table @code
8481 @item Reload .cfg
8482 Forces the buildmaster to reload its @file{master.cfg} file. This is
8483 equivalent to sending a SIGHUP to the buildmaster, but can be done
8484 remotely through the debug port. Note that it is a good idea to be
8485 watching the buildmaster's @file{twistd.log} as you reload the config
8486 file, as any errors which are detected in the config file will be
8487 announced there.
8489 @item Rebuild .py
8490 (not yet implemented). The idea here is to use Twisted's ``rebuild''
8491 facilities to replace the buildmaster's running code with a new
8492 version. Even if this worked, it would only be used by buildbot
8493 developers.
8495 @item poke IRC
8496 This locates a @code{words.IRC} status target and causes it to emit a
8497 message on all the channels to which it is currently connected. This
8498 was used to debug a problem in which the buildmaster lost the
8499 connection to the IRC server and did not attempt to reconnect.
8501 @item Commit
8502 This allows you to inject a Change, just as if a real one had been
8503 delivered by whatever VC hook you are using. You can set the name of
8504 the committed file and the name of the user who is doing the commit.
8505 Optionally, you can also set a revision for the change. If the
8506 revision you provide looks like a number, it will be sent as an
8507 integer, otherwise it will be sent as a string.
8509 @item Force Build
8510 This lets you force a Builder (selected by name) to start a build of
8511 the current source tree.
8513 @item Currently
8514 (obsolete). This was used to manually set the status of the given
8515 Builder, but the status-assignment code was changed in an incompatible
8516 way and these buttons are no longer meaningful.
8518 @end table
8521 @node .buildbot config directory,  , Other Tools, Command-line tool
8522 @section .buildbot config directory
8524 Many of the @command{buildbot} tools must be told how to contact the
8525 buildmaster that they interact with. This specification can be
8526 provided as a command-line argument, but most of the time it will be
8527 easier to set them in an ``options'' file. The @command{buildbot}
8528 command will look for a special directory named @file{.buildbot},
8529 starting from the current directory (where the command was run) and
8530 crawling upwards, eventually looking in the user's home directory. It
8531 will look for a file named @file{options} in this directory, and will
8532 evaluate it as a python script, looking for certain names to be set.
8533 You can just put simple @code{name = 'value'} pairs in this file to
8534 set the options.
8536 For a description of the names used in this file, please see the
8537 documentation for the individual @command{buildbot} sub-commands. The
8538 following is a brief sample of what this file's contents could be.
8540 @example
8541 # for status-reading tools
8542 masterstatus = 'buildbot.example.org:12345'
8543 # for 'sendchange' or the debug port
8544 master = 'buildbot.example.org:18990'
8545 debugPassword = 'eiv7Po'
8546 @end example
8548 @table @code
8549 @item masterstatus
8550 Location of the @code{client.PBListener} status port, used by
8551 @command{statuslog} and @command{statusgui}.
8553 @item master
8554 Location of the @code{debugPort} (for @command{debugclient}). Also the
8555 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
8556 Usually shares the slaveport, but a future version may make it
8557 possible to have these listen on a separate port number.
8559 @item debugPassword
8560 Must match the value of @code{c['debugPassword']}, used to protect the
8561 debug port, for the @command{debugclient} command.
8563 @item username
8564 Provides a default username for the @command{sendchange} command.
8566 @end table
8569 The following options are used by the @code{buildbot try} command
8570 (@pxref{try}):
8572 @table @code
8573 @item try_connect
8574 This specifies how the ``try'' command should deliver its request to
8575 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
8576 @item try_builders
8577 Which builders should be used for the ``try'' build.
8578 @item try_vc
8579 This specifies the version control system being used.
8580 @item try_branch
8581 This indicates that the current tree is on a non-trunk branch.
8582 @item try_topdir
8583 @item try_topfile
8584 Use @code{try_topdir} to explicitly indicate the top of your working
8585 tree, or @code{try_topfile} to name a file that will only be found in
8586 that top-most directory.
8588 @item try_host
8589 @item try_username
8590 @item try_dir
8591 When try_connect is ``ssh'', the command will pay attention to
8592 @code{try_host}, @code{try_username}, and @code{try_dir}.
8594 @item try_username
8595 @item try_password
8596 @item try_master
8597 Instead, when @code{try_connect} is ``pb'', the command will pay
8598 attention to @code{try_username}, @code{try_password}, and
8599 @code{try_master}.
8601 @item try_wait
8602 @item masterstatus
8603 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
8604 command to wait for the requested build to complete.
8606 @end table
8610 @node Resources, Developer's Appendix, Command-line tool, Top
8611 @chapter Resources
8613 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
8615 For configuration questions and general discussion, please use the
8616 @code{buildbot-devel} mailing list. The subscription instructions and
8617 archives are available at
8618 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
8620 @node Developer's Appendix, Index of Useful Classes, Resources, Top
8621 @unnumbered Developer's Appendix
8623 This appendix contains random notes about the implementation of the
8624 Buildbot, and is likely to only be of use to people intending to
8625 extend the Buildbot's internals.
8627 The buildmaster consists of a tree of Service objects, which is shaped
8628 as follows:
8630 @example
8631 BuildMaster
8632  ChangeMaster  (in .change_svc)
8633   [IChangeSource instances]
8634  [IScheduler instances]  (in .schedulers)
8635  BotMaster  (in .botmaster)
8636   [IBuildSlave instances]
8637  [IStatusTarget instances]  (in .statusTargets)
8638 @end example
8640 The BotMaster has a collection of Builder objects as values of its
8641 @code{.builders} dictionary.
8644 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
8645 @unnumbered Index of Useful Classes
8647 This is a list of all user-visible classes. There are the ones that
8648 are useful in @file{master.cfg}, the buildmaster's configuration file.
8649 Classes that are not listed here are generally internal things that
8650 admins are unlikely to have much use for.
8653 @heading Change Sources
8654 @printindex cs
8656 @heading Schedulers and Locks
8657 @printindex sl
8659 @heading Build Factories
8660 @printindex bf
8662 @heading Build Steps
8663 @printindex bs
8665 @c undocumented steps
8666 @bsindex buildbot.steps.source.Git
8667 @bsindex buildbot.steps.maxq.MaxQ
8670 @heading Status Targets
8671 @printindex st
8673 @c TODO: undocumented targets
8675 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
8676 @unnumbered Index of master.cfg keys
8678 This is a list of all of the significant keys in master.cfg . Recall
8679 that master.cfg is effectively a small python program with exactly one
8680 responsibility: create a dictionary named @code{BuildmasterConfig}.
8681 The keys of this dictionary are listed here. The beginning of the
8682 master.cfg file typically starts with something like:
8684 @example
8685 BuildmasterConfig = c = @{@}
8686 @end example
8688 Therefore a config key of @code{change_source} will usually appear in
8689 master.cfg as @code{c['change_source']}.
8691 @printindex bc
8694 @node Index,  , Index of master.cfg keys, Top
8695 @unnumbered Index
8697 @printindex cp
8700 @bye