0.7.10 release changes
[buildbot.git] / docs / buildbot.texinfo
blob639103b80267d265dcb3be62e517659c16877632
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename buildbot.info
4 @settitle BuildBot Manual 0.7.10
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::
232 * PyLint::
234 Writing New BuildSteps
236 * BuildStep LogFiles::
237 * Reading Logfiles::
238 * Adding LogObservers::
239 * BuildStep URLs::
241 Build Factories
243 * BuildStep Objects::
244 * BuildFactory::
245 * Process-Specific build factories::
247 BuildStep Objects
249 * BuildFactory Attributes::
250 * Quick builds::
252 BuildFactory
254 * BuildFactory Attributes::
255 * Quick builds::
257 Process-Specific build factories
259 * GNUAutoconf::
260 * CPAN::
261 * Python distutils::
262 * Python/Twisted/trial projects::
264 Status Delivery
266 * WebStatus::
267 * MailNotifier::
268 * IRC Bot::
269 * PBListener::
270 * Writing New Status Plugins::
272 WebStatus
274 * WebStatus Configuration Parameters::
275 * Buildbot Web Resources::
276 * XMLRPC server::
277 * HTML Waterfall::
279 Command-line tool
281 * Administrator Tools::
282 * Developer Tools::
283 * Other Tools::
284 * .buildbot config directory::
286 Developer Tools
288 * statuslog::
289 * statusgui::
290 * try::
292 waiting for results
294 * try --diff::
296 Other Tools
298 * sendchange::
299 * debugclient::
301 @end detailmenu
302 @end menu
304 @node Introduction, Installation, Top, Top
305 @chapter Introduction
307 @cindex introduction
309 The BuildBot is a system to automate the compile/test cycle required by most
310 software projects to validate code changes. By automatically rebuilding and
311 testing the tree each time something has changed, build problems are
312 pinpointed quickly, before other developers are inconvenienced by the
313 failure. The guilty developer can be identified and harassed without human
314 intervention. By running the builds on a variety of platforms, developers
315 who do not have the facilities to test their changes everywhere before
316 checkin will at least know shortly afterwards whether they have broken the
317 build or not. Warning counts, lint checks, image size, compile time, and
318 other build parameters can be tracked over time, are more visible, and
319 are therefore easier to improve.
321 The overall goal is to reduce tree breakage and provide a platform to
322 run tests or code-quality checks that are too annoying or pedantic for
323 any human to waste their time with. Developers get immediate (and
324 potentially public) feedback about their changes, encouraging them to
325 be more careful about testing before checkin.
327 Features:
329 @itemize @bullet
330 @item
331 run builds on a variety of slave platforms
332 @item
333 arbitrary build process: handles projects using C, Python, whatever
334 @item
335 minimal host requirements: python and Twisted
336 @item
337 slaves can be behind a firewall if they can still do checkout
338 @item
339 status delivery through web page, email, IRC, other protocols
340 @item
341 track builds in progress, provide estimated completion time
342 @item
343 flexible configuration by subclassing generic build process classes
344 @item
345 debug tools to force a new build, submit fake Changes, query slave status
346 @item
347 released under the GPL
348 @end itemize
350 @menu
351 * History and Philosophy::
352 * System Architecture::
353 * Control Flow::
354 @end menu
357 @node History and Philosophy, System Architecture, Introduction, Introduction
358 @section History and Philosophy
360 @cindex Philosophy of operation
362 The Buildbot was inspired by a similar project built for a development
363 team writing a cross-platform embedded system. The various components
364 of the project were supposed to compile and run on several flavors of
365 unix (linux, solaris, BSD), but individual developers had their own
366 preferences and tended to stick to a single platform. From time to
367 time, incompatibilities would sneak in (some unix platforms want to
368 use @code{string.h}, some prefer @code{strings.h}), and then the tree
369 would compile for some developers but not others. The buildbot was
370 written to automate the human process of walking into the office,
371 updating a tree, compiling (and discovering the breakage), finding the
372 developer at fault, and complaining to them about the problem they had
373 introduced. With multiple platforms it was difficult for developers to
374 do the right thing (compile their potential change on all platforms);
375 the buildbot offered a way to help.
377 Another problem was when programmers would change the behavior of a
378 library without warning its users, or change internal aspects that
379 other code was (unfortunately) depending upon. Adding unit tests to
380 the codebase helps here: if an application's unit tests pass despite
381 changes in the libraries it uses, you can have more confidence that
382 the library changes haven't broken anything. Many developers
383 complained that the unit tests were inconvenient or took too long to
384 run: having the buildbot run them reduces the developer's workload to
385 a minimum.
387 In general, having more visibility into the project is always good,
388 and automation makes it easier for developers to do the right thing.
389 When everyone can see the status of the project, developers are
390 encouraged to keep the tree in good working order. Unit tests that
391 aren't run on a regular basis tend to suffer from bitrot just like
392 code does: exercising them on a regular basis helps to keep them
393 functioning and useful.
395 The current version of the Buildbot is additionally targeted at
396 distributed free-software projects, where resources and platforms are
397 only available when provided by interested volunteers. The buildslaves
398 are designed to require an absolute minimum of configuration, reducing
399 the effort a potential volunteer needs to expend to be able to
400 contribute a new test environment to the project. The goal is for
401 anyone who wishes that a given project would run on their favorite
402 platform should be able to offer that project a buildslave, running on
403 that platform, where they can verify that their portability code
404 works, and keeps working.
406 @node System Architecture, Control Flow, History and Philosophy, Introduction
407 @comment  node-name,  next,  previous,  up
408 @section System Architecture
410 The Buildbot consists of a single @code{buildmaster} and one or more
411 @code{buildslaves}, connected in a star topology. The buildmaster
412 makes all decisions about what, when, and how to build. It sends
413 commands to be run on the build slaves, which simply execute the
414 commands and return the results. (certain steps involve more local
415 decision making, where the overhead of sending a lot of commands back
416 and forth would be inappropriate, but in general the buildmaster is
417 responsible for everything).
419 The buildmaster is usually fed @code{Changes} by some sort of version
420 control system (@pxref{Change Sources}), which may cause builds to be
421 run. As the builds are performed, various status messages are
422 produced, which are then sent to any registered Status Targets
423 (@pxref{Status Delivery}).
425 @c @image{FILENAME, WIDTH, HEIGHT, ALTTEXT, EXTENSION}
426 @image{images/overview,,,Overview Diagram,}
428 The buildmaster is configured and maintained by the ``buildmaster
429 admin'', who is generally the project team member responsible for
430 build process issues. Each buildslave is maintained by a ``buildslave
431 admin'', who do not need to be quite as involved. Generally slaves are
432 run by anyone who has an interest in seeing the project work well on
433 their favorite platform.
435 @menu
436 * BuildSlave Connections::
437 * Buildmaster Architecture::
438 * Status Delivery Architecture::
439 @end menu
441 @node BuildSlave Connections, Buildmaster Architecture, System Architecture, System Architecture
442 @subsection BuildSlave Connections
444 The buildslaves are typically run on a variety of separate machines,
445 at least one per platform of interest. These machines connect to the
446 buildmaster over a TCP connection to a publically-visible port. As a
447 result, the buildslaves can live behind a NAT box or similar
448 firewalls, as long as they can get to buildmaster. The TCP connections
449 are initiated by the buildslave and accepted by the buildmaster, but
450 commands and results travel both ways within this connection. The
451 buildmaster is always in charge, so all commands travel exclusively
452 from the buildmaster to the buildslave.
454 To perform builds, the buildslaves must typically obtain source code
455 from a CVS/SVN/etc repository. Therefore they must also be able to
456 reach the repository. The buildmaster provides instructions for
457 performing builds, but does not provide the source code itself.
459 @image{images/slaves,,,BuildSlave Connections,}
461 @node Buildmaster Architecture, Status Delivery Architecture, BuildSlave Connections, System Architecture
462 @subsection Buildmaster Architecture
464 The Buildmaster consists of several pieces:
466 @image{images/master,,,BuildMaster Architecture,}
468 @itemize @bullet
470 @item
471 Change Sources, which create a Change object each time something is
472 modified in the VC repository. Most ChangeSources listen for messages
473 from a hook script of some sort. Some sources actively poll the
474 repository on a regular basis. All Changes are fed to the Schedulers.
476 @item
477 Schedulers, which decide when builds should be performed. They collect
478 Changes into BuildRequests, which are then queued for delivery to
479 Builders until a buildslave is available.
481 @item
482 Builders, which control exactly @emph{how} each build is performed
483 (with a series of BuildSteps, configured in a BuildFactory). Each
484 Build is run on a single buildslave.
486 @item
487 Status plugins, which deliver information about the build results
488 through protocols like HTTP, mail, and IRC.
490 @end itemize
492 @image{images/slavebuilder,,,SlaveBuilders,}
494 Each Builder is configured with a list of BuildSlaves that it will use
495 for its builds. These buildslaves are expected to behave identically:
496 the only reason to use multiple BuildSlaves for a single Builder is to
497 provide a measure of load-balancing.
499 Within a single BuildSlave, each Builder creates its own SlaveBuilder
500 instance. These SlaveBuilders operate independently from each other.
501 Each gets its own base directory to work in. It is quite common to
502 have many Builders sharing the same buildslave. For example, there
503 might be two buildslaves: one for i386, and a second for PowerPC.
504 There may then be a pair of Builders that do a full compile/test run,
505 one for each architecture, and a lone Builder that creates snapshot
506 source tarballs if the full builders complete successfully. The full
507 builders would each run on a single buildslave, whereas the tarball
508 creation step might run on either buildslave (since the platform
509 doesn't matter when creating source tarballs). In this case, the
510 mapping would look like:
512 @example
513 Builder(full-i386)  ->  BuildSlaves(slave-i386)
514 Builder(full-ppc)   ->  BuildSlaves(slave-ppc)
515 Builder(source-tarball) -> BuildSlaves(slave-i386, slave-ppc)
516 @end example
518 and each BuildSlave would have two SlaveBuilders inside it, one for a
519 full builder, and a second for the source-tarball builder.
521 Once a SlaveBuilder is available, the Builder pulls one or more
522 BuildRequests off its incoming queue. (It may pull more than one if it
523 determines that it can merge the requests together; for example, there
524 may be multiple requests to build the current HEAD revision). These
525 requests are merged into a single Build instance, which includes the
526 SourceStamp that describes what exact version of the source code
527 should be used for the build. The Build is then randomly assigned to a
528 free SlaveBuilder and the build begins.
530 The behaviour when BuildRequests are merged can be customized, @pxref{Merging
531 BuildRequests}.
533 @node Status Delivery Architecture,  , Buildmaster Architecture, System Architecture
534 @subsection Status Delivery Architecture
536 The buildmaster maintains a central Status object, to which various
537 status plugins are connected. Through this Status object, a full
538 hierarchy of build status objects can be obtained.
540 @image{images/status,,,Status Delivery,}
542 The configuration file controls which status plugins are active. Each
543 status plugin gets a reference to the top-level Status object. From
544 there they can request information on each Builder, Build, Step, and
545 LogFile. This query-on-demand interface is used by the html.Waterfall
546 plugin to create the main status page each time a web browser hits the
547 main URL.
549 The status plugins can also subscribe to hear about new Builds as they
550 occur: this is used by the MailNotifier to create new email messages
551 for each recently-completed Build.
553 The Status object records the status of old builds on disk in the
554 buildmaster's base directory. This allows it to return information
555 about historical builds.
557 There are also status objects that correspond to Schedulers and
558 BuildSlaves. These allow status plugins to report information about
559 upcoming builds, and the online/offline status of each buildslave.
562 @node Control Flow,  , System Architecture, Introduction
563 @comment  node-name,  next,  previous,  up
564 @section Control Flow
566 A day in the life of the buildbot:
568 @itemize @bullet
570 @item
571 A developer commits some source code changes to the repository. A hook
572 script or commit trigger of some sort sends information about this
573 change to the buildmaster through one of its configured Change
574 Sources. This notification might arrive via email, or over a network
575 connection (either initiated by the buildmaster as it ``subscribes''
576 to changes, or by the commit trigger as it pushes Changes towards the
577 buildmaster). The Change contains information about who made the
578 change, what files were modified, which revision contains the change,
579 and any checkin comments.
581 @item
582 The buildmaster distributes this change to all of its configured
583 Schedulers. Any ``important'' changes cause the ``tree-stable-timer''
584 to be started, and the Change is added to a list of those that will go
585 into a new Build. When the timer expires, a Build is started on each
586 of a set of configured Builders, all compiling/testing the same source
587 code. Unless configured otherwise, all Builds run in parallel on the
588 various buildslaves.
590 @item
591 The Build consists of a series of Steps. Each Step causes some number
592 of commands to be invoked on the remote buildslave associated with
593 that Builder. The first step is almost always to perform a checkout of
594 the appropriate revision from the same VC system that produced the
595 Change. The rest generally perform a compile and run unit tests. As
596 each Step runs, the buildslave reports back command output and return
597 status to the buildmaster.
599 @item
600 As the Build runs, status messages like ``Build Started'', ``Step
601 Started'', ``Build Finished'', etc, are published to a collection of
602 Status Targets. One of these targets is usually the HTML ``Waterfall''
603 display, which shows a chronological list of events, and summarizes
604 the results of the most recent build at the top of each column.
605 Developers can periodically check this page to see how their changes
606 have fared. If they see red, they know that they've made a mistake and
607 need to fix it. If they see green, they know that they've done their
608 duty and don't need to worry about their change breaking anything.
610 @item
611 If a MailNotifier status target is active, the completion of a build
612 will cause email to be sent to any developers whose Changes were
613 incorporated into this Build. The MailNotifier can be configured to
614 only send mail upon failing builds, or for builds which have just
615 transitioned from passing to failing. Other status targets can provide
616 similar real-time notification via different communication channels,
617 like IRC.
619 @end itemize
622 @node Installation, Concepts, Introduction, Top
623 @chapter Installation
625 @menu
626 * Requirements::
627 * Installing the code::
628 * Creating a buildmaster::
629 * Upgrading an Existing Buildmaster::
630 * Creating a buildslave::
631 * Launching the daemons::
632 * Logfiles::
633 * Shutdown::
634 * Maintenance::
635 * Troubleshooting::
636 @end menu
638 @node Requirements, Installing the code, Installation, Installation
639 @section Requirements
641 At a bare minimum, you'll need the following (for both the buildmaster
642 and a buildslave):
644 @itemize @bullet
645 @item
646 Python: http://www.python.org
648 Buildbot requires python-2.3 or later, and is primarily developed
649 against python-2.4. It is also tested against python-2.5 .
651 @item
652 Twisted: http://twistedmatrix.com
654 Both the buildmaster and the buildslaves require Twisted-2.0.x or
655 later. It has been tested against all releases of Twisted up to
656 Twisted-2.5.0 (the most recent as of this writing). As always, the
657 most recent version is recommended.
659 Twisted is delivered as a collection of subpackages. You'll need at
660 least "Twisted" (the core package), and you'll also want TwistedMail,
661 TwistedWeb, and TwistedWords (for sending email, serving a web status
662 page, and delivering build status via IRC, respectively). You might
663 also want TwistedConch (for the encrypted Manhole debug port). Note
664 that Twisted requires ZopeInterface to be installed as well.
666 @end itemize
668 Certain other packages may be useful on the system running the
669 buildmaster:
671 @itemize @bullet
672 @item
673 CVSToys: http://purl.net/net/CVSToys
675 If your buildmaster uses FreshCVSSource to receive change notification
676 from a cvstoys daemon, it will require CVSToys be installed (tested
677 with CVSToys-1.0.10). If the it doesn't use that source (i.e. if you
678 only use a mail-parsing change source, or the SVN notification
679 script), you will not need CVSToys.
681 @end itemize
683 And of course, your project's build process will impose additional
684 requirements on the buildslaves. These hosts must have all the tools
685 necessary to compile and test your project's source code.
688 @node Installing the code, Creating a buildmaster, Requirements, Installation
689 @section Installing the code
691 @cindex installation
693 The Buildbot is installed using the standard python @code{distutils}
694 module. After unpacking the tarball, the process is:
696 @example
697 python setup.py build
698 python setup.py install
699 @end example
701 where the install step may need to be done as root. This will put the
702 bulk of the code in somewhere like
703 /usr/lib/python2.3/site-packages/buildbot . It will also install the
704 @code{buildbot} command-line tool in /usr/bin/buildbot.
706 To test this, shift to a different directory (like /tmp), and run:
708 @example
709 buildbot --version
710 @end example
712 If it shows you the versions of Buildbot and Twisted, the install went
713 ok. If it says @code{no such command} or it gets an @code{ImportError}
714 when it tries to load the libaries, then something went wrong.
715 @code{pydoc buildbot} is another useful diagnostic tool.
717 Windows users will find these files in other places. You will need to
718 make sure that python can find the libraries, and will probably find
719 it convenient to have @code{buildbot} on your PATH.
721 If you wish, you can run the buildbot unit test suite like this:
723 @example
724 PYTHONPATH=. trial buildbot.test
725 @end example
727 This should run up to 192 tests, depending upon what VC tools you have
728 installed. On my desktop machine it takes about five minutes to
729 complete. Nothing should fail, a few might be skipped. If any of the
730 tests fail, you should stop and investigate the cause before
731 continuing the installation process, as it will probably be easier to
732 track down the bug early.
734 If you cannot or do not wish to install the buildbot into a site-wide
735 location like @file{/usr} or @file{/usr/local}, you can also install
736 it into the account's home directory. Do the install command like
737 this:
739 @example
740 python setup.py install --home=~
741 @end example
743 That will populate @file{~/lib/python} and create
744 @file{~/bin/buildbot}. Make sure this lib directory is on your
745 @code{PYTHONPATH}.
748 @node Creating a buildmaster, Upgrading an Existing Buildmaster, Installing the code, Installation
749 @section Creating a buildmaster
751 As you learned earlier (@pxref{System Architecture}), the buildmaster
752 runs on a central host (usually one that is publically visible, so
753 everybody can check on the status of the project), and controls all
754 aspects of the buildbot system. Let us call this host
755 @code{buildbot.example.org}.
757 You may wish to create a separate user account for the buildmaster,
758 perhaps named @code{buildmaster}. This can help keep your personal
759 configuration distinct from that of the buildmaster and is useful if
760 you have to use a mail-based notification system (@pxref{Change
761 Sources}). However, the Buildbot will work just fine with your regular
762 user account.
764 You need to choose a directory for the buildmaster, called the
765 @code{basedir}. This directory will be owned by the buildmaster, which
766 will use configuration files therein, and create status files as it
767 runs. @file{~/Buildbot} is a likely value. If you run multiple
768 buildmasters in the same account, or if you run both masters and
769 slaves, you may want a more distinctive name like
770 @file{~/Buildbot/master/gnomovision} or
771 @file{~/Buildmasters/fooproject}. If you are using a separate user
772 account, this might just be @file{~buildmaster/masters/fooproject}.
774 Once you've picked a directory, use the @command{buildbot
775 create-master} command to create the directory and populate it with
776 startup files:
778 @example
779 buildbot create-master @var{basedir}
780 @end example
782 You will need to create a configuration file (@pxref{Configuration})
783 before starting the buildmaster. Most of the rest of this manual is
784 dedicated to explaining how to do this. A sample configuration file is
785 placed in the working directory, named @file{master.cfg.sample}, which
786 can be copied to @file{master.cfg} and edited to suit your purposes.
788 (Internal details: This command creates a file named
789 @file{buildbot.tac} that contains all the state necessary to create
790 the buildmaster. Twisted has a tool called @code{twistd} which can use
791 this .tac file to create and launch a buildmaster instance. twistd
792 takes care of logging and daemonization (running the program in the
793 background). @file{/usr/bin/buildbot} is a front end which runs twistd
794 for you.)
796 In addition to @file{buildbot.tac}, a small @file{Makefile.sample} is
797 installed. This can be used as the basis for customized daemon startup,
798 @xref{Launching the daemons}.
800 @node Upgrading an Existing Buildmaster, Creating a buildslave, Creating a buildmaster, Installation
801 @section Upgrading an Existing Buildmaster
803 If you have just installed a new version of the Buildbot code, and you
804 have buildmasters that were created using an older version, you'll
805 need to upgrade these buildmasters before you can use them. The
806 upgrade process adds and modifies files in the buildmaster's base
807 directory to make it compatible with the new code.
809 @example
810 buildbot upgrade-master @var{basedir}
811 @end example
813 This command will also scan your @file{master.cfg} file for
814 incompatbilities (by loading it and printing any errors or deprecation
815 warnings that occur). Each buildbot release tries to be compatible
816 with configurations that worked cleanly (i.e. without deprecation
817 warnings) on the previous release: any functions or classes that are
818 to be removed will first be deprecated in a release, to give users a
819 chance to start using their replacement.
821 The 0.7.6 release introduced the @file{public_html/} directory, which
822 contains @file{index.html} and other files served by the
823 @code{WebStatus} and @code{Waterfall} status displays. The
824 @code{upgrade-master} command will create these files if they do not
825 already exist. It will not modify existing copies, but it will write a
826 new copy in e.g. @file{index.html.new} if the new version differs from
827 the version that already exists.
829 The @code{upgrade-master} command is idempotent. It is safe to run it
830 multiple times. After each upgrade of the buildbot code, you should
831 use @code{upgrade-master} on all your buildmasters.
834 @node Creating a buildslave, Launching the daemons, Upgrading an Existing Buildmaster, Installation
835 @section Creating a buildslave
837 Typically, you will be adding a buildslave to an existing buildmaster,
838 to provide additional architecture coverage. The buildbot
839 administrator will give you several pieces of information necessary to
840 connect to the buildmaster. You should also be somewhat familiar with
841 the project being tested, so you can troubleshoot build problems
842 locally.
844 The buildbot exists to make sure that the project's stated ``how to
845 build it'' process actually works. To this end, the buildslave should
846 run in an environment just like that of your regular developers.
847 Typically the project build process is documented somewhere
848 (@file{README}, @file{INSTALL}, etc), in a document that should
849 mention all library dependencies and contain a basic set of build
850 instructions. This document will be useful as you configure the host
851 and account in which the buildslave runs.
853 Here's a good checklist for setting up a buildslave:
855 @enumerate
856 @item
857 Set up the account
859 It is recommended (although not mandatory) to set up a separate user
860 account for the buildslave. This account is frequently named
861 @code{buildbot} or @code{buildslave}. This serves to isolate your
862 personal working environment from that of the slave's, and helps to
863 minimize the security threat posed by letting possibly-unknown
864 contributors run arbitrary code on your system. The account should
865 have a minimum of fancy init scripts.
867 @item
868 Install the buildbot code
870 Follow the instructions given earlier (@pxref{Installing the code}).
871 If you use a separate buildslave account, and you didn't install the
872 buildbot code to a shared location, then you will need to install it
873 with @code{--home=~} for each account that needs it.
875 @item
876 Set up the host
878 Make sure the host can actually reach the buildmaster. Usually the
879 buildmaster is running a status webserver on the same machine, so
880 simply point your web browser at it and see if you can get there.
881 Install whatever additional packages or libraries the project's
882 INSTALL document advises. (or not: if your buildslave is supposed to
883 make sure that building without optional libraries still works, then
884 don't install those libraries).
886 Again, these libraries don't necessarily have to be installed to a
887 site-wide shared location, but they must be available to your build
888 process. Accomplishing this is usually very specific to the build
889 process, so installing them to @file{/usr} or @file{/usr/local} is
890 usually the best approach.
892 @item
893 Test the build process
895 Follow the instructions in the INSTALL document, in the buildslave's
896 account. Perform a full CVS (or whatever) checkout, configure, make,
897 run tests, etc. Confirm that the build works without manual fussing.
898 If it doesn't work when you do it by hand, it will be unlikely to work
899 when the buildbot attempts to do it in an automated fashion.
901 @item
902 Choose a base directory
904 This should be somewhere in the buildslave's account, typically named
905 after the project which is being tested. The buildslave will not touch
906 any file outside of this directory. Something like @file{~/Buildbot}
907 or @file{~/Buildslaves/fooproject} is appropriate.
909 @item
910 Get the buildmaster host/port, botname, and password
912 When the buildbot admin configures the buildmaster to accept and use
913 your buildslave, they will provide you with the following pieces of
914 information:
916 @itemize @bullet
917 @item
918 your buildslave's name
919 @item
920 the password assigned to your buildslave
921 @item
922 the hostname and port number of the buildmaster, i.e. buildbot.example.org:8007
923 @end itemize
925 @item
926 Create the buildslave
928 Now run the 'buildbot' command as follows:
930 @example
931 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
932 @end example
934 This will create the base directory and a collection of files inside,
935 including the @file{buildbot.tac} file that contains all the
936 information you passed to the @code{buildbot} command.
938 @item
939 Fill in the hostinfo files
941 When it first connects, the buildslave will send a few files up to the
942 buildmaster which describe the host that it is running on. These files
943 are presented on the web status display so that developers have more
944 information to reproduce any test failures that are witnessed by the
945 buildbot. There are sample files in the @file{info} subdirectory of
946 the buildbot's base directory. You should edit these to correctly
947 describe you and your host.
949 @file{BASEDIR/info/admin} should contain your name and email address.
950 This is the ``buildslave admin address'', and will be visible from the
951 build status page (so you may wish to munge it a bit if
952 address-harvesting spambots are a concern).
954 @file{BASEDIR/info/host} should be filled with a brief description of
955 the host: OS, version, memory size, CPU speed, versions of relevant
956 libraries installed, and finally the version of the buildbot code
957 which is running the buildslave.
959 If you run many buildslaves, you may want to create a single
960 @file{~buildslave/info} file and share it among all the buildslaves
961 with symlinks.
963 @end enumerate
965 @menu
966 * Buildslave Options::
967 @end menu
969 @node Buildslave Options,  , Creating a buildslave, Creating a buildslave
970 @subsection Buildslave Options
972 There are a handful of options you might want to use when creating the
973 buildslave with the @command{buildbot create-slave <options> DIR <params>}
974 command. You can type @command{buildbot create-slave --help} for a summary.
975 To use these, just include them on the @command{buildbot create-slave}
976 command line, like this:
978 @example
979 buildbot create-slave --umask=022 ~/buildslave buildmaster.example.org:42012 myslavename mypasswd
980 @end example
982 @table @code
983 @item --usepty
984 This is a boolean flag that tells the buildslave whether to launch child
985 processes in a PTY or with regular pipes (the default) when the master does not
986 specify.  This option is deprecated, as this particular parameter is better
987 specified on the master.
989 @item --umask
990 This is a string (generally an octal representation of an integer)
991 which will cause the buildslave process' ``umask'' value to be set
992 shortly after initialization. The ``twistd'' daemonization utility
993 forces the umask to 077 at startup (which means that all files created
994 by the buildslave or its child processes will be unreadable by any
995 user other than the buildslave account). If you want build products to
996 be readable by other accounts, you can add @code{--umask=022} to tell
997 the buildslave to fix the umask after twistd clobbers it. If you want
998 build products to be @emph{writable} by other accounts too, use
999 @code{--umask=000}, but this is likely to be a security problem.
1001 @item --keepalive
1002 This is a number that indicates how frequently ``keepalive'' messages
1003 should be sent from the buildslave to the buildmaster, expressed in
1004 seconds. The default (600) causes a message to be sent to the
1005 buildmaster at least once every 10 minutes. To set this to a lower
1006 value, use e.g. @code{--keepalive=120}.
1008 If the buildslave is behind a NAT box or stateful firewall, these
1009 messages may help to keep the connection alive: some NAT boxes tend to
1010 forget about a connection if it has not been used in a while. When
1011 this happens, the buildmaster will think that the buildslave has
1012 disappeared, and builds will time out. Meanwhile the buildslave will
1013 not realize than anything is wrong.
1015 @item --maxdelay
1016 This is a number that indicates the maximum amount of time the
1017 buildslave will wait between connection attempts, expressed in
1018 seconds. The default (300) causes the buildslave to wait at most 5
1019 minutes before trying to connect to the buildmaster again.
1021 @item --log-size
1022 This is the size in bytes when to rotate the Twisted log files.
1024 @item --log-count
1025 This is the number of log rotations to keep around. You can either
1026 specify a number or @code{None} (the default) to keep all
1027 @file{twistd.log} files around.
1029 @end table
1032 @node Launching the daemons, Logfiles, Creating a buildslave, Installation
1033 @section Launching the daemons
1035 Both the buildmaster and the buildslave run as daemon programs. To
1036 launch them, pass the working directory to the @code{buildbot}
1037 command:
1039 @example
1040 buildbot start @var{BASEDIR}
1041 @end example
1043 This command will start the daemon and then return, so normally it
1044 will not produce any output. To verify that the programs are indeed
1045 running, look for a pair of files named @file{twistd.log} and
1046 @file{twistd.pid} that should be created in the working directory.
1047 @file{twistd.pid} contains the process ID of the newly-spawned daemon.
1049 When the buildslave connects to the buildmaster, new directories will
1050 start appearing in its base directory. The buildmaster tells the slave
1051 to create a directory for each Builder which will be using that slave.
1052 All build operations are performed within these directories: CVS
1053 checkouts, compiles, and tests.
1055 Once you get everything running, you will want to arrange for the
1056 buildbot daemons to be started at boot time. One way is to use
1057 @code{cron}, by putting them in a @@reboot crontab entry@footnote{this
1058 @@reboot syntax is understood by Vixie cron, which is the flavor
1059 usually provided with linux systems. Other unices may have a cron that
1060 doesn't understand @@reboot}:
1062 @example
1063 @@reboot buildbot start @var{BASEDIR}
1064 @end example
1066 When you run @command{crontab} to set this up, remember to do it as
1067 the buildmaster or buildslave account! If you add this to your crontab
1068 when running as your regular account (or worse yet, root), then the
1069 daemon will run as the wrong user, quite possibly as one with more
1070 authority than you intended to provide.
1072 It is important to remember that the environment provided to cron jobs
1073 and init scripts can be quite different that your normal runtime.
1074 There may be fewer environment variables specified, and the PATH may
1075 be shorter than usual. It is a good idea to test out this method of
1076 launching the buildslave by using a cron job with a time in the near
1077 future, with the same command, and then check @file{twistd.log} to
1078 make sure the slave actually started correctly. Common problems here
1079 are for @file{/usr/local} or @file{~/bin} to not be on your
1080 @code{PATH}, or for @code{PYTHONPATH} to not be set correctly.
1081 Sometimes @code{HOME} is messed up too.
1083 To modify the way the daemons are started (perhaps you want to set
1084 some environment variables first, or perform some cleanup each time),
1085 you can create a file named @file{Makefile.buildbot} in the base
1086 directory. When the @file{buildbot} front-end tool is told to
1087 @command{start} the daemon, and it sees this file (and
1088 @file{/usr/bin/make} exists), it will do @command{make -f
1089 Makefile.buildbot start} instead of its usual action (which involves
1090 running @command{twistd}). When the buildmaster or buildslave is
1091 installed, a @file{Makefile.sample} is created which implements the
1092 same behavior as the the @file{buildbot} tool uses, so if you want to
1093 customize the process, just copy @file{Makefile.sample} to
1094 @file{Makefile.buildbot} and edit it as necessary.
1096 Some distributions may include conveniences to make starting buildbot
1097 at boot time easy.  For instance, with the default buildbot package in
1098 Debian-based distributions, you may only need to modify
1099 @code{/etc/default/buildbot} (see also @code{/etc/init.d/buildbot}, which
1100 reads the configuration in @code{/etc/default/buildbot}).
1102 @node Logfiles, Shutdown, Launching the daemons, Installation
1103 @section Logfiles
1105 @cindex logfiles
1107 While a buildbot daemon runs, it emits text to a logfile, named
1108 @file{twistd.log}. A command like @code{tail -f twistd.log} is useful
1109 to watch the command output as it runs.
1111 The buildmaster will announce any errors with its configuration file
1112 in the logfile, so it is a good idea to look at the log at startup
1113 time to check for any problems. Most buildmaster activities will cause
1114 lines to be added to the log.
1116 @node Shutdown, Maintenance, Logfiles, Installation
1117 @section Shutdown
1119 To stop a buildmaster or buildslave manually, use:
1121 @example
1122 buildbot stop @var{BASEDIR}
1123 @end example
1125 This simply looks for the @file{twistd.pid} file and kills whatever
1126 process is identified within.
1128 At system shutdown, all processes are sent a @code{SIGKILL}. The
1129 buildmaster and buildslave will respond to this by shutting down
1130 normally.
1132 The buildmaster will respond to a @code{SIGHUP} by re-reading its
1133 config file. Of course, this only works on unix-like systems with
1134 signal support, and won't work on Windows. The following shortcut is
1135 available:
1137 @example
1138 buildbot reconfig @var{BASEDIR}
1139 @end example
1141 When you update the Buildbot code to a new release, you will need to
1142 restart the buildmaster and/or buildslave before it can take advantage
1143 of the new code. You can do a @code{buildbot stop @var{BASEDIR}} and
1144 @code{buildbot start @var{BASEDIR}} in quick succession, or you can
1145 use the @code{restart} shortcut, which does both steps for you:
1147 @example
1148 buildbot restart @var{BASEDIR}
1149 @end example
1151 There are certain configuration changes that are not handled cleanly
1152 by @code{buildbot reconfig}. If this occurs, @code{buildbot restart}
1153 is a more robust tool to fully switch over to the new configuration.
1155 @code{buildbot restart} may also be used to start a stopped Buildbot
1156 instance. This behaviour is useful when writing scripts that stop, start
1157 and restart Buildbot.
1159 A buildslave may also be gracefully shutdown from the
1160 @pxref{WebStatus} status plugin. This is useful to shutdown a
1161 buildslave without interrupting any current builds. The buildmaster
1162 will wait until the buildslave is finished all its current builds, and
1163 will then tell the buildslave to shutdown.
1165 @node Maintenance, Troubleshooting, Shutdown, Installation
1166 @section Maintenance
1168 It is a good idea to check the buildmaster's status page every once in
1169 a while, to see if your buildslave is still online. Eventually the
1170 buildbot will probably be enhanced to send you email (via the
1171 @file{info/admin} email address) when the slave has been offline for
1172 more than a few hours.
1174 If you find you can no longer provide a buildslave to the project, please
1175 let the project admins know, so they can put out a call for a
1176 replacement.
1178 The Buildbot records status and logs output continually, each time a
1179 build is performed. The status tends to be small, but the build logs
1180 can become quite large. Each build and log are recorded in a separate
1181 file, arranged hierarchically under the buildmaster's base directory.
1182 To prevent these files from growing without bound, you should
1183 periodically delete old build logs. A simple cron job to delete
1184 anything older than, say, two weeks should do the job. The only trick
1185 is to leave the @file{buildbot.tac} and other support files alone, for
1186 which find's @code{-mindepth} argument helps skip everything in the
1187 top directory. You can use something like the following:
1189 @example
1190 @@weekly cd BASEDIR && find . -mindepth 2 i-path './public_html/*' -prune -o -type f -mtime +14 -exec rm @{@} \;
1191 @@weekly cd BASEDIR && find twistd.log* -mtime +14 -exec rm @{@} \;
1192 @end example
1194 @node Troubleshooting,  , Maintenance, Installation
1195 @section Troubleshooting
1197 Here are a few hints on diagnosing common problems.
1199 @menu
1200 * Starting the buildslave::
1201 * Connecting to the buildmaster::
1202 * Forcing Builds::
1203 @end menu
1205 @node Starting the buildslave, Connecting to the buildmaster, Troubleshooting, Troubleshooting
1206 @subsection Starting the buildslave
1208 Cron jobs are typically run with a minimal shell (@file{/bin/sh}, not
1209 @file{/bin/bash}), and tilde expansion is not always performed in such
1210 commands. You may want to use explicit paths, because the @code{PATH}
1211 is usually quite short and doesn't include anything set by your
1212 shell's startup scripts (@file{.profile}, @file{.bashrc}, etc). If
1213 you've installed buildbot (or other python libraries) to an unusual
1214 location, you may need to add a @code{PYTHONPATH} specification (note
1215 that python will do tilde-expansion on @code{PYTHONPATH} elements by
1216 itself). Sometimes it is safer to fully-specify everything:
1218 @example
1219 @@reboot PYTHONPATH=~/lib/python /usr/local/bin/buildbot start /usr/home/buildbot/basedir
1220 @end example
1222 Take the time to get the @@reboot job set up. Otherwise, things will work
1223 fine for a while, but the first power outage or system reboot you have will
1224 stop the buildslave with nothing but the cries of sorrowful developers to
1225 remind you that it has gone away.
1227 @node Connecting to the buildmaster, Forcing Builds, Starting the buildslave, Troubleshooting
1228 @subsection Connecting to the buildmaster
1230 If the buildslave cannot connect to the buildmaster, the reason should
1231 be described in the @file{twistd.log} logfile. Some common problems
1232 are an incorrect master hostname or port number, or a mistyped bot
1233 name or password. If the buildslave loses the connection to the
1234 master, it is supposed to attempt to reconnect with an
1235 exponentially-increasing backoff. Each attempt (and the time of the
1236 next attempt) will be logged. If you get impatient, just manually stop
1237 and re-start the buildslave.
1239 When the buildmaster is restarted, all slaves will be disconnected,
1240 and will attempt to reconnect as usual. The reconnect time will depend
1241 upon how long the buildmaster is offline (i.e. how far up the
1242 exponential backoff curve the slaves have travelled). Again,
1243 @code{buildbot stop @var{BASEDIR}; buildbot start @var{BASEDIR}} will
1244 speed up the process.
1246 @node Forcing Builds,  , Connecting to the buildmaster, Troubleshooting
1247 @subsection Forcing Builds
1249 From the buildmaster's main status web page, you can force a build to
1250 be run on your build slave. Figure out which column is for a builder
1251 that runs on your slave, click on that builder's name, and the page
1252 that comes up will have a ``Force Build'' button. Fill in the form,
1253 hit the button, and a moment later you should see your slave's
1254 @file{twistd.log} filling with commands being run. Using @code{pstree}
1255 or @code{top} should also reveal the cvs/make/gcc/etc processes being
1256 run by the buildslave. Note that the same web page should also show
1257 the @file{admin} and @file{host} information files that you configured
1258 earlier.
1260 @node Concepts, Configuration, Installation, Top
1261 @chapter Concepts
1263 This chapter defines some of the basic concepts that the Buildbot
1264 uses. You'll need to understand how the Buildbot sees the world to
1265 configure it properly.
1267 @menu
1268 * Version Control Systems::
1269 * Schedulers::
1270 * BuildSet::
1271 * BuildRequest::
1272 * Builder::
1273 * Users::
1274 * Build Properties::
1275 @end menu
1277 @node Version Control Systems, Schedulers, Concepts, Concepts
1278 @section Version Control Systems
1280 @cindex Version Control
1282 These source trees come from a Version Control System of some kind.
1283 CVS and Subversion are two popular ones, but the Buildbot supports
1284 others. All VC systems have some notion of an upstream
1285 @code{repository} which acts as a server@footnote{except Darcs, but
1286 since the Buildbot never modifies its local source tree we can ignore
1287 the fact that Darcs uses a less centralized model}, from which clients
1288 can obtain source trees according to various parameters. The VC
1289 repository provides source trees of various projects, for different
1290 branches, and from various points in time. The first thing we have to
1291 do is to specify which source tree we want to get.
1293 @menu
1294 * Generalizing VC Systems::
1295 * Source Tree Specifications::
1296 * How Different VC Systems Specify Sources::
1297 * Attributes of Changes::
1298 @end menu
1300 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1301 @subsection Generalizing VC Systems
1303 For the purposes of the Buildbot, we will try to generalize all VC
1304 systems as having repositories that each provide sources for a variety
1305 of projects. Each project is defined as a directory tree with source
1306 files. The individual files may each have revisions, but we ignore
1307 that and treat the project as a whole as having a set of revisions
1308 (CVS is really the only VC system still in widespread use that has
1309 per-file revisions.. everything modern has moved to atomic tree-wide
1310 changesets). Each time someone commits a change to the project, a new
1311 revision becomes available. These revisions can be described by a
1312 tuple with two items: the first is a branch tag, and the second is
1313 some kind of revision stamp or timestamp. Complex projects may have
1314 multiple branch tags, but there is always a default branch. The
1315 timestamp may be an actual timestamp (such as the -D option to CVS),
1316 or it may be a monotonically-increasing transaction number (such as
1317 the change number used by SVN and P4, or the revision number used by
1318 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1319 systems provide more complexity than this: in particular the local
1320 views that P4 and ClearCase can assemble out of various source
1321 directories are more complex than we're prepared to take advantage of
1322 here}. The SHA1 revision ID used by Monotone, Mercurial, and Git is
1323 also a kind of revision stamp, in that it specifies a unique copy of
1324 the source tree, as does a Darcs ``context'' file.
1326 When we aren't intending to make any changes to the sources we check out
1327 (at least not any that need to be committed back upstream), there are two
1328 basic ways to use a VC system:
1330 @itemize @bullet
1331 @item
1332 Retrieve a specific set of source revisions: some tag or key is used
1333 to index this set, which is fixed and cannot be changed by subsequent
1334 developers committing new changes to the tree. Releases are built from
1335 tagged revisions like this, so that they can be rebuilt again later
1336 (probably with controlled modifications).
1337 @item
1338 Retrieve the latest sources along a specific branch: some tag is used
1339 to indicate which branch is to be used, but within that constraint we want
1340 to get the latest revisions.
1341 @end itemize
1343 Build personnel or CM staff typically use the first approach: the
1344 build that results is (ideally) completely specified by the two
1345 parameters given to the VC system: repository and revision tag. This
1346 gives QA and end-users something concrete to point at when reporting
1347 bugs. Release engineers are also reportedly fond of shipping code that
1348 can be traced back to a concise revision tag of some sort.
1350 Developers are more likely to use the second approach: each morning
1351 the developer does an update to pull in the changes committed by the
1352 team over the last day. These builds are not easy to fully specify: it
1353 depends upon exactly when you did a checkout, and upon what local
1354 changes the developer has in their tree. Developers do not normally
1355 tag each build they produce, because there is usually significant
1356 overhead involved in creating these tags. Recreating the trees used by
1357 one of these builds can be a challenge. Some VC systems may provide
1358 implicit tags (like a revision number), while others may allow the use
1359 of timestamps to mean ``the state of the tree at time X'' as opposed
1360 to a tree-state that has been explicitly marked.
1362 The Buildbot is designed to help developers, so it usually works in
1363 terms of @emph{the latest} sources as opposed to specific tagged
1364 revisions. However, it would really prefer to build from reproducible
1365 source trees, so implicit revisions are used whenever possible.
1367 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1368 @subsection Source Tree Specifications
1370 So for the Buildbot's purposes we treat each VC system as a server
1371 which can take a list of specifications as input and produce a source
1372 tree as output. Some of these specifications are static: they are
1373 attributes of the builder and do not change over time. Others are more
1374 variable: each build will have a different value. The repository is
1375 changed over time by a sequence of Changes, each of which represents a
1376 single developer making changes to some set of files. These Changes
1377 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1378 violates this assumption of cumulative Changes, but in most situations
1379 the changes don't occur frequently enough for this to be a significant
1380 problem}.
1382 For normal builds, the Buildbot wants to get well-defined source trees
1383 that contain specific Changes, and exclude other Changes that may have
1384 occurred after the desired ones. We assume that the Changes arrive at
1385 the buildbot (through one of the mechanisms described in @pxref{Change
1386 Sources}) in the same order in which they are committed to the
1387 repository. The Buildbot waits for the tree to become ``stable''
1388 before initiating a build, for two reasons. The first is that
1389 developers frequently make multiple related commits in quick
1390 succession, even when the VC system provides ways to make atomic
1391 transactions involving multiple files at the same time. Running a
1392 build in the middle of these sets of changes would use an inconsistent
1393 set of source files, and is likely to fail (and is certain to be less
1394 useful than a build which uses the full set of changes). The
1395 tree-stable-timer is intended to avoid these useless builds that
1396 include some of the developer's changes but not all. The second reason
1397 is that some VC systems (i.e. CVS) do not provide repository-wide
1398 transaction numbers, so that timestamps are the only way to refer to
1399 a specific repository state. These timestamps may be somewhat
1400 ambiguous, due to processing and notification delays. By waiting until
1401 the tree has been stable for, say, 10 minutes, we can choose a
1402 timestamp from the middle of that period to use for our source
1403 checkout, and then be reasonably sure that any clock-skew errors will
1404 not cause the build to be performed on an inconsistent set of source
1405 files.
1407 The Schedulers always use the tree-stable-timer, with a timeout that
1408 is configured to reflect a reasonable tradeoff between build latency
1409 and change frequency. When the VC system provides coherent
1410 repository-wide revision markers (such as Subversion's revision
1411 numbers, or in fact anything other than CVS's timestamps), the
1412 resulting Build is simply performed against a source tree defined by
1413 that revision marker. When the VC system does not provide this, a
1414 timestamp from the middle of the tree-stable period is used to
1415 generate the source tree@footnote{this @code{checkoutDelay} defaults
1416 to half the tree-stable timer, but it can be overridden with an
1417 argument to the Source Step}.
1419 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1420 @subsection How Different VC Systems Specify Sources
1422 For CVS, the static specifications are @code{repository} and
1423 @code{module}. In addition to those, each build uses a timestamp (or
1424 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1425 (which defaults to HEAD). These parameters collectively specify a set
1426 of sources from which a build may be performed.
1428 @uref{http://subversion.tigris.org, Subversion} combines the
1429 repository, module, and branch into a single @code{Subversion URL}
1430 parameter. Within that scope, source checkouts can be specified by a
1431 numeric @code{revision number} (a repository-wide
1432 monotonically-increasing marker, such that each transaction that
1433 changes the repository is indexed by a different revision number), or
1434 a revision timestamp. When branches are used, the repository and
1435 module form a static @code{baseURL}, while each build has a
1436 @code{revision number} and a @code{branch} (which defaults to a
1437 statically-specified @code{defaultBranch}). The @code{baseURL} and
1438 @code{branch} are simply concatenated together to derive the
1439 @code{svnurl} to use for the checkout.
1441 @uref{http://www.perforce.com/, Perforce} is similar. The server
1442 is specified through a @code{P4PORT} parameter. Module and branch
1443 are specified in a single depot path, and revisions are
1444 depot-wide. When branches are used, the @code{p4base} and
1445 @code{defaultBranch} are concatenated together to produce the depot
1446 path.
1448 @uref{http://wiki.gnuarch.org/, Arch} and
1449 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1450 URL, as well as a @code{version} which is kind of like a branch name.
1451 Arch uses the word @code{archive} to represent the repository. Arch
1452 lets you push changes from one archive to another, removing the strict
1453 centralization required by CVS and SVN. It retains the distinction
1454 between repository and working directory that most other VC systems
1455 use. For complex multi-module directory structures, Arch has a
1456 built-in @code{build config} layer with which the checkout process has
1457 two steps. First, an initial bootstrap checkout is performed to
1458 retrieve a set of build-config files. Second, one of these files is
1459 used to figure out which archives/modules should be used to populate
1460 subdirectories of the initial checkout.
1462 Builders which use Arch and Bazaar therefore have a static archive
1463 @code{url}, and a default ``branch'' (which is a string that specifies
1464 a complete category--branch--version triple). Each build can have its
1465 own branch (the category--branch--version string) to override the
1466 default, as well as a revision number (which is turned into a
1467 --patch-NN suffix when performing the checkout).
1470 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1471 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1472 sort of repository-vs-workspace model as Arch, but the repository data
1473 can either be stored inside the working directory or kept elsewhere
1474 (either on the same machine or on an entirely different machine). For
1475 the purposes of Buildbot (which never commits changes), the repository
1476 is specified with a URL and a revision number.
1478 The most common way to obtain read-only access to a bzr tree is via
1479 HTTP, simply by making the repository visible through a web server
1480 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1481 process has sufficient privileges to access them. Higher performance
1482 can be obtained by running a special Bazaar-specific server. None of
1483 these matter to the buildbot: the repository URL just has to match the
1484 kind of server being used. The @code{repoURL} argument provides the
1485 location of the repository.
1487 Branches are expressed as subdirectories of the main central
1488 repository, which means that if branches are being used, the BZR step
1489 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1490 the @code{repoURL} argument.
1493 @uref{http://darcs.net/, Darcs} doesn't really have the
1494 notion of a single master repository. Nor does it really have
1495 branches. In Darcs, each working directory is also a repository, and
1496 there are operations to push and pull patches from one of these
1497 @code{repositories} to another. For the Buildbot's purposes, all you
1498 need to do is specify the URL of a repository that you want to build
1499 from. The build slave will then pull the latest patches from that
1500 repository and build them. Multiple branches are implemented by using
1501 multiple repositories (possibly living on the same server).
1503 Builders which use Darcs therefore have a static @code{repourl} which
1504 specifies the location of the repository. If branches are being used,
1505 the source Step is instead configured with a @code{baseURL} and a
1506 @code{defaultBranch}, and the two strings are simply concatenated
1507 together to obtain the repository's URL. Each build then has a
1508 specific branch which replaces @code{defaultBranch}, or just uses the
1509 default one. Instead of a revision number, each build can have a
1510 ``context'', which is a string that records all the patches that are
1511 present in a given tree (this is the output of @command{darcs changes
1512 --context}, and is considerably less concise than, e.g. Subversion's
1513 revision number, but the patch-reordering flexibility of Darcs makes
1514 it impossible to provide a shorter useful specification).
1516 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1517 each branch is stored in a separate repository. The @code{repourl},
1518 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1519 same way as with Darcs. The ``revision'', however, is the hash
1520 identifier returned by @command{hg identify}.
1522 @uref{http://git.or.cz/, Git} also follows a decentralized model, and
1523 each repository can have several branches and tags. The source Step is
1524 configured with a static @code{repourl} which specifies the location
1525 of the repository. In addition, an optional @code{branch} parameter
1526 can be specified to check out code from a specific branch instead of
1527 the default ``master'' branch. The ``revision'' is specified as a SHA1
1528 hash as returned by e.g. @command{git rev-parse}. No attempt is made
1529 to ensure that the specified revision is actually a subset of the
1530 specified branch.
1533 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1534 @subsection Attributes of Changes
1536 @heading Who
1538 Each Change has a @code{who} attribute, which specifies which
1539 developer is responsible for the change. This is a string which comes
1540 from a namespace controlled by the VC repository. Frequently this
1541 means it is a username on the host which runs the repository, but not
1542 all VC systems require this (Arch, for example, uses a fully-qualified
1543 @code{Arch ID}, which looks like an email address, as does Darcs).
1544 Each StatusNotifier will map the @code{who} attribute into something
1545 appropriate for their particular means of communication: an email
1546 address, an IRC handle, etc.
1548 @heading Files
1550 It also has a list of @code{files}, which are just the tree-relative
1551 filenames of any files that were added, deleted, or modified for this
1552 Change. These filenames are used by the @code{fileIsImportant}
1553 function (in the Scheduler) to decide whether it is worth triggering a
1554 new build or not, e.g. the function could use the following function
1555 to only run a build if a C file were checked in:
1557 @example
1558 def has_C_files(change):
1559     for name in change.files:
1560         if name.endswith(".c"):
1561             return True
1562     return False
1563 @end example
1565 Certain BuildSteps can also use the list of changed files
1566 to run a more targeted series of tests, e.g. the
1567 @code{python_twisted.Trial} step can run just the unit tests that
1568 provide coverage for the modified .py files instead of running the
1569 full test suite.
1571 @heading Comments
1573 The Change also has a @code{comments} attribute, which is a string
1574 containing any checkin comments.
1576 @heading Revision
1578 Each Change can have a @code{revision} attribute, which describes how
1579 to get a tree with a specific state: a tree which includes this Change
1580 (and all that came before it) but none that come after it. If this
1581 information is unavailable, the @code{.revision} attribute will be
1582 @code{None}. These revisions are provided by the ChangeSource, and
1583 consumed by the @code{computeSourceRevision} method in the appropriate
1584 @code{step.Source} class.
1586 @table @samp
1587 @item CVS
1588 @code{revision} is an int, seconds since the epoch
1589 @item SVN
1590 @code{revision} is an int, the changeset number (r%d)
1591 @item Darcs
1592 @code{revision} is a large string, the output of @code{darcs changes --context}
1593 @item Mercurial
1594 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1595 @item Arch/Bazaar
1596 @code{revision} is the full revision ID (ending in --patch-%d)
1597 @item P4
1598 @code{revision} is an int, the transaction number
1599 @item Git
1600 @code{revision} is a short string (a SHA1 hash), the output of e.g.
1601 @code{git rev-parse}
1602 @end table
1604 @heading Branches
1606 The Change might also have a @code{branch} attribute. This indicates
1607 that all of the Change's files are in the same named branch. The
1608 Schedulers get to decide whether the branch should be built or not.
1610 For VC systems like CVS, Arch, Monotone, and Git, the @code{branch}
1611 name is unrelated to the filename. (that is, the branch name and the
1612 filename inhabit unrelated namespaces). For SVN, branches are
1613 expressed as subdirectories of the repository, so the file's
1614 ``svnurl'' is a combination of some base URL, the branch name, and the
1615 filename within the branch. (In a sense, the branch name and the
1616 filename inhabit the same namespace). Darcs branches are
1617 subdirectories of a base URL just like SVN. Mercurial branches are the
1618 same as Darcs.
1620 @table @samp
1621 @item CVS
1622 branch='warner-newfeature', files=['src/foo.c']
1623 @item SVN
1624 branch='branches/warner-newfeature', files=['src/foo.c']
1625 @item Darcs
1626 branch='warner-newfeature', files=['src/foo.c']
1627 @item Mercurial
1628 branch='warner-newfeature', files=['src/foo.c']
1629 @item Arch/Bazaar
1630 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1631 @item Git
1632 branch='warner-newfeature', files=['src/foo.c']
1633 @end table
1635 @heading Links
1637 @c TODO: who is using 'links'? how is it being used?
1639 Finally, the Change might have a @code{links} list, which is intended
1640 to provide a list of URLs to a @emph{viewcvs}-style web page that
1641 provides more detail for this Change, perhaps including the full file
1642 diffs.
1645 @node Schedulers, BuildSet, Version Control Systems, Concepts
1646 @section Schedulers
1648 @cindex Scheduler
1650 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1651 gets a copy of every incoming Change. The Schedulers are responsible
1652 for deciding when Builds should be run. Some Buildbot installations
1653 might have a single Scheduler, while others may have several, each for
1654 a different purpose.
1656 For example, a ``quick'' scheduler might exist to give immediate
1657 feedback to developers, hoping to catch obvious problems in the code
1658 that can be detected quickly. These typically do not run the full test
1659 suite, nor do they run on a wide variety of platforms. They also
1660 usually do a VC update rather than performing a brand-new checkout
1661 each time. You could have a ``quick'' scheduler which used a 30 second
1662 timeout, and feeds a single ``quick'' Builder that uses a VC
1663 @code{mode='update'} setting.
1665 A separate ``full'' scheduler would run more comprehensive tests a
1666 little while later, to catch more subtle problems. This scheduler
1667 would have a longer tree-stable-timer, maybe 30 minutes, and would
1668 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1669 @code{'clobber'}, or @code{'export'}).
1671 The @code{tree-stable-timer} and @code{fileIsImportant} decisions are
1672 made by the Scheduler. Dependencies are also implemented here.
1673 Periodic builds (those which are run every N seconds rather than after
1674 new Changes arrive) are triggered by a special @code{Periodic}
1675 Scheduler subclass. The default Scheduler class can also be told to
1676 watch for specific branches, ignoring Changes on other branches. This
1677 may be useful if you have a trunk and a few release branches which
1678 should be tracked, but when you don't want to have the Buildbot pay
1679 attention to several dozen private user branches.
1681 When the setup has multiple sources of Changes the @code{category}
1682 can be used for @code{Scheduler} objects to filter out a subset
1683 of the Changes.  Note that not all change sources can attach a category.
1685 Some Schedulers may trigger builds for other reasons, other than
1686 recent Changes. For example, a Scheduler subclass could connect to a
1687 remote buildmaster and watch for builds of a library to succeed before
1688 triggering a local build that uses that library.
1690 Each Scheduler creates and submits @code{BuildSet} objects to the
1691 @code{BuildMaster}, which is then responsible for making sure the
1692 individual @code{BuildRequests} are delivered to the target
1693 @code{Builders}.
1695 @code{Scheduler} instances are activated by placing them in the
1696 @code{c['schedulers']} list in the buildmaster config file. Each
1697 Scheduler has a unique name.
1700 @node BuildSet, BuildRequest, Schedulers, Concepts
1701 @section BuildSet
1703 @cindex BuildSet
1705 A @code{BuildSet} is the name given to a set of Builds that all
1706 compile/test the same version of the tree on multiple Builders. In
1707 general, all these component Builds will perform the same sequence of
1708 Steps, using the same source code, but on different platforms or
1709 against a different set of libraries.
1711 The @code{BuildSet} is tracked as a single unit, which fails if any of
1712 the component Builds have failed, and therefore can succeed only if
1713 @emph{all} of the component Builds have succeeded. There are two kinds
1714 of status notification messages that can be emitted for a BuildSet:
1715 the @code{firstFailure} type (which fires as soon as we know the
1716 BuildSet will fail), and the @code{Finished} type (which fires once
1717 the BuildSet has completely finished, regardless of whether the
1718 overall set passed or failed).
1720 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1721 (branch, revision, changes, patch), some of which may be None, and a
1722 list of Builders on which it is to be run. They are then given to the
1723 BuildMaster, which is responsible for creating a separate
1724 @code{BuildRequest} for each Builder.
1726 There are a couple of different likely values for the
1727 @code{SourceStamp}:
1729 @table @code
1730 @item (revision=None, changes=[CHANGES], patch=None)
1731 This is a @code{SourceStamp} used when a series of Changes have
1732 triggered a build. The VC step will attempt to check out a tree that
1733 contains CHANGES (and any changes that occurred before CHANGES, but
1734 not any that occurred after them).
1736 @item (revision=None, changes=None, patch=None)
1737 This builds the most recent code on the default branch. This is the
1738 sort of @code{SourceStamp} that would be used on a Build that was
1739 triggered by a user request, or a Periodic scheduler. It is also
1740 possible to configure the VC Source Step to always check out the
1741 latest sources rather than paying attention to the Changes in the
1742 SourceStamp, which will result in same behavior as this.
1744 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1745 This builds the most recent code on the given BRANCH. Again, this is
1746 generally triggered by a user request or Periodic build.
1748 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1749 This checks out the tree at the given revision REV, then applies a
1750 patch (using @code{patch -pLEVEL <DIFF}). The @ref{try} feature uses
1751 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1752 step is bypassed.
1754 @end table
1756 The buildmaster is responsible for turning the @code{BuildSet} into a
1757 set of @code{BuildRequest} objects and queueing them on the
1758 appropriate Builders.
1761 @node BuildRequest, Builder, BuildSet, Concepts
1762 @section BuildRequest
1764 @cindex BuildRequest
1766 A @code{BuildRequest} is a request to build a specific set of sources
1767 on a single specific @code{Builder}. Each @code{Builder} runs the
1768 @code{BuildRequest} as soon as it can (i.e. when an associated
1769 buildslave becomes free). @code{BuildRequest}s are prioritized from
1770 oldest to newest, so when a buildslave becomes free, the
1771 @code{Builder} with the oldest @code{BuildRequest} is run.
1773 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1774 The actual process of running the build (the series of Steps that will
1775 be executed) is implemented by the @code{Build} object. In this future
1776 this might be changed, to have the @code{Build} define @emph{what}
1777 gets built, and a separate @code{BuildProcess} (provided by the
1778 Builder) to define @emph{how} it gets built.
1780 @code{BuildRequest} is created with optional @code{Properties}.  One
1781 of these, @code{owner}, is collected by the resultant @code{Build} and
1782 added to the set of @emph{interested users} to which status
1783 notifications will be sent, depending on the configuration for each
1784 status object.
1786 The @code{BuildRequest} may be mergeable with other compatible
1787 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1788 will generally be mergeable. Builds that are triggered by user
1789 requests are generally not, unless they are multiple requests to build
1790 the @emph{latest sources} of the same branch.
1792 @node Builder, Users, BuildRequest, Concepts
1793 @section Builder
1795 @cindex Builder
1797 The @code{Builder} is a long-lived object which controls all Builds of
1798 a given type. Each one is created when the config file is first
1799 parsed, and lives forever (or rather until it is removed from the
1800 config file). It mediates the connections to the buildslaves that do
1801 all the work, and is responsible for creating the @code{Build} objects
1802 that decide @emph{how} a build is performed (i.e., which steps are
1803 executed in what order).
1805 Each @code{Builder} gets a unique name, and the path name of a
1806 directory where it gets to do all its work (there is a
1807 buildmaster-side directory for keeping status information, as well as
1808 a buildslave-side directory where the actual checkout/compile/test
1809 commands are executed). It also gets a @code{BuildFactory}, which is
1810 responsible for creating new @code{Build} instances: because the
1811 @code{Build} instance is what actually performs each build, choosing
1812 the @code{BuildFactory} is the way to specify what happens each time a
1813 build is done.
1815 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1816 A @code{Builder} which is used to perform OS-X builds (as opposed to
1817 Linux or Solaris builds) should naturally be associated with an
1818 OS-X-based buildslave.
1820 A @code{Builder} may be given a set of environment variables to be used
1821 in its @pxref{ShellCommand}s. These variables will override anything in the
1822 buildslave's environment. Variables passed directly to a ShellCommand will
1823 override variables of the same name passed to the Builder.
1825 For example, if you a pool of identical slaves it is often easier to manage
1826 variables like PATH from Buildbot rather than manually editing it inside of
1827 the slaves' environment.
1829 @example
1830 f = factory.BuildFactory
1831 f.addStep(ShellCommand(
1832               command=['bash', './configure']))
1833 f.addStep(Compile())
1835 c['builders'] = [
1836   @{'name': 'test', 'slavenames': ['slave1', 'slave2', 'slave3', 'slave4',
1837                                    'slave5', 'slave6'],
1838     'builddir': 'test', 'factory': f',
1839     'env': @{'PATH': '/opt/local/bin:/opt/app/bin:/usr/local/bin:/usr/bin'@}@}
1841 @end example
1843 @node Users, Build Properties, Builder, Concepts
1844 @section Users
1846 @cindex Users
1848 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1849 the world consists of a set of developers, each of whom can be
1850 described by a couple of simple attributes. These developers make
1851 changes to the source code, causing builds which may succeed or fail.
1853 Each developer is primarily known through the source control system. Each
1854 Change object that arrives is tagged with a @code{who} field that
1855 typically gives the account name (on the repository machine) of the user
1856 responsible for that change. This string is the primary key by which the
1857 User is known, and is displayed on the HTML status pages and in each Build's
1858 ``blamelist''.
1860 To do more with the User than just refer to them, this username needs to
1861 be mapped into an address of some sort. The responsibility for this mapping
1862 is left up to the status module which needs the address. The core code knows
1863 nothing about email addresses or IRC nicknames, just user names.
1865 @menu
1866 * Doing Things With Users::
1867 * Email Addresses::
1868 * IRC Nicknames::
1869 * Live Status Clients::
1870 @end menu
1872 @node Doing Things With Users, Email Addresses, Users, Users
1873 @subsection Doing Things With Users
1875 Each Change has a single User who is responsible for that Change. Most
1876 Builds have a set of Changes: the Build represents the first time these
1877 Changes have been built and tested by the Buildbot. The build has a
1878 ``blamelist'' that consists of a simple union of the Users responsible
1879 for all the Build's Changes.
1881 The Build provides (through the IBuildStatus interface) a list of Users
1882 who are ``involved'' in the build. For now this is equal to the
1883 blamelist, but in the future it will be expanded to include a ``build
1884 sheriff'' (a person who is ``on duty'' at that time and responsible for
1885 watching over all builds that occur during their shift), as well as
1886 per-module owners who simply want to keep watch over their domain (chosen by
1887 subdirectory or a regexp matched against the filenames pulled out of the
1888 Changes). The Involved Users are those who probably have an interest in the
1889 results of any given build.
1891 In the future, Buildbot will acquire the concept of ``Problems'',
1892 which last longer than builds and have beginnings and ends. For example, a
1893 test case which passed in one build and then failed in the next is a
1894 Problem. The Problem lasts until the test case starts passing again, at
1895 which point the Problem is said to be ``resolved''.
1897 If there appears to be a code change that went into the tree at the
1898 same time as the test started failing, that Change is marked as being
1899 resposible for the Problem, and the user who made the change is added
1900 to the Problem's ``Guilty'' list. In addition to this user, there may
1901 be others who share responsibility for the Problem (module owners,
1902 sponsoring developers). In addition to the Responsible Users, there
1903 may be a set of Interested Users, who take an interest in the fate of
1904 the Problem.
1906 Problems therefore have sets of Users who may want to be kept aware of
1907 the condition of the problem as it changes over time. If configured, the
1908 Buildbot can pester everyone on the Responsible list with increasing
1909 harshness until the problem is resolved, with the most harshness reserved
1910 for the Guilty parties themselves. The Interested Users may merely be told
1911 when the problem starts and stops, as they are not actually responsible for
1912 fixing anything.
1914 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1915 @subsection Email Addresses
1917 The @code{buildbot.status.mail.MailNotifier} class
1918 (@pxref{MailNotifier}) provides a status target which can send email
1919 about the results of each build. It accepts a static list of email
1920 addresses to which each message should be delivered, but it can also
1921 be configured to send mail to the Build's Interested Users. To do
1922 this, it needs a way to convert User names into email addresses.
1924 For many VC systems, the User Name is actually an account name on the
1925 system which hosts the repository. As such, turning the name into an
1926 email address is a simple matter of appending
1927 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1928 (for example the preferred email address may be at ``project.org''
1929 despite the repository host being named ``cvs.project.org''), and some
1930 VC systems have full separation between the concept of a user and that
1931 of an account on the repository host (like Perforce). Some systems
1932 (like Arch) put a full contact email address in every change.
1934 To convert these names to addresses, the MailNotifier uses an EmailLookup
1935 object. This provides a .getAddress method which accepts a name and
1936 (eventually) returns an address. The default @code{MailNotifier}
1937 module provides an EmailLookup which simply appends a static string,
1938 configurable when the notifier is created. To create more complex behaviors
1939 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1940 determine a preferred address for the developer), provide a different object
1941 as the @code{lookup} argument.
1943 In the future, when the Problem mechanism has been set up, the Buildbot
1944 will need to send mail to arbitrary Users. It will do this by locating a
1945 MailNotifier-like object among all the buildmaster's status targets, and
1946 asking it to send messages to various Users. This means the User-to-address
1947 mapping only has to be set up once, in your MailNotifier, and every email
1948 message the buildbot emits will take advantage of it.
1950 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1951 @subsection IRC Nicknames
1953 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1954 provides a status target which can announce the results of each build. It
1955 also provides an interactive interface by responding to online queries
1956 posted in the channel or sent as private messages.
1958 In the future, the buildbot can be configured map User names to IRC
1959 nicknames, to watch for the recent presence of these nicknames, and to
1960 deliver build status messages to the interested parties. Like
1961 @code{MailNotifier} does for email addresses, the @code{IRC} object
1962 will have an @code{IRCLookup} which is responsible for nicknames. The
1963 mapping can be set up statically, or it can be updated by online users
1964 themselves (by claiming a username with some kind of ``buildbot: i am
1965 user warner'' commands).
1967 Once the mapping is established, the rest of the buildbot can ask the
1968 @code{IRC} object to send messages to various users. It can report on
1969 the likelihood that the user saw the given message (based upon how long the
1970 user has been inactive on the channel), which might prompt the Problem
1971 Hassler logic to send them an email message instead.
1973 @node Live Status Clients,  , IRC Nicknames, Users
1974 @subsection Live Status Clients
1976 The Buildbot also offers a PB-based status client interface which can
1977 display real-time build status in a GUI panel on the developer's desktop.
1978 This interface is normally anonymous, but it could be configured to let the
1979 buildmaster know @emph{which} developer is using the status client. The
1980 status client could then be used as a message-delivery service, providing an
1981 alternative way to deliver low-latency high-interruption messages to the
1982 developer (like ``hey, you broke the build'').
1984 @node Build Properties,  , Users, Concepts
1985 @section Build Properties
1986 @cindex Properties
1988 Each build has a set of ``Build Properties'', which can be used by its
1989 BuildStep to modify their actions.  These properties, in the form of
1990 key-value pairs, provide a general framework for dynamically altering
1991 the behavior of a build based on its circumstances.
1993 Properties come from a number of places:
1994 @itemize
1995 @item global configuration --
1996 These properties apply to all builds.
1997 @item schedulers --
1998 A scheduler can specify properties available to all the builds it
1999 starts.
2000 @item buildslaves --
2001 A buildslave can pass properties on to the builds it performs.
2002 @item builds --
2003 A build automatically sets a number of properties on itself.
2004 @item steps --
2005 Steps of a build can set properties that are available to subsequent
2006 steps.  In particular, source steps set a number of properties.
2007 @end itemize
2009 Properties are very flexible, and can be used to implement all manner
2010 of functionality.  Here are some examples:
2012 Most Source steps record the revision that they checked out in
2013 the @code{got_revision} property.  A later step could use this
2014 property to specify the name of a fully-built tarball, dropped in an
2015 easily-acessible directory for later testing.
2017 Some projects want to perform nightly builds as well as in response
2018 to committed changes.  Such a project would run two schedulers,
2019 both pointing to the same set of builders, but could provide an
2020 @code{is_nightly} property so that steps can distinguish the nightly
2021 builds, perhaps to run more resource-intensive tests.
2023 Some projects have different build processes on different systems.
2024 Rather than create a build factory for each slave, the steps can use
2025 buildslave properties to identify the unique aspects of each slave
2026 and adapt the build process dynamically.
2028 @node Configuration, Getting Source Code Changes, Concepts, Top
2029 @chapter Configuration
2031 @cindex Configuration
2033 The buildbot's behavior is defined by the ``config file'', which
2034 normally lives in the @file{master.cfg} file in the buildmaster's base
2035 directory (but this can be changed with an option to the
2036 @code{buildbot create-master} command). This file completely specifies
2037 which Builders are to be run, which slaves they should use, how
2038 Changes should be tracked, and where the status information is to be
2039 sent. The buildmaster's @file{buildbot.tac} file names the base
2040 directory; everything else comes from the config file.
2042 A sample config file was installed for you when you created the
2043 buildmaster, but you will need to edit it before your buildbot will do
2044 anything useful.
2046 This chapter gives an overview of the format of this file and the
2047 various sections in it. You will need to read the later chapters to
2048 understand how to fill in each section properly.
2050 @menu
2051 * Config File Format::
2052 * Loading the Config File::
2053 * Testing the Config File::
2054 * Defining the Project::
2055 * Change Sources and Schedulers::
2056 * Merging BuildRequests::
2057 * Setting the slaveport::
2058 * Buildslave Specifiers::
2059 * On-Demand ("Latent") Buildslaves::
2060 * Defining Global Properties::
2061 * Defining Builders::
2062 * Defining Status Targets::
2063 * Debug options::
2064 @end menu
2066 @node Config File Format, Loading the Config File, Configuration, Configuration
2067 @section Config File Format
2069 The config file is, fundamentally, just a piece of Python code which
2070 defines a dictionary named @code{BuildmasterConfig}, with a number of
2071 keys that are treated specially. You don't need to know Python to do
2072 basic configuration, though, you can just copy the syntax of the
2073 sample file. If you @emph{are} comfortable writing Python code,
2074 however, you can use all the power of a full programming language to
2075 achieve more complicated configurations.
2077 The @code{BuildmasterConfig} name is the only one which matters: all
2078 other names defined during the execution of the file are discarded.
2079 When parsing the config file, the Buildmaster generally compares the
2080 old configuration with the new one and performs the minimum set of
2081 actions necessary to bring the buildbot up to date: Builders which are
2082 not changed are left untouched, and Builders which are modified get to
2083 keep their old event history.
2085 Basic Python syntax: comments start with a hash character (``#''),
2086 tuples are defined with @code{(parenthesis, pairs)}, arrays are
2087 defined with @code{[square, brackets]}, tuples and arrays are mostly
2088 interchangeable. Dictionaries (data structures which map ``keys'' to
2089 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
2090 'key2': 'value2'@} }. Function calls (and object instantiation) can use
2091 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
2093 The config file starts with a series of @code{import} statements,
2094 which make various kinds of Steps and Status targets available for
2095 later use. The main @code{BuildmasterConfig} dictionary is created,
2096 then it is populated with a variety of keys. These keys are broken
2097 roughly into the following sections, each of which is documented in
2098 the rest of this chapter:
2100 @itemize @bullet
2101 @item
2102 Project Definitions
2103 @item
2104 Change Sources / Schedulers
2105 @item
2106 Slaveport
2107 @item
2108 Buildslave Configuration
2109 @item
2110 Builders / Interlocks
2111 @item
2112 Status Targets
2113 @item
2114 Debug options
2115 @end itemize
2117 The config file can use a few names which are placed into its namespace:
2119 @table @code
2120 @item basedir
2121 the base directory for the buildmaster. This string has not been
2122 expanded, so it may start with a tilde. It needs to be expanded before
2123 use. The config file is located in
2124 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
2126 @end table
2129 @node Loading the Config File, Testing the Config File, Config File Format, Configuration
2130 @section Loading the Config File
2132 The config file is only read at specific points in time. It is first
2133 read when the buildmaster is launched. Once it is running, there are
2134 various ways to ask it to reload the config file. If you are on the
2135 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
2136 it: the @command{buildbot} tool has a shortcut for this:
2138 @example
2139 buildbot reconfig @var{BASEDIR}
2140 @end example
2142 This command will show you all of the lines from @file{twistd.log}
2143 that relate to the reconfiguration. If there are any problems during
2144 the config-file reload, they will be displayed in these lines.
2146 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
2147 ``Reload .cfg'' button which will also trigger a reload. In the
2148 future, there will be other ways to accomplish this step (probably a
2149 password-protected button on the web page, as well as a privileged IRC
2150 command).
2152 When reloading the config file, the buildmaster will endeavor to
2153 change as little as possible about the running system. For example,
2154 although old status targets may be shut down and new ones started up,
2155 any status targets that were not changed since the last time the
2156 config file was read will be left running and untouched. Likewise any
2157 Builders which have not been changed will be left running. If a
2158 Builder is modified (say, the build process is changed) while a Build
2159 is currently running, that Build will keep running with the old
2160 process until it completes. Any previously queued Builds (or Builds
2161 which get queued after the reconfig) will use the new process.
2163 @node Testing the Config File, Defining the Project, Loading the Config File, Configuration
2164 @section Testing the Config File
2166 To verify that the config file is well-formed and contains no
2167 deprecated or invalid elements, use the ``checkconfig'' command:
2169 @example
2170 % buildbot checkconfig master.cfg
2171 Config file is good!
2172 @end example
2174 If the config file has deprecated features (perhaps because you've
2175 upgraded the buildmaster and need to update the config file to match),
2176 they will be announced by checkconfig. In this case, the config file
2177 will work, but you should really remove the deprecated items and use
2178 the recommended replacements instead:
2180 @example
2181 % buildbot checkconfig master.cfg
2182 /usr/lib/python2.4/site-packages/buildbot/master.py:559: DeprecationWarning: c['sources'] is
2183 deprecated as of 0.7.6 and will be removed by 0.8.0 . Please use c['change_source'] instead.
2184   warnings.warn(m, DeprecationWarning)
2185 Config file is good!
2186 @end example
2188 If the config file is simply broken, that will be caught too:
2190 @example
2191 % buildbot checkconfig master.cfg
2192 Traceback (most recent call last):
2193   File "/usr/lib/python2.4/site-packages/buildbot/scripts/runner.py", line 834, in doCheckConfig
2194     ConfigLoader(configFile)
2195   File "/usr/lib/python2.4/site-packages/buildbot/scripts/checkconfig.py", line 31, in __init__
2196     self.loadConfig(configFile)
2197   File "/usr/lib/python2.4/site-packages/buildbot/master.py", line 480, in loadConfig
2198     exec f in localDict
2199   File "/home/warner/BuildBot/master/foolscap/master.cfg", line 90, in ?
2200     c[bogus] = "stuff"
2201 NameError: name 'bogus' is not defined
2202 @end example
2205 @node Defining the Project, Change Sources and Schedulers, Testing the Config File, Configuration
2206 @section Defining the Project
2208 There are a couple of basic settings that you use to tell the buildbot
2209 what project it is working on. This information is used by status
2210 reporters to let users find out more about the codebase being
2211 exercised by this particular Buildbot installation.
2213 @example
2214 c['projectName'] = "Buildbot"
2215 c['projectURL'] = "http://buildbot.sourceforge.net/"
2216 c['buildbotURL'] = "http://localhost:8010/"
2217 @end example
2219 @bcindex c['projectName']
2220 @code{projectName} is a short string will be used to describe the
2221 project that this buildbot is working on. For example, it is used as
2222 the title of the waterfall HTML page.
2224 @bcindex c['projectURL']
2225 @code{projectURL} is a string that gives a URL for the project as a
2226 whole. HTML status displays will show @code{projectName} as a link to
2227 @code{projectURL}, to provide a link from buildbot HTML pages to your
2228 project's home page.
2230 @bcindex c['buildbotURL']
2231 The @code{buildbotURL} string should point to the location where the
2232 buildbot's internal web server (usually the @code{html.Waterfall}
2233 page) is visible. This typically uses the port number set when you
2234 create the @code{Waterfall} object: the buildbot needs your help to
2235 figure out a suitable externally-visible host name.
2237 When status notices are sent to users (either by email or over IRC),
2238 @code{buildbotURL} will be used to create a URL to the specific build
2239 or problem that they are being notified about. It will also be made
2240 available to queriers (over IRC) who want to find out where to get
2241 more information about this buildbot.
2243 @bcindex c['logCompressionLimit']
2244 The @code{logCompressionLimit} enables bz2-compression of build logs on
2245 disk for logs that are bigger than the given size, or disables that
2246 completely if given @code{False}. The default value is 4k, which should
2247 be a reasonable default on most file systems. This setting has no impact
2248 on status plugins, and merely affects the required disk space on the
2249 master for build logs.
2252 @node Change Sources and Schedulers, Merging BuildRequests, Defining the Project, Configuration
2253 @section Change Sources and Schedulers
2255 @bcindex c['sources']
2256 @bcindex c['change_source']
2258 The @code{c['change_source']} key is the ChangeSource
2259 instance@footnote{To be precise, it is an object or a list of objects
2260 which all implement the @code{buildbot.interfaces.IChangeSource}
2261 Interface. It is unusual to have multiple ChangeSources, so this key
2262 accepts either a single ChangeSource or a sequence of them.} that
2263 defines how the buildmaster learns about source code changes. More
2264 information about what goes here is available in @xref{Getting Source
2265 Code Changes}.
2267 @example
2268 from buildbot.changes.pb import PBChangeSource
2269 c['change_source'] = PBChangeSource()
2270 @end example
2271 @bcindex c['schedulers']
2273 (note: in buildbot-0.7.5 and earlier, this key was named
2274 @code{c['sources']}, and required a list. @code{c['sources']} is
2275 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2276 future release).
2278 @code{c['schedulers']} is a list of Scheduler instances, each
2279 of which causes builds to be started on a particular set of
2280 Builders. The two basic Scheduler classes you are likely to start
2281 with are @code{Scheduler} and @code{Periodic}, but you can write a
2282 customized subclass to implement more complicated build scheduling.
2284 Scheduler arguments
2285 should always be specified by name (as keyword arguments), to allow
2286 for future expansion:
2288 @example
2289 sched = Scheduler(name="quick", builderNames=['lin', 'win'])
2290 @end example
2292 All schedulers have several arguments in common:
2294 @table @code
2295 @item name
2297 Each Scheduler must have a unique name. This is used in status
2298 displays, and is also available in the build property @code{scheduler}.
2300 @item builderNames
2302 This is the set of builders which this scheduler should trigger, specified
2303 as a list of names (strings).
2305 @item properties
2306 @cindex Properties
2308 This is a dictionary specifying properties that will be transmitted
2309 to all builds started by this scheduler.
2311 @end table
2313 Here is a brief catalog of the available Scheduler types. All these
2314 Schedulers are classes in @code{buildbot.scheduler}, and the
2315 docstrings there are the best source of documentation on the arguments
2316 taken by each one.
2318 @menu
2319 * Scheduler Scheduler::
2320 * AnyBranchScheduler::
2321 * Dependent Scheduler::
2322 * Periodic Scheduler::
2323 * Nightly Scheduler::
2324 * Try Schedulers::
2325 * Triggerable Scheduler::
2326 @end menu
2328 @node Scheduler Scheduler, AnyBranchScheduler, Change Sources and Schedulers, Change Sources and Schedulers
2329 @subsection Scheduler Scheduler
2330 @slindex buildbot.scheduler.Scheduler
2332 This is the original and still most popular Scheduler class. It follows
2333 exactly one branch, and starts a configurable tree-stable-timer after
2334 each change on that branch. When the timer expires, it starts a build
2335 on some set of Builders. The Scheduler accepts a @code{fileIsImportant}
2336 function which can be used to ignore some Changes if they do not
2337 affect any ``important'' files.
2339 The arguments to this scheduler are:
2341 @table @code
2342 @item name
2344 @item builderNames
2346 @item properties
2348 @item branch
2349 This Scheduler will pay attention to a single branch, ignoring Changes
2350 that occur on other branches. Setting @code{branch} equal to the
2351 special value of @code{None} means it should only pay attention to
2352 the default branch. Note that @code{None} is a keyword, not a string,
2353 so you want to use @code{None} and not @code{"None"}.
2355 @item treeStableTimer
2356 The Scheduler will wait for this many seconds before starting the
2357 build. If new changes are made during this interval, the timer will be
2358 restarted, so really the build will be started after a change and then
2359 after this many seconds of inactivity.
2361 @item fileIsImportant
2362 A callable which takes one argument, a Change instance, and returns
2363 @code{True} if the change is worth building, and @code{False} if
2364 it is not.  Unimportant Changes are accumulated until the build is
2365 triggered by an important change.  The default value of None means
2366 that all Changes are important.
2368 @item categories
2369 A list of categories of changes that this scheduler will respond to.  If this
2370 is specified, then any non-matching changes are ignored.
2372 @end table
2374 Example:
2376 @example
2377 from buildbot import scheduler
2378 quick = scheduler.Scheduler(name="quick",
2379                     branch=None,
2380                     treeStableTimer=60,
2381                     builderNames=["quick-linux", "quick-netbsd"])
2382 full = scheduler.Scheduler(name="full",
2383                     branch=None,
2384                     treeStableTimer=5*60,
2385                     builderNames=["full-linux", "full-netbsd", "full-OSX"])
2386 c['schedulers'] = [quick, full]
2387 @end example
2389 In this example, the two ``quick'' builders are triggered 60 seconds
2390 after the tree has been changed. The ``full'' builds do not run quite
2391 so quickly (they wait 5 minutes), so hopefully if the quick builds
2392 fail due to a missing file or really simple typo, the developer can
2393 discover and fix the problem before the full builds are started. Both
2394 Schedulers only pay attention to the default branch: any changes
2395 on other branches are ignored by these Schedulers. Each Scheduler
2396 triggers a different set of Builders, referenced by name.
2398 @node AnyBranchScheduler, Dependent Scheduler, Scheduler Scheduler, Change Sources and Schedulers
2399 @subsection AnyBranchScheduler
2400 @slindex buildbot.scheduler.AnyBranchScheduler
2402 This scheduler uses a tree-stable-timer like the default one, but
2403 follows multiple branches at once. Each branch gets a separate timer.
2405 The arguments to this scheduler are:
2407 @table @code
2408 @item name
2410 @item builderNames
2412 @item properties
2414 @item branches
2415 This Scheduler will pay attention to any number of branches, ignoring
2416 Changes that occur on other branches. Branches are specified just as
2417 for the @code{Scheduler} class.
2419 @item treeStableTimer
2420 The Scheduler will wait for this many seconds before starting the
2421 build. If new changes are made during this interval, the timer will be
2422 restarted, so really the build will be started after a change and then
2423 after this many seconds of inactivity.
2425 @item fileIsImportant
2426 A callable which takes one argument, a Change instance, and returns
2427 @code{True} if the change is worth building, and @code{False} if
2428 it is not.  Unimportant Changes are accumulated until the build is
2429 triggered by an important change.  The default value of None means
2430 that all Changes are important.
2431 @end table
2433 @node Dependent Scheduler, Periodic Scheduler, AnyBranchScheduler, Change Sources and Schedulers
2434 @subsection Dependent Scheduler
2435 @cindex Dependent
2436 @cindex Dependencies
2437 @slindex buildbot.scheduler.Dependent
2439 It is common to wind up with one kind of build which should only be
2440 performed if the same source code was successfully handled by some
2441 other kind of build first. An example might be a packaging step: you
2442 might only want to produce .deb or RPM packages from a tree that was
2443 known to compile successfully and pass all unit tests. You could put
2444 the packaging step in the same Build as the compile and testing steps,
2445 but there might be other reasons to not do this (in particular you
2446 might have several Builders worth of compiles/tests, but only wish to
2447 do the packaging once). Another example is if you want to skip the
2448 ``full'' builds after a failing ``quick'' build of the same source
2449 code. Or, if one Build creates a product (like a compiled library)
2450 that is used by some other Builder, you'd want to make sure the
2451 consuming Build is run @emph{after} the producing one.
2453 You can use ``Dependencies'' to express this relationship
2454 to the Buildbot. There is a special kind of Scheduler named
2455 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2456 for builds to complete successfully (on all of its Builders). Each time
2457 that happens, the same source code (i.e. the same @code{SourceStamp})
2458 will be used to start a new set of builds, on a different set of
2459 Builders. This ``downstream'' scheduler doesn't pay attention to
2460 Changes at all. It only pays attention to the upstream scheduler.
2462 If the build fails on any of the Builders in the upstream set,
2463 the downstream builds will not fire.  Note that, for SourceStamps
2464 generated by a ChangeSource, the @code{revision} is None, meaning HEAD.
2465 If any changes are committed between the time the upstream scheduler
2466 begins its build and the time the dependent scheduler begins its
2467 build, then those changes will be included in the downstream build.
2468 See the @pxref{Triggerable Scheduler} for a more flexible dependency
2469 mechanism that can avoid this problem.
2471 The arguments to this scheduler are:
2473 @table @code
2474 @item name
2476 @item builderNames
2478 @item properties
2480 @item upstream
2481 The upstream scheduler to watch.  Note that this is an ``instance'',
2482 not the name of the scheduler.
2483 @end table
2485 Example:
2487 @example
2488 from buildbot import scheduler
2489 tests = scheduler.Scheduler("just-tests", None, 5*60,
2490                             ["full-linux", "full-netbsd", "full-OSX"])
2491 package = scheduler.Dependent("build-package",
2492                               tests, # upstream scheduler -- no quotes!
2493                               ["make-tarball", "make-deb", "make-rpm"])
2494 c['schedulers'] = [tests, package]
2495 @end example
2497 @node Periodic Scheduler, Nightly Scheduler, Dependent Scheduler, Change Sources and Schedulers
2498 @subsection Periodic Scheduler
2499 @slindex buildbot.scheduler.Periodic
2501 This simple scheduler just triggers a build every N seconds.
2503 The arguments to this scheduler are:
2505 @table @code
2506 @item name
2508 @item builderNames
2510 @item properties
2512 @item periodicBuildTimer
2513 The time, in seconds, after which to start a build.
2514 @end table
2516 Example:
2518 @example
2519 from buildbot import scheduler
2520 nightly = scheduler.Periodic(name="nightly",
2521                 builderNames=["full-solaris"],
2522                 periodicBuildTimer=24*60*60)
2523 c['schedulers'] = [nightly]
2524 @end example
2526 The Scheduler in this example just runs the full solaris build once
2527 per day. Note that this Scheduler only lets you control the time
2528 between builds, not the absolute time-of-day of each Build, so this
2529 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2530 depending upon when it was first activated.
2532 @node Nightly Scheduler, Try Schedulers, Periodic Scheduler, Change Sources and Schedulers
2533 @subsection Nightly Scheduler
2534 @slindex buildbot.scheduler.Nightly
2536 This is highly configurable periodic build scheduler, which triggers
2537 a build at particular times of day, week, month, or year. The
2538 configuration syntax is very similar to the well-known @code{crontab}
2539 format, in which you provide values for minute, hour, day, and month
2540 (some of which can be wildcards), and a build is triggered whenever
2541 the current time matches the given constraints. This can run a build
2542 every night, every morning, every weekend, alternate Thursdays,
2543 on your boss's birthday, etc.
2545 Pass some subset of @code{minute}, @code{hour}, @code{dayOfMonth},
2546 @code{month}, and @code{dayOfWeek}; each may be a single number or
2547 a list of valid values. The builds will be triggered whenever the
2548 current time matches these values. Wildcards are represented by a
2549 '*' string. All fields default to a wildcard except 'minute', so
2550 with no fields this defaults to a build every hour, on the hour.
2551 The full list of parameters is:
2553 @table @code
2554 @item name
2556 @item builderNames
2558 @item properties
2560 @item branch
2561 The branch to build, just as for @code{Scheduler}.
2563 @item minute
2564 The minute of the hour on which to start the build.  This defaults
2565 to 0, meaning an hourly build.
2567 @item hour
2568 The hour of the day on which to start the build, in 24-hour notation.
2569 This defaults to *, meaning every hour.
2571 @item month
2572 The month in which to start the build, with January = 1.  This defaults
2573 to *, meaning every month.
2575 @item dayOfWeek
2576 The day of the week to start a build, with Monday = 0.  This defauls
2577 to *, meaning every day of the week.
2579 @item onlyIfChanged
2580 If this is true, then builds will not be scheduled at the designated time
2581 unless the source has changed since the previous build.
2582 @end table
2584 For example, the following master.cfg clause will cause a build to be
2585 started every night at 3:00am:
2587 @example
2588 s = scheduler.Nightly(name='nightly',
2589         builderNames=['builder1', 'builder2'],
2590         hour=3,
2591         minute=0)
2592 @end example
2594 This scheduler will perform a build each monday morning at 6:23am and
2595 again at 8:23am, but only if someone has committed code in the interim:
2597 @example
2598 s = scheduler.Nightly(name='BeforeWork',
2599          builderNames=['builder1'],
2600          dayOfWeek=0,
2601          hour=[6,8],
2602          minute=23,
2603          onlyIfChanged=True)
2604 @end example
2606 The following runs a build every two hours, using Python's @code{range}
2607 function:
2609 @example
2610 s = Nightly(name='every2hours',
2611         builderNames=['builder1'],
2612         hour=range(0, 24, 2))
2613 @end example
2615 Finally, this example will run only on December 24th:
2617 @example
2618 s = Nightly(name='SleighPreflightCheck',
2619         builderNames=['flying_circuits', 'radar'],
2620         month=12,
2621         dayOfMonth=24,
2622         hour=12,
2623         minute=0)
2624 @end example
2626 @node Try Schedulers, Triggerable Scheduler, Nightly Scheduler, Change Sources and Schedulers
2627 @subsection Try Schedulers
2628 @slindex buildbot.scheduler.Try_Jobdir
2629 @slindex buildbot.scheduler.Try_Userpass
2631 This scheduler allows developers to use the @code{buildbot try}
2632 command to trigger builds of code they have not yet committed. See
2633 @ref{try} for complete details.
2635 Two implementations are available: @code{Try_Jobdir} and
2636 @code{Try_Userpass}.  The former monitors a job directory, specified
2637 by the @code{jobdir} parameter, while the latter listens for PB
2638 connections on a specific @code{port}, and authenticates against
2639 @code{userport}.
2641 @node Triggerable Scheduler,  , Try Schedulers, Change Sources and Schedulers
2642 @subsection Triggerable Scheduler
2643 @cindex Triggers
2644 @slindex buildbot.scheduler.Triggerable
2646 The @code{Triggerable} scheduler waits to be triggered by a Trigger
2647 step (see @ref{Triggering Schedulers}) in another build. That step
2648 can optionally wait for the scheduler's builds to complete. This
2649 provides two advantages over Dependent schedulers. First, the same
2650 scheduler can be triggered from multiple builds. Second, the ability
2651 to wait for a Triggerable's builds to complete provides a form of
2652 "subroutine call", where one or more builds can "call" a scheduler
2653 to perform some work for them, perhaps on other buildslaves.
2655 The parameters are just the basics:
2657 @table @code
2658 @item name
2659 @item builderNames
2660 @item properties
2661 @end table
2663 This class is only useful in conjunction with the @code{Trigger} step.
2664 Here is a fully-worked example:
2666 @example
2667 from buildbot import scheduler
2668 from buildbot.process import factory
2669 from buildbot.steps import trigger
2671 checkin = scheduler.Scheduler(name="checkin",
2672             branch=None,
2673             treeStableTimer=5*60,
2674             builderNames=["checkin"])
2675 nightly = scheduler.Nightly(name='nightly',
2676             builderNames=['nightly'],
2677             hour=3,
2678             minute=0)
2680 mktarball = scheduler.Triggerable(name="mktarball",
2681                 builderNames=["mktarball"])
2682 build = scheduler.Triggerable(name="build-all-platforms",
2683                 builderNames=["build-all-platforms"])
2684 test = scheduler.Triggerable(name="distributed-test",
2685                 builderNames=["distributed-test"])
2686 package = scheduler.Triggerable(name="package-all-platforms",
2687                 builderNames=["package-all-platforms"])
2689 c['schedulers'] = [checkin, nightly, build, test, package]
2691 # on checkin, make a tarball, build it, and test it
2692 checkin_factory = factory.BuildFactory()
2693 checkin_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2694                                        waitForFinish=True))
2695 checkin_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2696                                    waitForFinish=True))
2697 checkin_factory.addStep(trigger.Trigger(schedulerNames=['distributed-test'],
2698                                   waitForFinish=True))
2700 # and every night, make a tarball, build it, and package it
2701 nightly_factory = factory.BuildFactory()
2702 nightly_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2703                                        waitForFinish=True))
2704 nightly_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2705                                    waitForFinish=True))
2706 nightly_factory.addStep(trigger.Trigger(schedulerNames=['package-all-platforms'],
2707                                      waitForFinish=True))
2708 @end example
2710 @node Merging BuildRequests, Setting the slaveport, Change Sources and Schedulers, Configuration
2711 @section Merging BuildRequests
2713 @bcindex c['mergeRequests']
2715 By default, buildbot merges BuildRequests that have the compatible
2716 SourceStamps. This behaviour can be customized with the
2717 @code{c['mergeRequests']} configuration key.  This key specifies a function
2718 which is caleld with three arguments: a @code{Builder} and two
2719 @code{BuildRequest} objects.  It should return true if the requests can be
2720 merged.  For example:
2722 @example
2723 def mergeRequests(builder, req1, req2):
2724     """Don't merge buildrequest at all"""
2725     return False
2726 c['mergeRequests'] = mergeRequests
2727 @end example
2729 In many cases, the details of the SourceStamps and BuildRequests are important.
2730 In this example, only BuildRequests with the same "reason" are merged; thus
2731 developers forcing builds for different reasons will see distinct builds.
2733 @example
2734 def mergeRequests(builder, req1, req2):
2735     if req1.source.canBeMergedWith(req2.source) and  req1.reason == req2.reason:
2736        return True
2737     return False
2738 c['mergeRequests'] = mergeRequests
2739 @end example
2741 @node Setting the slaveport, Buildslave Specifiers, Merging BuildRequests, Configuration
2742 @section Setting the slaveport
2744 @bcindex c['slavePortnum']
2746 The buildmaster will listen on a TCP port of your choosing for
2747 connections from buildslaves. It can also use this port for
2748 connections from remote Change Sources, status clients, and debug
2749 tools. This port should be visible to the outside world, and you'll
2750 need to tell your buildslave admins about your choice.
2752 It does not matter which port you pick, as long it is externally
2753 visible, however you should probably use something larger than 1024,
2754 since most operating systems don't allow non-root processes to bind to
2755 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2756 box of some sort, you may have to configure your firewall to permit
2757 inbound connections to this port.
2759 @example
2760 c['slavePortnum'] = 10000
2761 @end example
2763 @code{c['slavePortnum']} is a @emph{strports} specification string,
2764 defined in the @code{twisted.application.strports} module (try
2765 @command{pydoc twisted.application.strports} to get documentation on
2766 the format). This means that you can have the buildmaster listen on a
2767 localhost-only port by doing:
2769 @example
2770 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2771 @end example
2773 This might be useful if you only run buildslaves on the same machine,
2774 and they are all configured to contact the buildmaster at
2775 @code{localhost:10000}.
2778 @node Buildslave Specifiers, On-Demand ("Latent") Buildslaves, Setting the slaveport, Configuration
2779 @section Buildslave Specifiers
2780 @bcindex c['slaves']
2782 The @code{c['slaves']} key is a list of known buildslaves. In the common case,
2783 each buildslave is defined by an instance of the BuildSlave class.  It
2784 represents a standard, manually started machine that will try to connect to
2785 the buildbot master as a slave.  Contrast these with the "on-demand" latent
2786 buildslaves, such as the Amazon Web Service Elastic Compute Cloud latent
2787 buildslave discussed below.
2789 The BuildSlave class is instantiated with two values: (slavename,
2790 slavepassword). These are the same two values that need to be provided to the
2791 buildslave administrator when they create the buildslave.
2793 The slavenames must be unique, of course. The password exists to
2794 prevent evildoers from interfering with the buildbot by inserting
2795 their own (broken) buildslaves into the system and thus displacing the
2796 real ones.
2798 Buildslaves with an unrecognized slavename or a non-matching password
2799 will be rejected when they attempt to connect, and a message
2800 describing the problem will be put in the log file (see @ref{Logfiles}).
2802 @example
2803 from buildbot.buildslave import BuildSlave
2804 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd')
2805                BuildSlave('bot-bsd', 'bsdpasswd')
2806               ]
2807 @end example
2809 @cindex Properties
2810 @code{BuildSlave} objects can also be created with an optional
2811 @code{properties} argument, a dictionary specifying properties that
2812 will be available to any builds performed on this slave.  For example:
2814 @example
2815 from buildbot.buildslave import BuildSlave
2816 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2817                     properties=@{'os':'solaris'@}),
2818               ]
2819 @end example
2821 The @code{BuildSlave} constructor can also take an optional
2822 @code{max_builds} parameter to limit the number of builds that it
2823 will execute simultaneously:
2825 @example
2826 from buildbot.buildslave import BuildSlave
2827 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2828 @end example
2830 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2831 key was used instead, and it took a list of (name, password) tuples.
2832 This key is accepted for backwards compatibility, but is deprecated as
2833 of 0.7.6 and will go away in some future release.
2835 @menu
2836 * When Buildslaves Go Missing::
2837 @end menu
2839 @node When Buildslaves Go Missing, , , Buildslave Specifiers
2840 @subsection When Buildslaves Go Missing
2842 Sometimes, the buildslaves go away. One very common reason for this is
2843 when the buildslave process is started once (manually) and left
2844 running, but then later the machine reboots and the process is not
2845 automatically restarted.
2847 If you'd like to have the administrator of the buildslave (or other
2848 people) be notified by email when the buildslave has been missing for
2849 too long, just add the @code{notify_on_missing=} argument to the
2850 @code{BuildSlave} definition:
2852 @example
2853 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2854                           notify_on_missing="bob@@example.com"),
2855               ]
2856 @end example
2858 By default, this will send email when the buildslave has been
2859 disconnected for more than one hour. Only one email per
2860 connection-loss event will be sent. To change the timeout, use
2861 @code{missing_timeout=} and give it a number of seconds (the default
2862 is 3600).
2864 You can have the buildmaster send email to multiple recipients: just
2865 provide a list of addresses instead of a single one:
2867 @example
2868 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2869                           notify_on_missing=["bob@@example.com",
2870                                              "alice@@example.org"],
2871                           missing_timeout=300, # notify after 5 minutes
2872                           ),
2873               ]
2874 @end example
2876 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2877 status target, if one is configured. This provides a way for you to
2878 control the ``from'' address of the email, as well as the relayhost
2879 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2880 configured on this buildmaster, the buildslave-missing emails will be
2881 sent using a default configuration.
2883 Note that if you want to have a MailNotifier for buildslave-missing
2884 emails but not for regular build emails, just create one with
2885 builders=[], as follows:
2887 @example
2888 from buildbot.status import mail
2889 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2890                       relayhost="smtp.example.org")
2891 c['status'].append(m)
2892 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2893                           notify_on_missing="bob@@example.com"),
2894               ]
2895 @end example
2897 @node On-Demand ("Latent") Buildslaves, Defining Global Properties, Buildslave Specifiers, Configuration
2898 @section On-Demand ("Latent") Buildslaves
2900 The standard buildbot model has slaves started manually.  The previous section
2901 described how to configure the master for this approach.
2903 Another approach is to let the buildbot master start slaves when builds are
2904 ready, on-demand.  Thanks to services such as Amazon Web Services' Elastic
2905 Compute Cloud ("AWS EC2"), this is relatively easy to set up, and can be
2906 very useful for some situations.
2908 The buildslaves that are started on-demand are called "latent" buildslaves.
2909 As of this writing, buildbot ships with an abstract base class for building
2910 latent buildslaves, and a concrete implementation for AWS EC2.
2912 @menu
2913 * Amazon Web Services Elastic Compute Cloud ("AWS EC2")::
2914 * Dangers with Latent Buildslaves::
2915 * Writing New Latent Buildslaves::
2916 @end menu
2918 @node Amazon Web Services Elastic Compute Cloud ("AWS EC2"), Dangers with Latent Buildslaves, , On-Demand ("Latent") Buildslaves
2919 @subsection Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2921 @url{http://aws.amazon.com/ec2/,,AWS EC2} is a web service that allows you to
2922 start virtual machines in an Amazon data center. Please see their website for
2923 details, incuding costs. Using the AWS EC2 latent buildslaves involves getting
2924 an EC2 account with AWS and setting up payment; customizing one or more EC2
2925 machine images ("AMIs") on your desired operating system(s) and publishing
2926 them (privately if needed); and configuring the buildbot master to know how to
2927 start your customized images for "substantiating" your latent slaves.
2929 @menu
2930 * Get an AWS EC2 Account::
2931 * Create an AMI::
2932 * Configure the Master with an EC2LatentBuildSlave::
2933 @end menu
2935 @node Get an AWS EC2 Account, Create an AMI, , Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2936 @subsubsection Get an AWS EC2 Account
2938 To start off, to use the AWS EC2 latent buildslave, you need to get an AWS
2939 developer account and sign up for EC2. These instructions may help you get
2940 started:
2942 @itemize @bullet
2943 @item
2944 Go to http://aws.amazon.com/ and click to "Sign Up Now" for an AWS account.
2946 @item
2947 Once you are logged into your account, you need to sign up for EC2.
2948 Instructions for how to do this have changed over time because Amazon changes
2949 their website, so the best advice is to hunt for it. After signing up for EC2,
2950 it may say it wants you to upload an x.509 cert. You will need this to create
2951 images (see below) but it is not technically necessary for the buildbot master
2952 configuration.
2954 @item
2955 You must enter a valid credit card before you will be able to use EC2. Do that
2956 under 'Payment Method'.
2958 @item
2959 Make sure you're signed up for EC2 by going to 'Your Account'->'Account
2960 Activity' and verifying EC2 is listed.
2961 @end itemize
2963 @node Create an AMI, Configure the Master with an EC2LatentBuildSlave, Get an AWS EC2 Account, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2964 @subsubsection Create an AMI
2966 Now you need to create an AMI and configure the master.  You may need to
2967 run through this cycle a few times to get it working, but these instructions
2968 should get you started.
2970 Creating an AMI is out of the scope of this document.  The
2971 @url{http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/,,EC2 Getting Started Guide}
2972 is a good resource for this task.  Here are a few additional hints.
2974 @itemize @bullet
2975 @item
2976 When an instance of the image starts, it needs to automatically start a
2977 buildbot slave that connects to your master (to create a buildbot slave,
2978 @pxref{Creating a buildslave}; to make a daemon,
2979 @pxref{Launching the daemons}).
2981 @item
2982 You may want to make an instance of the buildbot slave, configure it as a
2983 standard buildslave in the master (i.e., not as a latent slave), and test and
2984 debug it that way before you turn it into an AMI and convert to a latent
2985 slave in the master.
2986 @end itemize
2988 @node Configure the Master with an EC2LatentBuildSlave, , Create an AMI, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2989 @subsubsection Configure the Master with an EC2LatentBuildSlave
2991 Now let's assume you have an AMI that should work with the
2992 EC2LatentBuildSlave.  It's now time to set up your buildbot master
2993 configuration.
2995 You will need some information from your AWS account: the "Access Key Id" and
2996 the "Secret Access Key".  If you've built the AMI yourself, you probably
2997 already are familiar with these values.  If you have not, and someone has
2998 given you access to an AMI, these hints may help you find the necessary
2999 values:
3001 @itemize @bullet
3002 @item
3003 While logged into your AWS account, find the "Access Identifiers" link (either
3004 on the left, or via "Your Account" -> "Access Identifiers".
3006 @item
3007 On the page, you'll see alphanumeric values for "Your Access Key Id:" and
3008 "Your Secret Access Key:". Make a note of these. Later on, we'll call the
3009 first one your "identifier" and the second one your "secret_identifier."
3010 @end itemize
3012 When creating an EC2LatentBuildSlave in the buildbot master configuration,
3013 the first three arguments are required.  The name and password are the first
3014 two arguments, and work the same as with normal buildslaves.  The next
3015 argument specifies the type of the EC2 virtual machine (available options as
3016 of this writing include "m1.small", "m1.large", 'm1.xlarge", "c1.medium",
3017 and "c1.xlarge"; see the EC2 documentation for descriptions of these
3018 machines).
3020 Here is the simplest example of configuring an EC2 latent buildslave. It
3021 specifies all necessary remaining values explicitly in the instantiation.
3023 @example
3024 from buildbot.ec2buildslave import EC2LatentBuildSlave
3025 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3026                                    ami='ami-12345',
3027                                    identifier='publickey',
3028                                    secret_identifier='privatekey'
3029                                    )]
3030 @end example
3032 The "ami" argument specifies the AMI that the master should start.  The
3033 "identifier" argument specifies the AWS "Access Key Id," and the
3034 "secret_identifier" specifies the AWS "Secret Access Key." Both the AMI and
3035 the account information can be specified in alternate ways.
3037 Note that whoever has your identifier and secret_identifier values can request
3038 AWS work charged to your account, so these values need to be carefully
3039 protected. Another way to specify these access keys is to put them in a
3040 separate file. You can then make the access privileges stricter for this
3041 separate file, and potentially let more people read your main configuration
3042 file.
3044 By default, you can make an .ec2 directory in the home folder of the user
3045 running the buildbot master. In that directory, create a file called aws_id.
3046 The first line of that file should be your access key id; the second line
3047 should be your secret access key id. Then you can instantiate the build slave
3048 as follows.
3050 @example
3051 from buildbot.ec2buildslave import EC2LatentBuildSlave
3052 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3053                                    ami='ami-12345')]
3054 @end example
3056 If you want to put the key information in another file, use the
3057 "aws_id_file_path" initialization argument.
3059 Previous examples used a particular AMI.  If the Buildbot master will be
3060 deployed in a process-controlled environment, it may be convenient to
3061 specify the AMI more flexibly.  Rather than specifying an individual AMI,
3062 specify one or two AMI filters.
3064 In all cases, the AMI that sorts last by its location (the S3 bucket and
3065 manifest name) will be preferred.
3067 One available filter is to specify the acceptable AMI owners, by AWS account
3068 number (the 12 digit number, usually rendered in AWS with hyphens like
3069 "1234-5678-9012", should be entered as in integer).
3071 @example
3072 from buildbot.ec2buildslave import EC2LatentBuildSlave
3073 bot1 = EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3074                            valid_ami_owners=[11111111111,
3075                                              22222222222],
3076                            identifier='publickey',
3077                            secret_identifier='privatekey'
3078                            )
3079 @end example
3081 The other available filter is to provide a regular expression string that
3082 will be matched against each AMI's location (the S3 bucket and manifest name).
3084 @example
3085 from buildbot.ec2buildslave import EC2LatentBuildSlave
3086 bot1 = EC2LatentBuildSlave(
3087     'bot1', 'sekrit', 'm1.large',
3088     valid_ami_location_regex=r'buildbot\-.*/image.manifest.xml',
3089     identifier='publickey', secret_identifier='privatekey')
3090 @end example
3092 The regular expression can specify a group, which will be preferred for the
3093 sorting.  Only the first group is used; subsequent groups are ignored.
3095 @example
3096 from buildbot.ec2buildslave import EC2LatentBuildSlave
3097 bot1 = EC2LatentBuildSlave(
3098     'bot1', 'sekrit', 'm1.large',
3099     valid_ami_location_regex=r'buildbot\-.*\-(.*)/image.manifest.xml',
3100     identifier='publickey', secret_identifier='privatekey')
3101 @end example
3103 If the group can be cast to an integer, it will be.  This allows 10 to sort
3104 after 1, for instance.
3106 @example
3107 from buildbot.ec2buildslave import EC2LatentBuildSlave
3108 bot1 = EC2LatentBuildSlave(
3109     'bot1', 'sekrit', 'm1.large',
3110     valid_ami_location_regex=r'buildbot\-.*\-(\d+)/image.manifest.xml',
3111     identifier='publickey', secret_identifier='privatekey')
3112 @end example
3114 In addition to using the password as a handshake between the master and the
3115 slave, you may want to use a firewall to assert that only machines from a
3116 specific IP can connect as slaves.  This is possible with AWS EC2 by using
3117 the Elastic IP feature.  To configure, generate a Elastic IP in AWS, and then
3118 specify it in your configuration using the "elastic_ip" argument.
3120 @example
3121 from buildbot.ec2buildslave import EC2LatentBuildSlave
3122 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3123                                    'ami-12345',
3124                                    identifier='publickey',
3125                                    secret_identifier='privatekey',
3126                                    elastic_ip='208.77.188.166'
3127                                    )]
3128 @end example
3130 The EC2LatentBuildSlave supports all other configuration from the standard
3131 BuildSlave.  The "missing_timeout" and "notify_on_missing" specify how long
3132 to wait for an EC2 instance to attach before considering the attempt to have
3133 failed, and email addresses to alert, respectively.  "missing_timeout"
3134 defaults to 20 minutes.
3136 The "build_wait_timeout" allows you to specify how long an EC2LatentBuildSlave
3137 should wait after a build for another build before it shuts down the EC2
3138 instance.  It defaults to 10 minutes.
3140 "keypair_name" and "security_name" allow you to specify different names for
3141 these AWS EC2 values.  They both default to "latent_buildbot_slave".
3143 @node Dangers with Latent Buildslaves, Writing New Latent Buildslaves, Amazon Web Services Elastic Compute Cloud ("AWS EC2"), On-Demand ("Latent") Buildslaves
3144 @subsection Dangers with Latent Buildslaves
3146 Any latent build slave that interacts with a for-fee service, such as the
3147 EC2LatentBuildSlave, brings significant risks. As already identified, the
3148 configuraton will need access to account information that, if obtained by a
3149 criminal, can be used to charge services to your account. Also, bugs in the
3150 buildbot software may lead to unnecessary charges. In particular, if the
3151 master neglects to shut down an instance for some reason, a virtual machine
3152 may be running unnecessarily, charging against your account. Manual and/or
3153 automatic (e.g. nagios with a plugin using a library like boto)
3154 double-checking may be appropriate.
3156 A comparitively trivial note is that currently if two instances try to attach
3157 to the same latent buildslave, it is likely that the system will become
3158 confused.  This should not occur, unless, for instance, you configure a normal
3159 build slave to connect with the authentication of a latent buildbot.  If the
3160 situation occurs, stop all attached instances and restart the master.
3162 @node Writing New Latent Buildslaves, , Dangers with Latent Buildslaves, On-Demand ("Latent") Buildslaves
3163 @subsection Writing New Latent Buildslaves
3165 Writing a new latent buildslave should only require subclassing
3166 @code{buildbot.buildslave.AbstractLatentBuildSlave} and implementing
3167 start_instance and stop_instance.
3169 @example
3170 def start_instance(self):
3171     # responsible for starting instance that will try to connect with this
3172     # master. Should return deferred. Problems should use an errback. The
3173     # callback value can be None, or can be an iterable of short strings to
3174     # include in the "substantiate success" status message, such as
3175     # identifying the instance that started.
3176     raise NotImplementedError
3178 def stop_instance(self, fast=False):
3179     # responsible for shutting down instance. Return a deferred. If `fast`,
3180     # we're trying to shut the master down, so callback as soon as is safe.
3181     # Callback value is ignored.
3182     raise NotImplementedError
3183 @end example
3185 See @code{buildbot.ec2buildslave.EC2LatentBuildSlave} for an example, or see the
3186 test example @code{buildbot.test_slaves.FakeLatentBuildSlave}.
3188 @node Defining Global Properties, Defining Builders, On-Demand ("Latent") Buildslaves, Configuration
3189 @section Defining Global Properties
3190 @bcindex c['properties']
3191 @cindex Properties
3193 The @code{'properties'} configuration key defines a dictionary
3194 of properties that will be available to all builds started by the
3195 buildmaster:
3197 @example
3198 c['properties'] = @{
3199     'Widget-version' : '1.2',
3200     'release-stage' : 'alpha'
3202 @end example
3204 @node Defining Builders, Defining Status Targets, Defining Global Properties, Configuration
3205 @section Defining Builders
3207 @bcindex c['builders']
3209 The @code{c['builders']} key is a list of dictionaries which specify
3210 the Builders. The Buildmaster runs a collection of Builders, each of
3211 which handles a single type of build (e.g. full versus quick), on a
3212 single build slave. A Buildbot which makes sure that the latest code
3213 (``HEAD'') compiles correctly across four separate architecture will
3214 have four Builders, each performing the same build but on different
3215 slaves (one per platform).
3217 Each Builder gets a separate column in the waterfall display. In
3218 general, each Builder runs independently (although various kinds of
3219 interlocks can cause one Builder to have an effect on another).
3221 Each Builder specification dictionary has several required keys:
3223 @table @code
3224 @item name
3225 This specifies the Builder's name, which is used in status
3226 reports.
3228 @item slavename
3229 This specifies which buildslave will be used by this Builder.
3230 @code{slavename} must appear in the @code{c['slaves']} list. Each
3231 buildslave can accomodate multiple Builders.
3233 @item slavenames
3234 If you provide @code{slavenames} instead of @code{slavename}, you can
3235 give a list of buildslaves which are capable of running this Builder.
3236 If multiple buildslaves are available for any given Builder, you will
3237 have some measure of redundancy: in case one slave goes offline, the
3238 others can still keep the Builder working. In addition, multiple
3239 buildslaves will allow multiple simultaneous builds for the same
3240 Builder, which might be useful if you have a lot of forced or ``try''
3241 builds taking place.
3243 If you use this feature, it is important to make sure that the
3244 buildslaves are all, in fact, capable of running the given build. The
3245 slave hosts should be configured similarly, otherwise you will spend a
3246 lot of time trying (unsuccessfully) to reproduce a failure that only
3247 occurs on some of the buildslaves and not the others. Different
3248 platforms, operating systems, versions of major programs or libraries,
3249 all these things mean you should use separate Builders.
3251 @item builddir
3252 This specifies the name of a subdirectory (under the base directory)
3253 in which everything related to this builder will be placed. On the
3254 buildmaster, this holds build status information. On the buildslave,
3255 this is where checkouts, compiles, and tests are run.
3257 @item factory
3258 This is a @code{buildbot.process.factory.BuildFactory} instance which
3259 controls how the build is performed. Full details appear in their own
3260 chapter, @xref{Build Process}. Parameters like the location of the CVS
3261 repository and the compile-time options used for the build are
3262 generally provided as arguments to the factory's constructor.
3264 @end table
3266 Other optional keys may be set on each Builder:
3268 @table @code
3270 @item category
3271 If provided, this is a string that identifies a category for the
3272 builder to be a part of. Status clients can limit themselves to a
3273 subset of the available categories. A common use for this is to add
3274 new builders to your setup (for a new module, or for a new buildslave)
3275 that do not work correctly yet and allow you to integrate them with
3276 the active builders. You can put these new builders in a test
3277 category, make your main status clients ignore them, and have only
3278 private status clients pick them up. As soon as they work, you can
3279 move them over to the active category.
3281 @end table
3284 @node Defining Status Targets, Debug options, Defining Builders, Configuration
3285 @section Defining Status Targets
3287 The Buildmaster has a variety of ways to present build status to
3288 various users. Each such delivery method is a ``Status Target'' object
3289 in the configuration's @code{status} list. To add status targets, you
3290 just append more objects to this list:
3292 @bcindex c['status']
3294 @example
3295 c['status'] = []
3297 from buildbot.status import html
3298 c['status'].append(html.Waterfall(http_port=8010))
3300 from buildbot.status import mail
3301 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
3302                       extraRecipients=["builds@@lists.example.com"],
3303                       sendToInterestedUsers=False)
3304 c['status'].append(m)
3306 from buildbot.status import words
3307 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
3308                              channels=["#example"]))
3309 @end example
3311 Status delivery has its own chapter, @xref{Status Delivery}, in which
3312 all the built-in status targets are documented.
3315 @node Debug options,  , Defining Status Targets, Configuration
3316 @section Debug options
3319 @bcindex c['debugPassword']
3320 If you set @code{c['debugPassword']}, then you can connect to the
3321 buildmaster with the diagnostic tool launched by @code{buildbot
3322 debugclient MASTER:PORT}. From this tool, you can reload the config
3323 file, manually force builds, and inject changes, which may be useful
3324 for testing your buildmaster without actually commiting changes to
3325 your repository (or before you have the Change Sources set up). The
3326 debug tool uses the same port number as the slaves do:
3327 @code{c['slavePortnum']}, and is authenticated with this password.
3329 @example
3330 c['debugPassword'] = "debugpassword"
3331 @end example
3333 @bcindex c['manhole']
3334 If you set @code{c['manhole']} to an instance of one of the classes in
3335 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
3336 and get an interactive Python shell, which may be useful for debugging
3337 buildbot internals. It is probably only useful for buildbot
3338 developers. It exposes full access to the buildmaster's account
3339 (including the ability to modify and delete files), so it should not
3340 be enabled with a weak or easily guessable password.
3342 There are three separate @code{Manhole} classes. Two of them use SSH,
3343 one uses unencrypted telnet. Two of them use a username+password
3344 combination to grant access, one of them uses an SSH-style
3345 @file{authorized_keys} file which contains a list of ssh public keys.
3347 @table @code
3348 @item manhole.AuthorizedKeysManhole
3349 You construct this with the name of a file that contains one SSH
3350 public key per line, just like @file{~/.ssh/authorized_keys}. If you
3351 provide a non-absolute filename, it will be interpreted relative to
3352 the buildmaster's base directory.
3354 @item manhole.PasswordManhole
3355 This one accepts SSH connections but asks for a username and password
3356 when authenticating. It accepts only one such pair.
3359 @item manhole.TelnetManhole
3360 This accepts regular unencrypted telnet connections, and asks for a
3361 username/password pair before providing access. Because this
3362 username/password is transmitted in the clear, and because Manhole
3363 access to the buildmaster is equivalent to granting full shell
3364 privileges to both the buildmaster and all the buildslaves (and to all
3365 accounts which then run code produced by the buildslaves), it is
3366 highly recommended that you use one of the SSH manholes instead.
3368 @end table
3370 @example
3371 # some examples:
3372 from buildbot import manhole
3373 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
3374 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
3375 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
3376 @end example
3378 The @code{Manhole} instance can be configured to listen on a specific
3379 port. You may wish to have this listening port bind to the loopback
3380 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
3381 restrict access to clients which are running on the same host.
3383 @example
3384 from buildbot.manhole import PasswordManhole
3385 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
3386 @end example
3388 To have the @code{Manhole} listen on all interfaces, use
3389 @code{"tcp:9999"} or simply 9999. This port specification uses
3390 @code{twisted.application.strports}, so you can make it listen on SSL
3391 or even UNIX-domain sockets if you want.
3393 Note that using any Manhole requires that the TwistedConch package be
3394 installed, and that you be using Twisted version 2.0 or later.
3396 The buildmaster's SSH server will use a different host key than the
3397 normal sshd running on a typical unix host. This will cause the ssh
3398 client to complain about a ``host key mismatch'', because it does not
3399 realize there are two separate servers running on the same host. To
3400 avoid this, use a clause like the following in your @file{.ssh/config}
3401 file:
3403 @example
3404 Host remotehost-buildbot
3405  HostName remotehost
3406  HostKeyAlias remotehost-buildbot
3407  Port 9999
3408  # use 'user' if you use PasswordManhole and your name is not 'admin'.
3409  # if you use AuthorizedKeysManhole, this probably doesn't matter.
3410  User admin
3411 @end example
3414 @node Getting Source Code Changes, Build Process, Configuration, Top
3415 @chapter Getting Source Code Changes
3417 The most common way to use the Buildbot is centered around the idea of
3418 @code{Source Trees}: a directory tree filled with source code of some form
3419 which can be compiled and/or tested. Some projects use languages that don't
3420 involve any compilation step: nevertheless there may be a @code{build} phase
3421 where files are copied or rearranged into a form that is suitable for
3422 installation. Some projects do not have unit tests, and the Buildbot is
3423 merely helping to make sure that the sources can compile correctly. But in
3424 all of these cases, the thing-being-tested is a single source tree.
3426 A Version Control System mantains a source tree, and tells the
3427 buildmaster when it changes. The first step of each Build is typically
3428 to acquire a copy of some version of this tree.
3430 This chapter describes how the Buildbot learns about what Changes have
3431 occurred. For more information on VC systems and Changes, see
3432 @ref{Version Control Systems}.
3435 @menu
3436 * Change Sources::
3437 * Choosing ChangeSources::
3438 * CVSToys - PBService::
3439 * Mail-parsing ChangeSources::
3440 * PBChangeSource::
3441 * P4Source::
3442 * BonsaiPoller::
3443 * SVNPoller::
3444 * MercurialHook::
3445 * Bzr Hook::
3446 * Bzr Poller::
3447 @end menu
3451 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
3452 @section Change Sources
3454 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
3455 @c so narrow-minded anymore
3457 Each Buildmaster watches a single source tree. Changes can be provided
3458 by a variety of ChangeSource types, however any given project will
3459 typically have only a single ChangeSource active. This section
3460 provides a description of all available ChangeSource types and
3461 explains how to set up each of them.
3463 There are a variety of ChangeSources available, some of which are
3464 meant to be used in conjunction with other tools to deliver Change
3465 events from the VC repository to the buildmaster.
3467 @itemize @bullet
3469 @item CVSToys
3470 This ChangeSource opens a TCP connection from the buildmaster to a
3471 waiting FreshCVS daemon that lives on the repository machine, and
3472 subscribes to hear about Changes.
3474 @item MaildirSource
3475 This one watches a local maildir-format inbox for email sent out by
3476 the repository when a change is made. When a message arrives, it is
3477 parsed to create the Change object. A variety of parsing functions are
3478 available to accomodate different email-sending tools.
3480 @item PBChangeSource
3481 This ChangeSource listens on a local TCP socket for inbound
3482 connections from a separate tool. Usually, this tool would be run on
3483 the VC repository machine in a commit hook. It is expected to connect
3484 to the TCP socket and send a Change message over the network
3485 connection. The @command{buildbot sendchange} command is one example
3486 of a tool that knows how to send these messages, so you can write a
3487 commit script for your VC system that calls it to deliver the Change.
3488 There are other tools in the contrib/ directory that use the same
3489 protocol.
3491 @end itemize
3493 As a quick guide, here is a list of VC systems and the ChangeSources
3494 that might be useful with them. All of these ChangeSources are in the
3495 @code{buildbot.changes} module.
3497 @table @code
3498 @item CVS
3500 @itemize @bullet
3501 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
3502 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
3503 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
3504 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
3505 @item pb.PBChangeSource (listening for connections from @code{buildbot
3506 sendchange} run in a loginfo script)
3507 @item pb.PBChangeSource (listening for connections from a long-running
3508 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
3509 database directly
3510 @end itemize
3512 @item SVN
3513 @itemize @bullet
3514 @item pb.PBChangeSource (listening for connections from
3515 @code{contrib/svn_buildbot.py} run in a postcommit script)
3516 @item pb.PBChangeSource (listening for connections from a long-running
3517 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
3518 process
3519 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
3520 @item svnpoller.SVNPoller (polling the SVN repository)
3521 @end itemize
3523 @item Darcs
3524 @itemize @bullet
3525 @item pb.PBChangeSource (listening for connections from
3526 @code{contrib/darcs_buildbot.py} in a commit script
3527 @end itemize
3529 @item Mercurial
3530 @itemize @bullet
3531 @item pb.PBChangeSource (listening for connections from
3532 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
3533 @item pb.PBChangeSource (listening for connections from
3534 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
3535 hook)
3536 @end itemize
3538 @item Arch/Bazaar
3539 @itemize @bullet
3540 @item pb.PBChangeSource (listening for connections from
3541 @code{contrib/arch_buildbot.py} run in a commit hook)
3542 @end itemize
3544 @item Bzr (the newer Bazaar)
3545 @itemize @bullet
3546 @item pb.PBChangeSource (listening for connections from
3547 @code{contrib/bzr_buildbot.py} run in a post-change-branch-tip or commit hook)
3548 @item @code{contrib/bzr_buildbot.py}'s BzrPoller (polling the Bzr repository)
3549 @end itemize
3551 @item Git
3552 @itemize @bullet
3553 @item pb.PBChangeSource (listening for connections from
3554 @code{contrib/git_buildbot.py} run in the post-receive hook)
3555 @end itemize
3557 @end table
3559 All VC systems can be driven by a PBChangeSource and the
3560 @code{buildbot sendchange} tool run from some form of commit script.
3561 If you write an email parsing function, they can also all be driven by
3562 a suitable @code{MaildirSource}.
3565 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
3566 @section Choosing ChangeSources
3568 The @code{master.cfg} configuration file has a dictionary key named
3569 @code{BuildmasterConfig['change_source']}, which holds the active
3570 @code{IChangeSource} object. The config file will typically create an
3571 object from one of the classes described below and stuff it into this
3572 key.
3574 Each buildmaster typically has just a single ChangeSource, since it is
3575 only watching a single source tree. But if, for some reason, you need
3576 multiple sources, just set @code{c['change_source']} to a list of
3577 ChangeSources.. it will accept that too.
3579 @example
3580 s = FreshCVSSourceNewcred(host="host", port=4519,
3581                           user="alice", passwd="secret",
3582                           prefix="Twisted")
3583 BuildmasterConfig['change_source'] = [s]
3584 @end example
3586 Each source tree has a nominal @code{top}. Each Change has a list of
3587 filenames, which are all relative to this top location. The
3588 ChangeSource is responsible for doing whatever is necessary to
3589 accomplish this. Most sources have a @code{prefix} argument: a partial
3590 pathname which is stripped from the front of all filenames provided to
3591 that @code{ChangeSource}. Files which are outside this sub-tree are
3592 ignored by the changesource: it does not generate Changes for those
3593 files.
3596 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
3597 @section CVSToys - PBService
3599 @csindex buildbot.changes.freshcvs.FreshCVSSource
3601 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
3602 server which runs on the machine that hosts the CVS repository it
3603 watches. It has a variety of ways to distribute commit notifications,
3604 and offers a flexible regexp-based way to filter out uninteresting
3605 changes. One of the notification options is named @code{PBService} and
3606 works by listening on a TCP port for clients. These clients subscribe
3607 to hear about commit notifications.
3609 The buildmaster has a CVSToys-compatible @code{PBService} client built
3610 in. There are two versions of it, one for old versions of CVSToys
3611 (1.0.9 and earlier) which used the @code{oldcred} authentication
3612 framework, and one for newer versions (1.0.10 and later) which use
3613 @code{newcred}. Both are classes in the
3614 @code{buildbot.changes.freshcvs} package.
3616 @code{FreshCVSSourceNewcred} objects are created with the following
3617 parameters:
3619 @table @samp
3621 @item @code{host} and @code{port}
3622 these specify where the CVSToys server can be reached
3624 @item @code{user} and @code{passwd}
3625 these specify the login information for the CVSToys server
3626 (@code{freshcvs}). These must match the server's values, which are
3627 defined in the @code{freshCfg} configuration file (which lives in the
3628 CVSROOT directory of the repository).
3630 @item @code{prefix}
3631 this is the prefix to be found and stripped from filenames delivered
3632 by the CVSToys server. Most projects live in sub-directories of the
3633 main repository, as siblings of the CVSROOT sub-directory, so
3634 typically this prefix is set to that top sub-directory name.
3636 @end table
3638 @heading Example
3640 To set up the freshCVS server, add a statement like the following to
3641 your @file{freshCfg} file:
3643 @example
3644 pb = ConfigurationSet([
3645     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
3646     ])
3647 @end example
3649 This will announce all changes to a client which connects to port 4519
3650 using a username of 'foo' and a password of 'bar'.
3652 Then add a clause like this to your buildmaster's @file{master.cfg}:
3654 @example
3655 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
3656                                                     "foo", "bar",
3657                                                     prefix="glib/")
3658 @end example
3660 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
3661 "glib" is the top-level directory (relative to the repository's root) where
3662 all your source code lives. Most projects keep one or more projects in the
3663 same repository (along with CVSROOT/ to hold admin files like loginfo and
3664 freshCfg); the prefix= argument tells the buildmaster to ignore everything
3665 outside that directory, and to strip that common prefix from all pathnames
3666 it handles.
3669 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
3670 @section Mail-parsing ChangeSources
3672 Many projects publish information about changes to their source tree
3673 by sending an email message out to a mailing list, frequently named
3674 PROJECT-commits or PROJECT-changes. Each message usually contains a
3675 description of the change (who made the change, which files were
3676 affected) and sometimes a copy of the diff. Humans can subscribe to
3677 this list to stay informed about what's happening to the source tree.
3679 The Buildbot can also be subscribed to a -commits mailing list, and
3680 can trigger builds in response to Changes that it hears about. The
3681 buildmaster admin needs to arrange for these email messages to arrive
3682 in a place where the buildmaster can find them, and configure the
3683 buildmaster to parse the messages correctly. Once that is in place,
3684 the email parser will create Change objects and deliver them to the
3685 Schedulers (see @pxref{Change Sources and Schedulers}) just
3686 like any other ChangeSource.
3688 There are two components to setting up an email-based ChangeSource.
3689 The first is to route the email messages to the buildmaster, which is
3690 done by dropping them into a ``maildir''. The second is to actually
3691 parse the messages, which is highly dependent upon the tool that was
3692 used to create them. Each VC system has a collection of favorite
3693 change-emailing tools, and each has a slightly different format, so
3694 each has a different parsing function. There is a separate
3695 ChangeSource variant for each parsing function.
3697 Once you've chosen a maildir location and a parsing function, create
3698 the change source and put it in @code{c['change_source']}:
3700 @example
3701 from buildbot.changes.mail import SyncmailMaildirSource
3702 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
3703                                            prefix="/trunk/")
3704 @end example
3706 @menu
3707 * Subscribing the Buildmaster::
3708 * Using Maildirs::
3709 * Parsing Email Change Messages::
3710 @end menu
3712 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
3713 @subsection Subscribing the Buildmaster
3715 The recommended way to install the buildbot is to create a dedicated
3716 account for the buildmaster. If you do this, the account will probably
3717 have a distinct email address (perhaps
3718 @email{buildmaster@@example.org}). Then just arrange for this
3719 account's email to be delivered to a suitable maildir (described in
3720 the next section).
3722 If the buildbot does not have its own account, ``extension addresses''
3723 can be used to distinguish between email intended for the buildmaster
3724 and email intended for the rest of the account. In most modern MTAs,
3725 the e.g. @code{foo@@example.org} account has control over every email
3726 address at example.org which begins with "foo", such that email
3727 addressed to @email{account-foo@@example.org} can be delivered to a
3728 different destination than @email{account-bar@@example.org}. qmail
3729 does this by using separate .qmail files for the two destinations
3730 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
3731 controlling the base address and @file{.qmail-default} controlling all
3732 other extensions). Other MTAs have similar mechanisms.
3734 Thus you can assign an extension address like
3735 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
3736 @email{foo@@example.org} for your own use.
3739 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
3740 @subsection Using Maildirs
3742 A ``maildir'' is a simple directory structure originally developed for
3743 qmail that allows safe atomic update without locking. Create a base
3744 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
3745 When messages arrive, they are put into a uniquely-named file (using
3746 pids, timestamps, and random numbers) in ``tmp''. When the file is
3747 complete, it is atomically renamed into ``new''. Eventually the
3748 buildmaster notices the file in ``new'', reads and parses the
3749 contents, then moves it into ``cur''. A cronjob can be used to delete
3750 files in ``cur'' at leisure.
3752 Maildirs are frequently created with the @command{maildirmake} tool,
3753 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
3754 equivalent.
3756 Many modern MTAs can deliver directly to maildirs. The usual .forward
3757 or .procmailrc syntax is to name the base directory with a trailing
3758 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
3759 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
3760 Delivery Agent).
3762 For MTAs which cannot put files into maildirs directly, the
3763 ``safecat'' tool can be executed from a .forward file to accomplish
3764 the same thing.
3766 The Buildmaster uses the linux DNotify facility to receive immediate
3767 notification when the maildir's ``new'' directory has changed. When
3768 this facility is not available, it polls the directory for new
3769 messages, every 10 seconds by default.
3771 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
3772 @subsection Parsing Email Change Messages
3774 The second component to setting up an email-based ChangeSource is to
3775 parse the actual notices. This is highly dependent upon the VC system
3776 and commit script in use.
3778 A couple of common tools used to create these change emails are:
3780 @table @samp
3782 @item CVS
3783 @table @samp
3784 @item CVSToys MailNotifier
3785 @ref{FCMaildirSource}
3786 @item Bonsai notification
3787 @ref{BonsaiMaildirSource}
3788 @item syncmail
3789 @ref{SyncmailMaildirSource}
3790 @end table
3792 @item SVN
3793 @table @samp
3794 @item svnmailer
3795 http://opensource.perlig.de/en/svnmailer/
3796 @item commit-email.pl
3797 @ref{SVNCommitEmailMaildirSource}
3798 @end table
3800 @item Mercurial
3801 @table @samp
3802 @item NotifyExtension
3803 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
3804 @end table
3806 @item Git
3807 @table @samp
3808 @item post-receive-email
3809 http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email;hb=HEAD
3810 @end table
3812 @end table
3815 The following sections describe the parsers available for each of
3816 these tools.
3818 Most of these parsers accept a @code{prefix=} argument, which is used
3819 to limit the set of files that the buildmaster pays attention to. This
3820 is most useful for systems like CVS and SVN which put multiple
3821 projects in a single repository (or use repository names to indicate
3822 branches). Each filename that appears in the email is tested against
3823 the prefix: if the filename does not start with the prefix, the file
3824 is ignored. If the filename @emph{does} start with the prefix, that
3825 prefix is stripped from the filename before any further processing is
3826 done. Thus the prefix usually ends with a slash.
3828 @menu
3829 * FCMaildirSource::
3830 * SyncmailMaildirSource::
3831 * BonsaiMaildirSource::
3832 * SVNCommitEmailMaildirSource::
3833 @end menu
3835 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
3836 @subsubsection FCMaildirSource
3839 @csindex buildbot.changes.mail.FCMaildirSource
3841 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
3843 This parser works with the CVSToys @code{MailNotification} action,
3844 which will send email to a list of recipients for each commit. This
3845 tends to work better than using @code{/bin/mail} from within the
3846 CVSROOT/loginfo file directly, as CVSToys will batch together all
3847 files changed during the same CVS invocation, and can provide more
3848 information (like creating a ViewCVS URL for each file changed).
3850 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3851 messages and turn them into Change objects. It can be given two
3852 parameters: the directory name of the maildir root, and the prefix to
3853 strip.
3855 @example
3856 from buildbot.changes.mail import FCMaildirSource
3857 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3858 @end example
3860 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3861 @subsubsection SyncmailMaildirSource
3863 @csindex buildbot.changes.mail.SyncmailMaildirSource
3865 http://sourceforge.net/projects/cvs-syncmail
3867 @code{SyncmailMaildirSource} knows how to parse the message format used by
3868 the CVS ``syncmail'' script.
3870 @example
3871 from buildbot.changes.mail import SyncmailMaildirSource
3872 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3873 @end example
3875 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3876 @subsubsection BonsaiMaildirSource
3878 @csindex buildbot.changes.mail.BonsaiMaildirSource
3880 http://www.mozilla.org/bonsai.html
3882 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3883 tree-management system built by Mozilla.
3885 @example
3886 from buildbot.changes.mail import BonsaiMaildirSource
3887 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3888 @end example
3890 @node SVNCommitEmailMaildirSource,  , BonsaiMaildirSource, Parsing Email Change Messages
3891 @subsubsection SVNCommitEmailMaildirSource
3893 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3895 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3896 @code{commit-email.pl} script, which is included in the Subversion
3897 distribution.
3899 It does not currently handle branches: all of the Change objects that
3900 it creates will be associated with the default (i.e. trunk) branch.
3902 @example
3903 from buildbot.changes.mail import SVNCommitEmailMaildirSource
3904 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
3905 @end example
3908 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
3909 @section PBChangeSource
3911 @csindex buildbot.changes.pb.PBChangeSource
3913 The last kind of ChangeSource actually listens on a TCP port for
3914 clients to connect and push change notices @emph{into} the
3915 Buildmaster. This is used by the built-in @code{buildbot sendchange}
3916 notification tool, as well as the VC-specific
3917 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
3918 @file{contrib/hg_buildbot.py} tools, and the
3919 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
3920 repository (in a commit hook script), and connect to the buildmaster
3921 directly each time a file is comitted. This is also useful for
3922 creating new kinds of change sources that work on a @code{push} model
3923 instead of some kind of subscription scheme, for example a script
3924 which is run out of an email .forward file.
3926 This ChangeSource can be configured to listen on its own TCP port, or
3927 it can share the port that the buildmaster is already using for the
3928 buildslaves to connect. (This is possible because the
3929 @code{PBChangeSource} uses the same protocol as the buildslaves, and
3930 they can be distinguished by the @code{username} attribute used when
3931 the initial connection is established). It might be useful to have it
3932 listen on a different port if, for example, you wanted to establish
3933 different firewall rules for that port. You could allow only the SVN
3934 repository machine access to the @code{PBChangeSource} port, while
3935 allowing only the buildslave machines access to the slave port. Or you
3936 could just expose one port and run everything over it. @emph{Note:
3937 this feature is not yet implemented, the PBChangeSource will always
3938 share the slave port and will always have a @code{user} name of
3939 @code{change}, and a passwd of @code{changepw}. These limitations will
3940 be removed in the future.}.
3943 The @code{PBChangeSource} is created with the following arguments. All
3944 are optional.
3946 @table @samp
3947 @item @code{port}
3948 which port to listen on. If @code{None} (which is the default), it
3949 shares the port used for buildslave connections. @emph{Not
3950 Implemented, always set to @code{None}}.
3952 @item @code{user} and @code{passwd}
3953 The user/passwd account information that the client program must use
3954 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
3955 Implemented, @code{user} is currently always set to @code{change},
3956 @code{passwd} is always set to @code{changepw}}.
3958 @item @code{prefix}
3959 The prefix to be found and stripped from filenames delivered over the
3960 connection. Any filenames which do not start with this prefix will be
3961 removed. If all the filenames in a given Change are removed, the that
3962 whole Change will be dropped. This string should probably end with a
3963 directory separator.
3965 This is useful for changes coming from version control systems that
3966 represent branches as parent directories within the repository (like
3967 SVN and Perforce). Use a prefix of 'trunk/' or
3968 'project/branches/foobranch/' to only follow one branch and to get
3969 correct tree-relative filenames. Without a prefix, the PBChangeSource
3970 will probably deliver Changes with filenames like @file{trunk/foo.c}
3971 instead of just @file{foo.c}. Of course this also depends upon the
3972 tool sending the Changes in (like @command{buildbot sendchange}) and
3973 what filenames it is delivering: that tool may be filtering and
3974 stripping prefixes at the sending end.
3976 @end table
3978 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
3979 @section P4Source
3981 @csindex buildbot.changes.p4poller.P4Source
3983 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
3984 Perforce} depot for changes. It accepts the following arguments:
3986 @table @samp
3987 @item @code{p4base}
3988 The base depot path to watch, without the trailing '/...'.
3990 @item @code{p4port}
3991 The Perforce server to connect to (as host:port).
3993 @item @code{p4user}
3994 The Perforce user.
3996 @item @code{p4passwd}
3997 The Perforce password.
3999 @item @code{p4bin}
4000 An optional string parameter. Specify the location of the perforce command 
4001 line binary (p4).  You only need to do this if the perforce binary is not 
4002 in the path of the buildbot user.  Defaults to ``p4''.
4004 @item @code{split_file}
4005 A function that maps a pathname, without the leading @code{p4base}, to a
4006 (branch, filename) tuple. The default just returns (None, branchfile),
4007 which effectively disables branch support. You should supply a function
4008 which understands your repository structure.
4010 @item @code{pollinterval}
4011 How often to poll, in seconds. Defaults to 600 (10 minutes).
4013 @item @code{histmax}
4014 The maximum number of changes to inspect at a time. If more than this
4015 number occur since the last poll, older changes will be silently
4016 ignored.
4017 @end table
4019 @heading Example
4021 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
4022 specified in the buildmaster's environment. It watches a project in which the
4023 branch name is simply the next path component, and the file is all path
4024 components after.
4026 @example
4027 import buildbot.changes.p4poller
4028 s = p4poller.P4Source(p4base='//depot/project/',
4029                       split_file=lambda branchfile: branchfile.split('/',1),
4030                      )
4031 c['change_source'] = s
4032 @end example
4034 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
4035 @section BonsaiPoller
4037 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
4039 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
4040 CGI script accessed through a web server that provides information
4041 about a CVS tree, for example the Mozilla bonsai server at
4042 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
4043 humans and machines. In this case, the buildbot's change source forms
4044 a query which asks about any files in the specified branch which have
4045 changed since the last query.
4047 Please take a look at the BonsaiPoller docstring for details about the
4048 arguments it accepts.
4051 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
4052 @section SVNPoller
4054 @csindex buildbot.changes.svnpoller.SVNPoller
4056 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
4057 which periodically polls a @uref{http://subversion.tigris.org/,
4058 Subversion} repository for new revisions, by running the @code{svn
4059 log} command in a subshell. It can watch a single branch or multiple
4060 branches.
4062 @code{SVNPoller} accepts the following arguments:
4064 @table @code
4065 @item svnurl
4066 The base URL path to watch, like
4067 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
4068 @code{http://divmod.org/svn/Divmod/}, or even
4069 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
4070 include the access scheme, the location of the repository (both the
4071 hostname for remote ones, and any additional directory names necessary
4072 to get to the repository), and the sub-path within the repository's
4073 virtual filesystem for the project and branch of interest.
4075 The @code{SVNPoller} will only pay attention to files inside the
4076 subdirectory specified by the complete svnurl.
4078 @item split_file
4079 A function to convert pathnames into (branch, relative_pathname)
4080 tuples. Use this to explain your repository's branch-naming policy to
4081 @code{SVNPoller}. This function must accept a single string and return
4082 a two-entry tuple. There are a few utility functions in
4083 @code{buildbot.changes.svnpoller} that can be used as a
4084 @code{split_file} function, see below for details.
4086 The default value always returns (None, path), which indicates that
4087 all files are on the trunk.
4089 Subclasses of @code{SVNPoller} can override the @code{split_file}
4090 method instead of using the @code{split_file=} argument.
4092 @item svnuser
4093 An optional string parameter. If set, the @code{--user} argument will
4094 be added to all @code{svn} commands. Use this if you have to
4095 authenticate to the svn server before you can do @code{svn info} or
4096 @code{svn log} commands.
4098 @item svnpasswd
4099 Like @code{svnuser}, this will cause a @code{--password} argument to
4100 be passed to all svn commands.
4102 @item pollinterval
4103 How often to poll, in seconds. Defaults to 600 (checking once every 10
4104 minutes). Lower this if you want the buildbot to notice changes
4105 faster, raise it if you want to reduce the network and CPU load on
4106 your svn server. Please be considerate of public SVN repositories by
4107 using a large interval when polling them.
4109 @item histmax
4110 The maximum number of changes to inspect at a time. Every POLLINTERVAL
4111 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
4112 looks through them for any ones it does not already know about. If
4113 more than HISTMAX revisions have been committed since the last poll,
4114 older changes will be silently ignored. Larger values of histmax will
4115 cause more time and memory to be consumed on each poll attempt.
4116 @code{histmax} defaults to 100.
4118 @item svnbin
4119 This controls the @code{svn} executable to use. If subversion is
4120 installed in a weird place on your system (outside of the
4121 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
4122 to find it. The default value of ``svn'' will almost always be
4123 sufficient.
4125 @end table
4127 @heading Branches
4129 Each source file that is tracked by a Subversion repository has a
4130 fully-qualified SVN URL in the following form:
4131 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
4132 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
4133 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
4134 string. The @code{SVNPoller} is responsible for producing Changes that
4135 contain a branch name and a FILEPATH (which is relative to the top of
4136 a checked-out tree). The details of how these strings are split up
4137 depend upon how your repository names its branches.
4139 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
4141 One common layout is to have all the various projects that share a
4142 repository get a single top-level directory each. Then under a given
4143 project's directory, you get two subdirectories, one named ``trunk''
4144 and another named ``branches''. Under ``branches'' you have a bunch of
4145 other directories, one per branch, with names like ``1.5.x'' and
4146 ``testing''. It is also common to see directories like ``tags'' and
4147 ``releases'' next to ``branches'' and ``trunk''.
4149 For example, the Twisted project has a subversion server on
4150 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
4151 repository is available through a SCHEME of ``svn:''. The primary
4152 sub-project is Twisted, of course, with a repository root of
4153 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
4154 Informant, with a root of
4155 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
4156 checked-out Twisted tree, there is a file named bin/trial (which is
4157 used to run unit test suites).
4159 The trunk for Twisted is in
4160 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
4161 fully-qualified SVN URL for the trunk version of @code{trial} would be
4162 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
4163 SVNURL for that file on a branch named ``1.5.x'' would be
4164 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
4166 To set up a @code{SVNPoller} that watches the Twisted trunk (and
4167 nothing else), we would use the following:
4169 @example
4170 from buildbot.changes.svnpoller import SVNPoller
4171 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
4172 @end example
4174 In this case, every Change that our @code{SVNPoller} produces will
4175 have @code{.branch=None}, to indicate that the Change is on the trunk.
4176 No other sub-projects or branches will be tracked.
4178 If we want our ChangeSource to follow multiple branches, we have to do
4179 two things. First we have to change our @code{svnurl=} argument to
4180 watch more than just ``.../Twisted/trunk''. We will set it to
4181 ``.../Twisted'' so that we'll see both the trunk and all the branches.
4182 Second, we have to tell @code{SVNPoller} how to split the
4183 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
4184 out into (BRANCH) and (FILEPATH) pairs.
4186 We do the latter by providing a ``split_file'' function. This function
4187 is responsible for splitting something like
4188 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
4189 @code{filepath}=''bin/trial''. This function is always given a string
4190 that names a file relative to the subdirectory pointed to by the
4191 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
4192 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
4193 branch indicated), or None to indicate that the file is outside any
4194 project of interest.
4196 (note that we want to see ``branches/1.5.x'' rather than just
4197 ``1.5.x'' because when we perform the SVN checkout, we will probably
4198 append the branch name to the baseURL, which requires that we keep the
4199 ``branches'' component in there. Other VC schemes use a different
4200 approach towards branches and may not require this artifact.)
4202 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
4203 scheme, the following function will work:
4205 @example
4206 def split_file_branches(path):
4207     pieces = path.split('/')
4208     if pieces[0] == 'trunk':
4209         return (None, '/'.join(pieces[1:]))
4210     elif pieces[0] == 'branches':
4211         return ('/'.join(pieces[0:2]),
4212                 '/'.join(pieces[2:]))
4213     else:
4214         return None
4215 @end example
4217 This function is provided as
4218 @code{buildbot.changes.svnpoller.split_file_branches} for your
4219 convenience. So to have our Twisted-watching @code{SVNPoller} follow
4220 multiple branches, we would use this:
4222 @example
4223 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
4224 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
4225                                split_file=split_file_branches)
4226 @end example
4228 Changes for all sorts of branches (with names like ``branches/1.5.x'',
4229 and None to indicate the trunk) will be delivered to the Schedulers.
4230 Each Scheduler is then free to use or ignore each branch as it sees
4231 fit.
4233 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
4235 Another common way to organize a Subversion repository is to put the
4236 branch name at the top, and the projects underneath. This is
4237 especially frequent when there are a number of related sub-projects
4238 that all get released in a group.
4240 For example, Divmod.org hosts a project named ``Nevow'' as well as one
4241 named ``Quotient''. In a checked-out Nevow tree there is a directory
4242 named ``formless'' that contains a python source file named
4243 ``webform.py''. This repository is accessible via webdav (and thus
4244 uses an ``http:'' scheme) through the divmod.org hostname. There are
4245 many branches in this repository, and they use a
4246 (BRANCHNAME)/(PROJECT) naming policy.
4248 The fully-qualified SVN URL for the trunk version of webform.py is
4249 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
4250 You can do an @code{svn co} with that URL and get a copy of the latest
4251 version. The 1.5.x branch version of this file would have a URL of
4252 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
4253 The whole Nevow trunk would be checked out with
4254 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
4255 trunk would be checked out using
4256 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
4258 Now suppose we want to have an @code{SVNPoller} that only cares about
4259 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
4260 described earlier:
4262 @example
4263 from buildbot.changes.svnpoller import SVNPoller
4264 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
4265 @end example
4267 But what happens when we want to track multiple Nevow branches? We
4268 have to point our @code{svnurl=} high enough to see all those
4269 branches, but we also don't want to include Quotient changes (since
4270 we're only building Nevow). To accomplish this, we must rely upon the
4271 @code{split_file} function to help us tell the difference between
4272 files that belong to Nevow and those that belong to Quotient, as well
4273 as figuring out which branch each one is on.
4275 @example
4276 from buildbot.changes.svnpoller import SVNPoller
4277 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
4278                                split_file=my_file_splitter)
4279 @end example
4281 The @code{my_file_splitter} function will be called with
4282 repository-relative pathnames like:
4284 @table @code
4285 @item trunk/Nevow/formless/webform.py
4286 This is a Nevow file, on the trunk. We want the Change that includes this
4287 to see a filename of @code{formless/webform.py"}, and a branch of None
4289 @item branches/1.5.x/Nevow/formless/webform.py
4290 This is a Nevow file, on a branch. We want to get
4291 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
4293 @item trunk/Quotient/setup.py
4294 This is a Quotient file, so we want to ignore it by having
4295 @code{my_file_splitter} return None.
4297 @item branches/1.5.x/Quotient/setup.py
4298 This is also a Quotient file, which should be ignored.
4299 @end table
4301 The following definition for @code{my_file_splitter} will do the job:
4303 @example
4304 def my_file_splitter(path):
4305     pieces = path.split('/')
4306     if pieces[0] == 'trunk':
4307         branch = None
4308         pieces.pop(0) # remove 'trunk'
4309     elif pieces[0] == 'branches':
4310         pieces.pop(0) # remove 'branches'
4311         # grab branch name
4312         branch = 'branches/' + pieces.pop(0)
4313     else:
4314         return None # something weird
4315     projectname = pieces.pop(0)
4316     if projectname != 'Nevow':
4317         return None # wrong project
4318     return (branch, '/'.join(pieces))
4319 @end example
4321 @node MercurialHook,  Bzr Hook, SVNPoller, Getting Source Code Changes
4322 @section MercurialHook
4324 Since Mercurial is written in python, the hook script can invoke
4325 Buildbot's @code{sendchange} function directly, rather than having to
4326 spawn an external process. This function delivers the same sort of
4327 changes as @code{buildbot sendchange} and the various hook scripts in
4328 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
4329 buildmaster to receive these changes.
4331 To set this up, first choose a Mercurial repository that represents
4332 your central ``official'' source tree. This will be the same
4333 repository that your buildslaves will eventually pull from. Install
4334 Buildbot on the machine that hosts this repository, using the same
4335 version of python as Mercurial is using (so that the Mercurial hook
4336 can import code from buildbot). Then add the following to the
4337 @code{.hg/hgrc} file in that repository, replacing the buildmaster
4338 hostname/portnumber as appropriate for your buildbot:
4340 @example
4341 [hooks]
4342 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
4344 [hgbuildbot]
4345 master = buildmaster.example.org:9987
4346 @end example
4348 (Note that Mercurial lets you define multiple @code{changegroup} hooks
4349 by giving them distinct names, like @code{changegroup.foo} and
4350 @code{changegroup.bar}, which is why we use
4351 @code{changegroup.buildbot} in this example. There is nothing magical
4352 about the ``buildbot'' suffix in the hook name. The
4353 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
4354 only section that the buildbot hook pays attention to.)
4356 Also note that this runs as a @code{changegroup} hook, rather than as
4357 an @code{incoming} hook. The @code{changegroup} hook is run with
4358 multiple revisions at a time (say, if multiple revisions are being
4359 pushed to this repository in a single @command{hg push} command),
4360 whereas the @code{incoming} hook is run with just one revision at a
4361 time. The @code{hgbuildbot.hook} function will only work with the
4362 @code{changegroup} hook.
4364 The @code{[hgbuildbot]} section has two other parameters that you
4365 might specify, both of which control the name of the branch that is
4366 attached to the changes coming from this hook.
4368 One common branch naming policy for Mercurial repositories is to use
4369 it just like Darcs: each branch goes into a separate repository, and
4370 all the branches for a single project share a common parent directory.
4371 For example, you might have @file{/var/repos/PROJECT/trunk/} and
4372 @file{/var/repos/PROJECT/release}. To use this style, use the
4373 @code{branchtype = dirname} setting, which simply uses the last
4374 component of the repository's enclosing directory as the branch name:
4376 @example
4377 [hgbuildbot]
4378 master = buildmaster.example.org:9987
4379 branchtype = dirname
4380 @end example
4382 Another approach is to use Mercurial's built-in branches (the kind
4383 created with @command{hg branch} and listed with @command{hg
4384 branches}). This feature associates persistent names with particular
4385 lines of descent within a single repository. (note that the buildbot
4386 @code{source.Mercurial} checkout step does not yet support this kind
4387 of branch). To have the commit hook deliver this sort of branch name
4388 with the Change object, use @code{branchtype = inrepo}:
4390 @example
4391 [hgbuildbot]
4392 master = buildmaster.example.org:9987
4393 branchtype = inrepo
4394 @end example
4396 Finally, if you want to simply specify the branchname directly, for
4397 all changes, use @code{branch = BRANCHNAME}. This overrides
4398 @code{branchtype}:
4400 @example
4401 [hgbuildbot]
4402 master = buildmaster.example.org:9987
4403 branch = trunk
4404 @end example
4406 If you use @code{branch=} like this, you'll need to put a separate
4407 .hgrc in each repository. If you use @code{branchtype=}, you may be
4408 able to use the same .hgrc for all your repositories, stored in
4409 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
4412 @node Bzr Hook, Bzr Poller, MercurialHook, Getting Source Code Changes
4413 @section Bzr Hook
4415 Bzr is also written in Python, and the Bzr hook depends on Twisted to send the
4416 changes.
4418 To install, put @code{contrib/bzr_buildbot.py} in one of your plugins
4419 locations a bzr plugins directory (e.g.,
4420 @code{~/.bazaar/plugins}). Then, in one of your bazaar conf files (e.g.,
4421 @code{~/.bazaar/locations.conf}), set the location you want to connect with buildbot
4422 with these keys:
4424 @table @code
4425 @item buildbot_on
4426 one of 'commit', 'push, or 'change'. Turns the plugin on to report changes via
4427 commit, changes via push, or any changes to the trunk. 'change' is
4428 recommended.
4430 @item buildbot_server
4431 (required to send to a buildbot master) the URL of the buildbot master to
4432 which you will connect (as of this writing, the same server and port to which
4433 slaves connect).
4435 @item buildbot_port
4436 (optional, defaults to 9989) the port of the buildbot master to which you will
4437 connect (as of this writing, the same server and port to which slaves connect)
4439 @item buildbot_pqm
4440 (optional, defaults to not pqm) Normally, the user that commits the revision
4441 is the user that is responsible for the change. When run in a pqm (Patch Queue
4442 Manager, see https://launchpad.net/pqm) environment, the user that commits is
4443 the Patch Queue Manager, and the user that committed the *parent* revision is
4444 responsible for the change. To turn on the pqm mode, set this value to any of
4445 (case-insensitive) "Yes", "Y", "True", or "T".
4447 @item buildbot_dry_run
4448 (optional, defaults to not a dry run) Normally, the post-commit hook will
4449 attempt to communicate with the configured buildbot server and port. If this
4450 parameter is included and any of (case-insensitive) "Yes", "Y", "True", or
4451 "T", then the hook will simply print what it would have sent, but not attempt
4452 to contact the buildbot master.
4454 @item buildbot_send_branch_name
4455 (optional, defaults to not sending the branch name) If your buildbot's bzr
4456 source build step uses a repourl, do *not* turn this on. If your buildbot's
4457 bzr build step uses a baseURL, then you may set this value to any of
4458 (case-insensitive) "Yes", "Y", "True", or "T" to have the buildbot master
4459 append the branch name to the baseURL.
4461 @end table
4463 When buildbot no longer has a hardcoded password, it will be a configuration
4464 option here as well.
4466 Here's a simple example that you might have in your
4467 @code{~/.bazaar/locations.conf}.
4469 @example
4470 [chroot-*:///var/local/myrepo/mybranch]
4471 buildbot_on = change
4472 buildbot_server = localhost
4473 @end example
4475 @node Bzr Poller, , Bzr Hook, Getting Source Code Changes
4476 @section Bzr Poller
4478 If you cannot insert a Bzr hook in the server, you can use the Bzr Poller. To
4479 use, put @code{contrib/bzr_buildbot.py} somewhere that your buildbot
4480 configuration can import it. Even putting it in the same directory as the master.cfg
4481 should work. Install the poller in the buildbot configuration as with any
4482 other change source. Minimally, provide a URL that you want to poll (bzr://,
4483 bzr+ssh://, or lp:), though make sure the buildbot user has necessary
4484 privileges. You may also want to specify these optional values.
4486 @table @code
4487 @item poll_interval
4488 The number of seconds to wait between polls.  Defaults to 10 minutes.
4490 @item branch_name
4491 Any value to be used as the branch name. Defaults to None, or specify a
4492 string, or specify the constants from @code{bzr_buildbot.py} SHORT or FULL to
4493 get the short branch name or full branch address.
4495 @item blame_merge_author
4496 normally, the user that commits the revision is the user that is responsible
4497 for the change. When run in a pqm (Patch Queue Manager, see
4498 https://launchpad.net/pqm) environment, the user that commits is the Patch
4499 Queue Manager, and the user that committed the merged, *parent* revision is
4500 responsible for the change. set this value to True if this is pointed against
4501 a PQM-managed branch.
4502 @end table
4504 @node Build Process, Status Delivery, Getting Source Code Changes, Top
4505 @chapter Build Process
4507 A @code{Build} object is responsible for actually performing a build.
4508 It gets access to a remote @code{SlaveBuilder} where it may run
4509 commands, and a @code{BuildStatus} object where it must emit status
4510 events. The @code{Build} is created by the Builder's
4511 @code{BuildFactory}.
4513 The default @code{Build} class is made up of a fixed sequence of
4514 @code{BuildSteps}, executed one after another until all are complete
4515 (or one of them indicates that the build should be halted early). The
4516 default @code{BuildFactory} creates instances of this @code{Build}
4517 class with a list of @code{BuildSteps}, so the basic way to configure
4518 the build is to provide a list of @code{BuildSteps} to your
4519 @code{BuildFactory}.
4521 More complicated @code{Build} subclasses can make other decisions:
4522 execute some steps only if certain files were changed, or if certain
4523 previous steps passed or failed. The base class has been written to
4524 allow users to express basic control flow without writing code, but
4525 you can always subclass and customize to achieve more specialized
4526 behavior.
4528 @menu
4529 * Build Steps::
4530 * Interlocks::
4531 * Build Factories::
4532 @end menu
4534 @node Build Steps, Interlocks, Build Process, Build Process
4535 @section Build Steps
4537 @code{BuildStep}s are usually specified in the buildmaster's
4538 configuration file, in a list that goes into the @code{BuildFactory}.
4539 The @code{BuildStep} instances in this list are used as templates to
4540 construct new independent copies for each build (so that state can be
4541 kept on the @code{BuildStep} in one build without affecting a later
4542 build). Each @code{BuildFactory} can be created with a list of steps,
4543 or the factory can be created empty and then steps added to it using
4544 the @code{addStep} method:
4546 @example
4547 from buildbot.steps import source, shell
4548 from buildbot.process import factory
4550 f = factory.BuildFactory()
4551 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
4552 f.addStep(shell.ShellCommand(command=["make", "all"]))
4553 f.addStep(shell.ShellCommand(command=["make", "test"]))
4554 @end example
4556 In earlier versions (0.7.5 and older), these steps were specified with
4557 a tuple of (step_class, keyword_arguments). Steps can still be
4558 specified this way, but the preferred form is to pass actual
4559 @code{BuildStep} instances to @code{addStep}, because that gives the
4560 @code{BuildStep} class a chance to do some validation on the
4561 arguments.
4563 If you have a common set of steps which are used in several factories, the
4564 @code{addSteps} method may be handy.  It takes an iterable of @code{BuildStep}
4565 instances.
4567 @example
4568 setup_steps = [
4569     source.SVN(svnurl="http://svn.example.org/Trunk/")
4570     shell.ShellCommand(command="./setup")
4572 quick = factory.BuildFactory()
4573 quick.addSteps(setup_steps)
4574 quick.addStep(shell.shellCommand(command="make quick"))
4575 @end example
4577 The rest of this section lists all the standard BuildStep objects
4578 available for use in a Build, and the parameters which can be used to
4579 control each.
4581 @menu
4582 * Common Parameters::
4583 * Using Build Properties::
4584 * Source Checkout::
4585 * ShellCommand::
4586 * Simple ShellCommand Subclasses::
4587 * Python BuildSteps::
4588 * Transferring Files::
4589 * Steps That Run on the Master::
4590 * Triggering Schedulers::
4591 * Writing New BuildSteps::
4592 @end menu
4594 @node Common Parameters, Using Build Properties, Build Steps, Build Steps
4595 @subsection Common Parameters
4597 The standard @code{Build} runs a series of @code{BuildStep}s in order,
4598 only stopping when it runs out of steps or if one of them requests
4599 that the build be halted. It collects status information from each one
4600 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
4602 All BuildSteps accept some common parameters. Some of these control
4603 how their individual status affects the overall build. Others are used
4604 to specify which @code{Locks} (see @pxref{Interlocks}) should be
4605 acquired before allowing the step to run.
4607 Arguments common to all @code{BuildStep} subclasses:
4610 @table @code
4611 @item name
4612 the name used to describe the step on the status display. It is also
4613 used to give a name to any LogFiles created by this step.
4615 @item haltOnFailure
4616 if True, a FAILURE of this build step will cause the build to halt
4617 immediately. Steps with @code{alwaysRun=True} are still run. Generally
4618 speaking, haltOnFailure implies flunkOnFailure (the default for most
4619 BuildSteps). In some cases, particularly series of tests, it makes sense
4620 to haltOnFailure if something fails early on but not flunkOnFailure.
4621 This can be achieved with haltOnFailure=True, flunkOnFailure=False.
4623 @item flunkOnWarnings
4624 when True, a WARNINGS or FAILURE of this build step will mark the
4625 overall build as FAILURE. The remaining steps will still be executed.
4627 @item flunkOnFailure
4628 when True, a FAILURE of this build step will mark the overall build as
4629 a FAILURE. The remaining steps will still be executed.
4631 @item warnOnWarnings
4632 when True, a WARNINGS or FAILURE of this build step will mark the
4633 overall build as having WARNINGS. The remaining steps will still be
4634 executed.
4636 @item warnOnFailure
4637 when True, a FAILURE of this build step will mark the overall build as
4638 having WARNINGS. The remaining steps will still be executed.
4640 @item alwaysRun
4641 if True, this build step will always be run, even if a previous buildstep
4642 with @code{haltOnFailure=True} has failed.
4644 @item locks
4645 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
4646 @code{buildbot.locks.MasterLock}) that should be acquired before
4647 starting this Step. The Locks will be released when the step is
4648 complete. Note that this is a list of actual Lock instances, not
4649 names. Also note that all Locks must have unique names.
4651 @end table
4653 @node Using Build Properties, Source Checkout, Common Parameters, Build Steps
4654 @subsection Using Build Properties
4655 @cindex Properties
4657 Build properties are a generalized way to provide configuration
4658 information to build steps; see @ref{Build Properties}.
4660 Some build properties are inherited from external sources -- global
4661 properties, schedulers, or buildslaves.  Some build properties are
4662 set when the build starts, such as the SourceStamp information. Other
4663 properties can be set by BuildSteps as they run, for example the
4664 various Source steps will set the @code{got_revision} property to the
4665 source revision that was actually checked out (which can be useful
4666 when the SourceStamp in use merely requested the ``latest revision'':
4667 @code{got_revision} will tell you what was actually built).
4669 In custom BuildSteps, you can get and set the build properties with
4670 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4671 for the name of the property, and returns or accepts an
4672 arbitrary@footnote{Build properties are serialized along with the
4673 build results, so they must be serializable. For this reason, the
4674 value of any build property should be simple inert data: strings,
4675 numbers, lists, tuples, and dictionaries. They should not contain
4676 class instances.} object. For example:
4678 @example
4679 class MakeTarball(ShellCommand):
4680     def start(self):
4681         if self.getProperty("os") == "win":
4682             self.setCommand([ ... ]) # windows-only command
4683         else:
4684             self.setCommand([ ... ]) # equivalent for other systems
4685         ShellCommand.start(self)
4686 @end example
4688 @heading WithProperties
4689 @cindex WithProperties
4691 You can use build properties in ShellCommands by using the
4692 @code{WithProperties} wrapper when setting the arguments of
4693 the ShellCommand. This interpolates the named build properties
4694 into the generated shell command.  Most step parameters accept
4695 @code{WithProperties}.  Please file bugs for any parameters which
4696 do not.
4698 @example
4699 from buildbot.steps.shell import ShellCommand
4700 from buildbot.process.properties import WithProperties
4702 f.addStep(ShellCommand(
4703           command=["tar", "czf",
4704                    WithProperties("build-%s.tar.gz", "revision"),
4705                    "source"]))
4706 @end example
4708 If this BuildStep were used in a tree obtained from Subversion, it
4709 would create a tarball with a name like @file{build-1234.tar.gz}.
4711 The @code{WithProperties} function does @code{printf}-style string
4712 interpolation, using strings obtained by calling
4713 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4714 @code{%d}, etc), you must have exactly one additional argument to
4715 indicate which build property you want to insert.
4717 You can also use python dictionary-style string interpolation by using
4718 the @code{%(propname)s} syntax. In this form, the property name goes
4719 in the parentheses, and WithProperties takes @emph{no} additional
4720 arguments:
4722 @example
4723 f.addStep(ShellCommand(
4724           command=["tar", "czf",
4725                    WithProperties("build-%(revision)s.tar.gz"),
4726                    "source"]))
4727 @end example
4729 Don't forget the extra ``s'' after the closing parenthesis! This is
4730 the cause of many confusing errors.
4732 The dictionary-style interpolation supports a number of more advanced
4733 syntaxes, too.
4735 @table @code
4737 @item propname:-replacement
4738 If @code{propname} exists, substitute its value; otherwise,
4739 substitute @code{replacement}.  @code{replacement} may be empty
4740 (@code{%(propname:-)s})
4742 @item propname:+replacement
4743 If @code{propname} exists, substitute @code{replacement}; otherwise,
4744 substitute an empty string.
4746 @end table
4748 Although these are similar to shell substitutions, no other
4749 substitutions are currently supported, and @code{replacement} in the
4750 above cannot contain more substitutions.
4752 Note: like python, you can either do positional-argument interpolation
4753 @emph{or} keyword-argument interpolation, not both. Thus you cannot use
4754 a string like @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4756 @heading Common Build Properties
4758 The following build properties are set when the build is started, and
4759 are available to all steps.
4761 @table @code
4762 @item branch
4764 This comes from the build's SourceStamp, and describes which branch is
4765 being checked out. This will be @code{None} (which interpolates into
4766 @code{WithProperties} as an empty string) if the build is on the
4767 default branch, which is generally the trunk. Otherwise it will be a
4768 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4769 system being used.
4771 @item revision
4773 This also comes from the SourceStamp, and is the revision of the source code
4774 tree that was requested from the VC system. When a build is requested of a
4775 specific revision (as is generally the case when the build is triggered by
4776 Changes), this will contain the revision specification. This is always a
4777 string, although the syntax depends upon the VC system in use: for SVN it is an
4778 integer, for Mercurial it is a short string, for Darcs it is a rather large
4779 string, etc.
4781 If the ``force build'' button was pressed, the revision will be @code{None},
4782 which means to use the most recent revision available.  This is a ``trunk
4783 build''. This will be interpolated as an empty string.
4785 @item got_revision
4787 This is set when a Source step checks out the source tree, and
4788 provides the revision that was actually obtained from the VC system.
4789 In general this should be the same as @code{revision}, except for
4790 trunk builds, where @code{got_revision} indicates what revision was
4791 current when the checkout was performed. This can be used to rebuild
4792 the same source code later.
4794 Note that for some VC systems (Darcs in particular), the revision is a
4795 large string containing newlines, and is not suitable for interpolation
4796 into a filename.
4798 @item buildername
4800 This is a string that indicates which Builder the build was a part of.
4801 The combination of buildername and buildnumber uniquely identify a
4802 build.
4804 @item buildnumber
4806 Each build gets a number, scoped to the Builder (so the first build
4807 performed on any given Builder will have a build number of 0). This
4808 integer property contains the build's number.
4810 @item slavename
4812 This is a string which identifies which buildslave the build is
4813 running on.
4815 @item scheduler
4817 If the build was started from a scheduler, then this property will
4818 contain the name of that scheduler.
4820 @end table
4823 @node Source Checkout, ShellCommand, Using Build Properties, Build Steps
4824 @subsection Source Checkout
4826 The first step of any build is typically to acquire the source code
4827 from which the build will be performed. There are several classes to
4828 handle this, one for each of the different source control system that
4829 Buildbot knows about. For a description of how Buildbot treats source
4830 control in general, see @ref{Version Control Systems}.
4832 All source checkout steps accept some common parameters to control how
4833 they get the sources and where they should be placed. The remaining
4834 per-VC-system parameters are mostly to specify where exactly the
4835 sources are coming from.
4837 @table @code
4838 @item mode
4840 a string describing the kind of VC operation that is desired. Defaults
4841 to @code{update}.
4843 @table @code
4844 @item update
4845 specifies that the CVS checkout/update should be performed directly
4846 into the workdir. Each build is performed in the same directory,
4847 allowing for incremental builds. This minimizes disk space, bandwidth,
4848 and CPU time. However, it may encounter problems if the build process
4849 does not handle dependencies properly (sometimes you must do a ``clean
4850 build'' to make sure everything gets compiled), or if source files are
4851 deleted but generated files can influence test behavior (e.g. python's
4852 .pyc files), or when source directories are deleted but generated
4853 files prevent CVS from removing them. Builds ought to be correct
4854 regardless of whether they are done ``from scratch'' or incrementally,
4855 but it is useful to test both kinds: this mode exercises the
4856 incremental-build style.
4858 @item copy
4859 specifies that the CVS workspace should be maintained in a separate
4860 directory (called the 'copydir'), using checkout or update as
4861 necessary. For each build, a new workdir is created with a copy of the
4862 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
4863 disk space required, but keeps the bandwidth low (update instead of a
4864 full checkout). A full 'clean' build is performed each time. This
4865 avoids any generated-file build problems, but is still occasionally
4866 vulnerable to CVS problems such as a repository being manually
4867 rearranged, causing CVS errors on update which are not an issue with a
4868 full checkout.
4870 @c TODO: something is screwy about this, revisit. Is it the source
4871 @c directory or the working directory that is deleted each time?
4873 @item clobber
4874 specifes that the working directory should be deleted each time,
4875 necessitating a full checkout for each build. This insures a clean
4876 build off a complete checkout, avoiding any of the problems described
4877 above. This mode exercises the ``from-scratch'' build style.
4879 @item export
4880 this is like @code{clobber}, except that the 'cvs export' command is
4881 used to create the working directory. This command removes all CVS
4882 metadata files (the CVS/ directories) from the tree, which is
4883 sometimes useful for creating source tarballs (to avoid including the
4884 metadata in the tar file).
4885 @end table
4887 @item workdir
4888 like all Steps, this indicates the directory where the build will take
4889 place. Source Steps are special in that they perform some operations
4890 outside of the workdir (like creating the workdir itself).
4892 @item alwaysUseLatest
4893 if True, bypass the usual ``update to the last Change'' behavior, and
4894 always update to the latest changes instead.
4896 @item retry
4897 If set, this specifies a tuple of @code{(delay, repeats)} which means
4898 that when a full VC checkout fails, it should be retried up to
4899 @var{repeats} times, waiting @var{delay} seconds between attempts. If
4900 you don't provide this, it defaults to @code{None}, which means VC
4901 operations should not be retried. This is provided to make life easier
4902 for buildslaves which are stuck behind poor network connections.
4904 @end table
4907 My habit as a developer is to do a @code{cvs update} and @code{make} each
4908 morning. Problems can occur, either because of bad code being checked in, or
4909 by incomplete dependencies causing a partial rebuild to fail where a
4910 complete from-scratch build might succeed. A quick Builder which emulates
4911 this incremental-build behavior would use the @code{mode='update'}
4912 setting.
4914 On the other hand, other kinds of dependency problems can cause a clean
4915 build to fail where a partial build might succeed. This frequently results
4916 from a link step that depends upon an object file that was removed from a
4917 later version of the tree: in the partial tree, the object file is still
4918 around (even though the Makefiles no longer know how to create it).
4920 ``official'' builds (traceable builds performed from a known set of
4921 source revisions) are always done as clean builds, to make sure it is
4922 not influenced by any uncontrolled factors (like leftover files from a
4923 previous build). A ``full'' Builder which behaves this way would want
4924 to use the @code{mode='clobber'} setting.
4926 Each VC system has a corresponding source checkout class: their
4927 arguments are described on the following pages.
4930 @menu
4931 * CVS::
4932 * SVN::
4933 * Darcs::
4934 * Mercurial::
4935 * Arch::
4936 * Bazaar::
4937 * Bzr::
4938 * P4::
4939 * Git::
4940 @end menu
4942 @node CVS, SVN, Source Checkout, Source Checkout
4943 @subsubsection CVS
4944 @cindex CVS Checkout
4945 @bsindex buildbot.steps.source.CVS
4948 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
4949 CVS} checkout or update. It takes the following arguments:
4951 @table @code
4952 @item cvsroot
4953 (required): specify the CVSROOT value, which points to a CVS
4954 repository, probably on a remote machine. For example, the cvsroot
4955 value you would use to get a copy of the Buildbot source code is
4956 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
4958 @item cvsmodule
4959 (required): specify the cvs @code{module}, which is generally a
4960 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
4961 code is @code{buildbot}.
4963 @item branch
4964 a string which will be used in a @code{-r} argument. This is most
4965 useful for specifying a branch to work on. Defaults to @code{HEAD}.
4967 @item global_options
4968 a list of flags to be put before the verb in the CVS command.
4970 @item checkoutDelay
4971 if set, the number of seconds to put between the timestamp of the last
4972 known Change and the value used for the @code{-D} option. Defaults to
4973 half of the parent Build's treeStableTimer.
4975 @end table
4978 @node SVN, Darcs, CVS, Source Checkout
4979 @subsubsection SVN
4981 @cindex SVN Checkout
4982 @bsindex buildbot.steps.source.SVN
4985 The @code{SVN} build step performs a
4986 @uref{http://subversion.tigris.org, Subversion} checkout or update.
4987 There are two basic ways of setting up the checkout step, depending
4988 upon whether you are using multiple branches or not.
4990 If all of your builds use the same branch, then you should create the
4991 @code{SVN} step with the @code{svnurl} argument:
4993 @table @code
4994 @item svnurl
4995 (required): this specifies the @code{URL} argument that will be given
4996 to the @code{svn checkout} command. It dictates both where the
4997 repository is located and which sub-tree should be extracted. In this
4998 respect, it is like a combination of the CVS @code{cvsroot} and
4999 @code{cvsmodule} arguments. For example, if you are using a remote
5000 Subversion repository which is accessible through HTTP at a URL of
5001 @code{http://svn.example.com/repos}, and you wanted to check out the
5002 @code{trunk/calc} sub-tree, you would use
5003 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
5004 to your @code{SVN} step.
5005 @end table
5007 If, on the other hand, you are building from multiple branches, then
5008 you should create the @code{SVN} step with the @code{baseURL} and
5009 @code{defaultBranch} arguments instead:
5011 @table @code
5012 @item baseURL
5013 (required): this specifies the base repository URL, to which a branch
5014 name will be appended. It should probably end in a slash.
5016 @item defaultBranch
5017 this specifies the name of the branch to use when a Build does not
5018 provide one of its own. This will be appended to @code{baseURL} to
5019 create the string that will be passed to the @code{svn checkout}
5020 command.
5022 @item username
5023 if specified, this will be passed to the @code{svn} binary with a
5024 @code{--username} option.
5026 @item password
5027 if specified, this will be passed to the @code{svn} binary with a
5028 @code{--password} option.  The password itself will be suitably obfuscated in
5029 the logs.
5031 @end table
5033 If you are using branches, you must also make sure your
5034 @code{ChangeSource} will report the correct branch names.
5036 @heading branch example
5038 Let's suppose that the ``MyProject'' repository uses branches for the
5039 trunk, for various users' individual development efforts, and for
5040 several new features that will require some amount of work (involving
5041 multiple developers) before they are ready to merge onto the trunk.
5042 Such a repository might be organized as follows:
5044 @example
5045 svn://svn.example.org/MyProject/trunk
5046 svn://svn.example.org/MyProject/branches/User1/foo
5047 svn://svn.example.org/MyProject/branches/User1/bar
5048 svn://svn.example.org/MyProject/branches/User2/baz
5049 svn://svn.example.org/MyProject/features/newthing
5050 svn://svn.example.org/MyProject/features/otherthing
5051 @end example
5053 Further assume that we want the Buildbot to run tests against the
5054 trunk and against all the feature branches (i.e., do a
5055 checkout/compile/build of branch X when a file has been changed on
5056 branch X, when X is in the set [trunk, features/newthing,
5057 features/otherthing]). We do not want the Buildbot to automatically
5058 build any of the user branches, but it should be willing to build a
5059 user branch when explicitly requested (most likely by the user who
5060 owns that branch).
5062 There are three things that need to be set up to accomodate this
5063 system. The first is a ChangeSource that is capable of identifying the
5064 branch which owns any given file. This depends upon a user-supplied
5065 function, in an external program that runs in the SVN commit hook and
5066 connects to the buildmaster's @code{PBChangeSource} over a TCP
5067 connection. (you can use the ``@code{buildbot sendchange}'' utility
5068 for this purpose, but you will still need an external program to
5069 decide what value should be passed to the @code{--branch=} argument).
5070 For example, a change to a file with the SVN url of
5071 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
5072 be broken down into a Change instance with
5073 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
5075 The second piece is an @code{AnyBranchScheduler} which will pay
5076 attention to the desired branches. It will not pay attention to the
5077 user branches, so it will not automatically start builds in response
5078 to changes there. The AnyBranchScheduler class requires you to
5079 explicitly list all the branches you want it to use, but it would not
5080 be difficult to write a subclass which used
5081 @code{branch.startswith('features/'} to remove the need for this
5082 explicit list. Or, if you want to build user branches too, you can use
5083 AnyBranchScheduler with @code{branches=None} to indicate that you want
5084 it to pay attention to all branches.
5086 The third piece is an @code{SVN} checkout step that is configured to
5087 handle the branches correctly, with a @code{baseURL} value that
5088 matches the way the ChangeSource splits each file's URL into base,
5089 branch, and file.
5091 @example
5092 from buildbot.changes.pb import PBChangeSource
5093 from buildbot.scheduler import AnyBranchScheduler
5094 from buildbot.process import source, factory
5095 from buildbot.steps import source, shell
5097 c['change_source'] = PBChangeSource()
5098 s1 = AnyBranchScheduler('main',
5099                         ['trunk', 'features/newthing', 'features/otherthing'],
5100                         10*60, ['test-i386', 'test-ppc'])
5101 c['schedulers'] = [s1]
5103 f = factory.BuildFactory()
5104 f.addStep(source.SVN(mode='update',
5105                      baseURL='svn://svn.example.org/MyProject/',
5106                      defaultBranch='trunk'))
5107 f.addStep(shell.Compile(command="make all"))
5108 f.addStep(shell.Test(command="make test"))
5110 c['builders'] = [
5111   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
5112                        'factory':f @},
5113   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
5114                       'factory':f @},
5116 @end example
5118 In this example, when a change arrives with a @code{branch} attribute
5119 of ``trunk'', the resulting build will have an SVN step that
5120 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
5121 ``trunk'' (the branch name) to get the correct svn command. If the
5122 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
5123 will concatenate ``svn://svn.example.org/MyProject/'' with
5124 ``features/newthing'' to get the svnurl for checkout.
5126 @node Darcs, Mercurial, SVN, Source Checkout
5127 @subsubsection Darcs
5129 @cindex Darcs Checkout
5130 @bsindex buildbot.steps.source.Darcs
5133 The @code{Darcs} build step performs a
5134 @uref{http://darcs.net/, Darcs} checkout or update.
5136 Like @xref{SVN}, this step can either be configured to always check
5137 out a specific tree, or set up to pull from a particular branch that
5138 gets specified separately for each build. Also like SVN, the
5139 repository URL given to Darcs is created by concatenating a
5140 @code{baseURL} with the branch name, and if no particular branch is
5141 requested, it uses a @code{defaultBranch}. The only difference in
5142 usage is that each potential Darcs repository URL must point to a
5143 fully-fledged repository, whereas SVN URLs usually point to sub-trees
5144 of the main Subversion repository. In other words, doing an SVN
5145 checkout of @code{baseURL} is legal, but silly, since you'd probably
5146 wind up with a copy of every single branch in the whole repository.
5147 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
5148 the parent directory of a collection of Darcs repositories is not
5149 itself a valid repository.
5151 The Darcs step takes the following arguments:
5153 @table @code
5154 @item repourl
5155 (required unless @code{baseURL} is provided): the URL at which the
5156 Darcs source repository is available.
5158 @item baseURL
5159 (required unless @code{repourl} is provided): the base repository URL,
5160 to which a branch name will be appended. It should probably end in a
5161 slash.
5163 @item defaultBranch
5164 (allowed if and only if @code{baseURL} is provided): this specifies
5165 the name of the branch to use when a Build does not provide one of its
5166 own. This will be appended to @code{baseURL} to create the string that
5167 will be passed to the @code{darcs get} command.
5168 @end table
5170 @node Mercurial, Arch, Darcs, Source Checkout
5171 @subsubsection Mercurial
5173 @cindex Mercurial Checkout
5174 @bsindex buildbot.steps.source.Mercurial
5177 The @code{Mercurial} build step performs a
5178 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
5179 or update.
5181 Branches are handled just like @xref{Darcs}.
5183 The Mercurial step takes the following arguments:
5185 @table @code
5186 @item repourl
5187 (required unless @code{baseURL} is provided): the URL at which the
5188 Mercurial source repository is available.
5190 @item baseURL
5191 (required unless @code{repourl} is provided): the base repository URL,
5192 to which a branch name will be appended. It should probably end in a
5193 slash.
5195 @item defaultBranch
5196 (allowed if and only if @code{baseURL} is provided): this specifies
5197 the name of the branch to use when a Build does not provide one of its
5198 own. This will be appended to @code{baseURL} to create the string that
5199 will be passed to the @code{hg clone} command.
5200 @end table
5203 @node Arch, Bazaar, Mercurial, Source Checkout
5204 @subsubsection Arch
5206 @cindex Arch Checkout
5207 @bsindex buildbot.steps.source.Arch
5210 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
5211 Arch} checkout or update using the @code{tla} client. It takes the
5212 following arguments:
5214 @table @code
5215 @item url
5216 (required): this specifies the URL at which the Arch source archive is
5217 available.
5219 @item version
5220 (required): this specifies which ``development line'' (like a branch)
5221 should be used. This provides the default branch name, but individual
5222 builds may specify a different one.
5224 @item archive
5225 (optional): Each repository knows its own archive name. If this
5226 parameter is provided, it must match the repository's archive name.
5227 The parameter is accepted for compatibility with the @code{Bazaar}
5228 step, below.
5230 @end table
5232 @node Bazaar, Bzr, Arch, Source Checkout
5233 @subsubsection Bazaar
5235 @cindex Bazaar Checkout
5236 @bsindex buildbot.steps.source.Bazaar
5239 @code{Bazaar} is an alternate implementation of the Arch VC system,
5240 which uses a client named @code{baz}. The checkout semantics are just
5241 different enough from @code{tla} that there is a separate BuildStep for
5244 It takes exactly the same arguments as @code{Arch}, except that the
5245 @code{archive=} parameter is required. (baz does not emit the archive
5246 name when you do @code{baz register-archive}, so we must provide it
5247 ourselves).
5250 @node Bzr, P4, Bazaar, Source Checkout
5251 @subsubsection Bzr
5253 @cindex Bzr Checkout
5254 @bsindex buildbot.steps.source.Bzr
5256 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
5257 as simply ``Bazaar''. The repository-vs-workspace model is similar to
5258 Darcs, but it uses a strictly linear sequence of revisions (one
5259 history per branch) like Arch. Branches are put in subdirectories.
5260 This makes it look very much like Mercurial, so it takes the same
5261 arguments:
5263 @table @code
5265 @item repourl
5266 (required unless @code{baseURL} is provided): the URL at which the
5267 Bzr source repository is available.
5269 @item baseURL
5270 (required unless @code{repourl} is provided): the base repository URL,
5271 to which a branch name will be appended. It should probably end in a
5272 slash.
5274 @item defaultBranch
5275 (allowed if and only if @code{baseURL} is provided): this specifies
5276 the name of the branch to use when a Build does not provide one of its
5277 own. This will be appended to @code{baseURL} to create the string that
5278 will be passed to the @code{bzr checkout} command.
5279 @end table
5283 @node P4, Git, Bzr, Source Checkout
5284 @subsubsection P4
5286 @cindex Perforce Update
5287 @bsindex buildbot.steps.source.P4
5288 @c TODO @bsindex buildbot.steps.source.P4Sync
5291 The @code{P4} build step creates a @uref{http://www.perforce.com/,
5292 Perforce} client specification and performs an update.
5294 @table @code
5295 @item p4base
5296 A view into the Perforce depot without branch name or trailing "...".
5297 Typically "//depot/proj/".
5298 @item defaultBranch
5299 A branch name to append on build requests if none is specified.
5300 Typically "trunk".
5301 @item p4port
5302 (optional): the host:port string describing how to get to the P4 Depot
5303 (repository), used as the -p argument for all p4 commands.
5304 @item p4user
5305 (optional): the Perforce user, used as the -u argument to all p4
5306 commands.
5307 @item p4passwd
5308 (optional): the Perforce password, used as the -p argument to all p4
5309 commands.
5310 @item p4extra_views
5311 (optional): a list of (depotpath, clientpath) tuples containing extra
5312 views to be mapped into the client specification. Both will have
5313 "/..." appended automatically. The client name and source directory
5314 will be prepended to the client path.
5315 @item p4client
5316 (optional): The name of the client to use. In mode='copy' and
5317 mode='update', it's particularly important that a unique name is used
5318 for each checkout directory to avoid incorrect synchronization. For
5319 this reason, Python percent substitution will be performed on this value
5320 to replace %(slave)s with the slave name and %(builder)s with the
5321 builder name. The default is "buildbot_%(slave)s_%(build)s".
5322 @end table
5325 @node Git,  , P4, Source Checkout
5326 @subsubsection Git
5328 @cindex Git Checkout
5329 @bsindex buildbot.steps.source.Git
5331 The @code{Git} build step clones or updates a @uref{http://git.or.cz/,
5332 Git} repository and checks out the specified branch or revision. Note
5333 that the buildbot supports Git version 1.2.0 and later: earlier
5334 versions (such as the one shipped in Ubuntu 'Dapper') do not support
5335 the @command{git init} command that the buildbot uses.
5337 The Git step takes the following arguments:
5339 @table @code
5340 @item repourl
5341 (required): the URL of the upstream Git repository.
5343 @item branch
5344 (optional): this specifies the name of the branch to use when a Build
5345 does not provide one of its own. If this this parameter is not
5346 specified, and the Build does not provide a branch, the ``master''
5347 branch will be used.
5348 @end table
5351 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
5352 @subsection ShellCommand
5354 @bsindex buildbot.steps.shell.ShellCommand
5355 @c TODO @bsindex buildbot.steps.shell.TreeSize
5357 This is a useful base class for just about everything you might want
5358 to do during a build (except for the initial source checkout). It runs
5359 a single command in a child shell on the buildslave. All stdout/stderr
5360 is recorded into a LogFile. The step finishes with a status of FAILURE
5361 if the command's exit code is non-zero, otherwise it has a status of
5362 SUCCESS.
5364 The preferred way to specify the command is with a list of argv strings,
5365 since this allows for spaces in filenames and avoids doing any fragile
5366 shell-escaping. You can also specify the command with a single string, in
5367 which case the string is given to '/bin/sh -c COMMAND' for parsing.
5369 On Windows, commands are run via @code{cmd.exe /c} which works well. However,
5370 if you're running a batch file, the error level does not get propagated
5371 correctly unless you add 'call' before your batch file's name:
5372 @code{cmd=['call', 'myfile.bat', ...]}.
5374 All ShellCommands are run by default in the ``workdir'', which
5375 defaults to the ``@file{build}'' subdirectory of the slave builder's
5376 base directory. The absolute path of the workdir will thus be the
5377 slave's basedir (set as an option to @code{buildbot create-slave},
5378 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
5379 builder's @code{c['builddir']} key in master.cfg) plus the workdir
5380 itself (a class-level attribute of the BuildFactory, defaults to
5381 ``@file{build}'').
5383 @code{ShellCommand} arguments:
5385 @table @code
5386 @item command
5387 a list of strings (preferred) or single string (discouraged) which
5388 specifies the command to be run. A list of strings is preferred
5389 because it can be used directly as an argv array. Using a single
5390 string (with embedded spaces) requires the buildslave to pass the
5391 string to /bin/sh for interpretation, which raises all sorts of
5392 difficult questions about how to escape or interpret shell
5393 metacharacters.
5395 @item env
5396 a dictionary of environment strings which will be added to the child
5397 command's environment. For example, to run tests with a different i18n
5398 language setting, you might use
5400 @example
5401 f.addStep(ShellCommand(command=["make", "test"],
5402                        env=@{'LANG': 'fr_FR'@}))
5403 @end example
5405 These variable settings will override any existing ones in the
5406 buildslave's environment or the environment specified in the
5407 Builder. The exception is PYTHONPATH, which is merged
5408 with (actually prepended to) any existing $PYTHONPATH setting. The
5409 value is treated as a list of directories to prepend, and a single
5410 string is treated like a one-item list. For example, to prepend both
5411 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
5412 to any existing $PYTHONPATH setting, you would do something like the
5413 following:
5415 @example
5416 f.addStep(ShellCommand(
5417               command=["make", "test"],
5418               env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
5419                                    "/home/buildbot/lib/python"] @}))
5420 @end example
5422 @item want_stdout
5423 if False, stdout from the child process is discarded rather than being
5424 sent to the buildmaster for inclusion in the step's LogFile.
5426 @item want_stderr
5427 like @code{want_stdout} but for stderr. Note that commands run through
5428 a PTY do not have separate stdout/stderr streams: both are merged into
5429 stdout.
5431 @item usePTY
5432 Should this command be run in a @code{pty}?  The default is to observe the
5433 configuration of the client (@pxref{Buildslave Options}), but specifying
5434 @code{True} or @code{False} here will override the default.
5436 The advantage of using a PTY is that ``grandchild'' processes are more likely
5437 to be cleaned up if the build is interrupted or times out (since it enables the
5438 use of a ``process group'' in which all child processes will be placed). The
5439 disadvantages: some forms of Unix have problems with PTYs, some of your unit
5440 tests may behave differently when run under a PTY (generally those which check
5441 to see if they are being run interactively), and PTYs will merge the stdout and
5442 stderr streams into a single output stream (which means the red-vs-black
5443 coloring in the logfiles will be lost).
5445 @item logfiles
5446 Sometimes commands will log interesting data to a local file, rather
5447 than emitting everything to stdout or stderr. For example, Twisted's
5448 ``trial'' command (which runs unit tests) only presents summary
5449 information to stdout, and puts the rest into a file named
5450 @file{_trial_temp/test.log}. It is often useful to watch these files
5451 as the command runs, rather than using @command{/bin/cat} to dump
5452 their contents afterwards.
5454 The @code{logfiles=} argument allows you to collect data from these
5455 secondary logfiles in near-real-time, as the step is running. It
5456 accepts a dictionary which maps from a local Log name (which is how
5457 the log data is presented in the build results) to a remote filename
5458 (interpreted relative to the build's working directory). Each named
5459 file will be polled on a regular basis (every couple of seconds) as
5460 the build runs, and any new text will be sent over to the buildmaster.
5462 @example
5463 f.addStep(ShellCommand(
5464               command=["make", "test"],
5465               logfiles=@{"triallog": "_trial_temp/test.log"@}))
5466 @end example
5469 @item timeout
5470 if the command fails to produce any output for this many seconds, it
5471 is assumed to be locked up and will be killed.
5473 @item description
5474 This will be used to describe the command (on the Waterfall display)
5475 while the command is still running. It should be a single
5476 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
5477 form is a list of short strings, which allows the HTML Waterfall
5478 display to create narrower columns by emitting a <br> tag between each
5479 word. You may also provide a single string.
5481 @item descriptionDone
5482 This will be used to describe the command once it has finished. A
5483 simple noun like ``compile'' or ``tests'' should be used. Like
5484 @code{description}, this may either be a list of short strings or a
5485 single string.
5487 If neither @code{description} nor @code{descriptionDone} are set, the
5488 actual command arguments will be used to construct the description.
5489 This may be a bit too wide to fit comfortably on the Waterfall
5490 display.
5492 @example
5493 f.addStep(ShellCommand(command=["make", "test"],
5494                        description=["testing"],
5495                        descriptionDone=["tests"]))
5496 @end example
5498 @item logEnviron
5499 If this option is true (the default), then the step's logfile will describe the
5500 environment variables on the slave.  In situations where the environment is not
5501 relevant and is long, it may be easier to set @code{logEnviron=False}.
5503 @end table
5505 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
5506 @subsection Simple ShellCommand Subclasses
5508 Several subclasses of ShellCommand are provided as starting points for
5509 common build steps. These are all very simple: they just override a few
5510 parameters so you don't have to specify them yourself, making the master.cfg
5511 file less verbose.
5513 @menu
5514 * Configure::
5515 * Compile::
5516 * Test::
5517 * TreeSize::
5518 * PerlModuleTest::
5519 * SetProperty::
5520 @end menu
5522 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
5523 @subsubsection Configure
5525 @bsindex buildbot.steps.shell.Configure
5527 This is intended to handle the @code{./configure} step from
5528 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
5529 MakeMaker.pm-style modules. The default command is @code{./configure}
5530 but you can change this by providing a @code{command=} parameter.
5532 @node Compile, Test, Configure, Simple ShellCommand Subclasses
5533 @subsubsection Compile
5535 @bsindex buildbot.steps.shell.Compile
5537 This is meant to handle compiling or building a project written in C.
5538 The default command is @code{make all}. When the compile is finished,
5539 the log file is scanned for GCC warning messages, a summary log is
5540 created with any problems that were seen, and the step is marked as
5541 WARNINGS if any were discovered. The number of warnings is stored in a
5542 Build Property named ``warnings-count'', which is accumulated over all
5543 Compile steps (so if two warnings are found in one step, and three are
5544 found in another step, the overall build will have a
5545 ``warnings-count'' property of 5.
5547 The default regular expression used to detect a warning is
5548 @code{'.*warning[: ].*'} , which is fairly liberal and may cause
5549 false-positives. To use a different regexp, provide a
5550 @code{warningPattern=} argument, or use a subclass which sets the
5551 @code{warningPattern} attribute:
5553 @example
5554 f.addStep(Compile(command=["make", "test"],
5555                   warningPattern="^Warning: "))
5556 @end example
5558 The @code{warningPattern=} can also be a pre-compiled python regexp
5559 object: this makes it possible to add flags like @code{re.I} (to use
5560 case-insensitive matching).
5562 (TODO: this step needs to be extended to look for GCC error messages
5563 as well, and collect them into a separate logfile, along with the
5564 source code filenames involved).
5567 @node Test, TreeSize, Compile, Simple ShellCommand Subclasses
5568 @subsubsection Test
5570 @bsindex buildbot.steps.shell.Test
5572 This is meant to handle unit tests. The default command is @code{make
5573 test}, and the @code{warnOnFailure} flag is set.
5575 @node TreeSize, PerlModuleTest, Test, Simple ShellCommand Subclasses
5576 @subsubsection TreeSize
5578 @bsindex buildbot.steps.shell.TreeSize
5580 This is a simple command that uses the 'du' tool to measure the size
5581 of the code tree. It puts the size (as a count of 1024-byte blocks,
5582 aka 'KiB' or 'kibibytes') on the step's status text, and sets a build
5583 property named 'tree-size-KiB' with the same value.
5585 @node PerlModuleTest, SetProperty, TreeSize, Simple ShellCommand Subclasses
5586 @subsubsection PerlModuleTest
5588 @bsindex buildbot.steps.shell.PerlModuleTest
5590 This is a simple command that knows how to run tests of perl modules.
5591 It parses the output to determine the number of tests passed and
5592 failed and total number executed, saving the results for later query.
5594 @node SetProperty,  , PerlModuleTest, Simple ShellCommand Subclasses
5595 @subsubsection SetProperty
5597 @bsindex buildbot.steps.shell.SetProperty
5599 This buildstep is similar to ShellCommand, except that it captures the
5600 output of the command into a property.  It is usually used like this:
5602 @example
5603 f.addStep(SetProperty(command="uname -a", property="uname"))
5604 @end example
5606 This runs @code{uname -a} and captures its stdout, stripped of leading
5607 and trailing whitespace, in the property "uname".  To avoid stripping,
5608 add @code{strip=False}.  The @code{property} argument can be specified
5609 as a @code{WithProperties} object.
5611 The more advanced usage allows you to specify a function to extract
5612 properties from the command output.  Here you can use regular
5613 expressions, string interpolation, or whatever you would like.
5614 The function is called with three arguments: the exit status of the
5615 command, its standard output as a string, and its standard error as
5616 a string.  It should return a dictionary containing all new properties.
5618 @example
5619 def glob2list(rc, stdout, stderr):
5620     jpgs = [ l.strip() for l in stdout.split('\n') ]
5621     return @{ 'jpgs' : jpgs @}
5622 f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
5623 @end example
5625 Note that any ordering relationship of the contents of stdout and
5626 stderr is lost.  For example, given
5628 @example
5629 f.addStep(SetProperty(
5630     command="echo output1; echo error >&2; echo output2",
5631     extract_fn=my_extract))
5632 @end example
5634 Then @code{my_extract} will see @code{stdout="output1\noutput2\n"}
5635 and @code{stderr="error\n"}.
5637 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
5638 @subsection Python BuildSteps
5640 Here are some BuildSteps that are specifcally useful for projects
5641 implemented in Python.
5643 @menu
5644 * BuildEPYDoc::
5645 * PyFlakes::
5646 * PyLint::
5647 @end menu
5649 @node BuildEPYDoc
5650 @subsubsection BuildEPYDoc
5652 @bsindex buildbot.steps.python.BuildEPYDoc
5654 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
5655 API documentation for Python modules from their docstrings. It reads
5656 all the .py files from your source tree, processes the docstrings
5657 therein, and creates a large tree of .html files (or a single .pdf
5658 file).
5660 The @code{buildbot.steps.python.BuildEPYDoc} step will run
5661 @command{epydoc} to produce this API documentation, and will count the
5662 errors and warnings from its output.
5664 You must supply the command line to be used. The default is
5665 @command{make epydocs}, which assumes that your project has a Makefile
5666 with an ``epydocs'' target. You might wish to use something like
5667 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
5668 to add @command{--pdf} to generate a PDF file instead of a large tree
5669 of HTML files.
5671 The API docs are generated in-place in the build tree (under the
5672 workdir, in the subdirectory controlled by the ``-o'' argument). To
5673 make them useful, you will probably have to copy them to somewhere
5674 they can be read. A command like @command{rsync -ad apiref/
5675 dev.example.com:~public_html/current-apiref/} might be useful. You
5676 might instead want to bundle them into a tarball and publish it in the
5677 same place where the generated install tarball is placed.
5679 @example
5680 from buildbot.steps.python import BuildEPYDoc
5683 f.addStep(BuildEPYDoc(command=["epydoc", "-o", "apiref", "source/mypkg"]))
5684 @end example
5687 @node PyFlakes
5688 @subsubsection PyFlakes
5690 @bsindex buildbot.steps.python.PyFlakes
5692 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
5693 to perform basic static analysis of Python code to look for simple
5694 errors, like missing imports and references of undefined names. It is
5695 like a fast and simple form of the C ``lint'' program. Other tools
5696 (like pychecker) provide more detailed results but take longer to run.
5698 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
5699 count the various kinds of errors and warnings it detects.
5701 You must supply the command line to be used. The default is
5702 @command{make pyflakes}, which assumes you have a top-level Makefile
5703 with a ``pyflakes'' target. You might want to use something like
5704 @command{pyflakes .} or @command{pyflakes src}.
5706 @example
5707 from buildbot.steps.python import PyFlakes
5710 f.addStep(PyFlakes(command=["pyflakes", "src"]))
5711 @end example
5713 @node PyLint
5714 @subsubsection PyLint
5716 @bsindex buildbot.steps.python.PyLint
5718 Similarly, the @code{buildbot.steps.python.PyLint} step will run pylint and
5719 analyze the results.
5721 You must supply the command line to be used. There is no default.
5723 @example
5724 from buildbot.steps.python import PyLint
5727 f.addStep(PyLint(command=["pylint", "src"]))
5728 @end example
5731 @node Transferring Files
5732 @subsection Transferring Files
5734 @cindex File Transfer
5735 @bsindex buildbot.steps.transfer.FileUpload
5736 @bsindex buildbot.steps.transfer.FileDownload
5737 @bsindex buildbot.steps.transfer.DirectoryUpload
5739 Most of the work involved in a build will take place on the
5740 buildslave. But occasionally it is useful to do some work on the
5741 buildmaster side. The most basic way to involve the buildmaster is
5742 simply to move a file from the slave to the master, or vice versa.
5743 There are a pair of BuildSteps named @code{FileUpload} and
5744 @code{FileDownload} to provide this functionality. @code{FileUpload}
5745 moves a file @emph{up to} the master, while @code{FileDownload} moves
5746 a file @emph{down from} the master.
5748 As an example, let's assume that there is a step which produces an
5749 HTML file within the source tree that contains some sort of generated
5750 project documentation. We want to move this file to the buildmaster,
5751 into a @file{~/public_html} directory, so it can be visible to
5752 developers. This file will wind up in the slave-side working directory
5753 under the name @file{docs/reference.html}. We want to put it into the
5754 master-side @file{~/public_html/ref.html}.
5756 @example
5757 from buildbot.steps.shell import ShellCommand
5758 from buildbot.steps.transfer import FileUpload
5760 f.addStep(ShellCommand(command=["make", "docs"]))
5761 f.addStep(FileUpload(slavesrc="docs/reference.html",
5762                      masterdest="~/public_html/ref.html"))
5763 @end example
5765 The @code{masterdest=} argument will be passed to os.path.expanduser,
5766 so things like ``~'' will be expanded properly. Non-absolute paths
5767 will be interpreted relative to the buildmaster's base directory.
5768 Likewise, the @code{slavesrc=} argument will be expanded and
5769 interpreted relative to the builder's working directory.
5772 To move a file from the master to the slave, use the
5773 @code{FileDownload} command. For example, let's assume that some step
5774 requires a configuration file that, for whatever reason, could not be
5775 recorded in the source code repository or generated on the buildslave
5776 side:
5778 @example
5779 from buildbot.steps.shell import ShellCommand
5780 from buildbot.steps.transfer import FileUpload
5782 f.addStep(FileDownload(mastersrc="~/todays_build_config.txt",
5783                        slavedest="build_config.txt"))
5784 f.addStep(ShellCommand(command=["make", "config"]))
5785 @end example
5787 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
5788 relative to the buildmaster's base directory, and the
5789 @code{slavedest=} argument is relative to the builder's working
5790 directory. If the buildslave is running in @file{~buildslave}, and the
5791 builder's ``builddir'' is something like @file{tests-i386}, then the
5792 workdir is going to be @file{~buildslave/tests-i386/build}, and a
5793 @code{slavedest=} of @file{foo/bar.html} will get put in
5794 @file{~buildslave/tests-i386/build/foo/bar.html}. Both of these commands
5795 will create any missing intervening directories.
5797 @subheading Other Parameters
5799 The @code{maxsize=} argument lets you set a maximum size for the file
5800 to be transferred. This may help to avoid surprises: transferring a
5801 100MB coredump when you were expecting to move a 10kB status file
5802 might take an awfully long time. The @code{blocksize=} argument
5803 controls how the file is sent over the network: larger blocksizes are
5804 slightly more efficient but also consume more memory on each end, and
5805 there is a hard-coded limit of about 640kB.
5807 The @code{mode=} argument allows you to control the access permissions
5808 of the target file, traditionally expressed as an octal integer. The
5809 most common value is probably 0755, which sets the ``x'' executable
5810 bit on the file (useful for shell scripts and the like). The default
5811 value for @code{mode=} is None, which means the permission bits will
5812 default to whatever the umask of the writing process is. The default
5813 umask tends to be fairly restrictive, but at least on the buildslave
5814 you can make it less restrictive with a --umask command-line option at
5815 creation time (@pxref{Buildslave Options}).
5817 @subheading Transfering Directories
5819 To transfer complete directories from the buildslave to the master, there
5820 is a BuildStep named @code{DirectoryUpload}. It works like @code{FileUpload},
5821 just for directories. However it does not support the @code{maxsize},
5822 @code{blocksize} and @code{mode} arguments. As an example, let's assume an
5823 generated project documentation, which consists of many files (like the output
5824 of doxygen or epydoc). We want to move the entire documentation to the
5825 buildmaster, into a @code{~/public_html/docs} directory. On the slave-side
5826 the directory can be found under @code{docs}:
5828 @example
5829 from buildbot.steps.shell import ShellCommand
5830 from buildbot.steps.transfer import DirectoryUpload
5832 f.addStep(ShellCommand(command=["make", "docs"]))
5833 f.addStep(DirectoryUpload(slavesrc="docs",
5834                                 masterdest="~/public_html/docs"))
5835 @end example
5837 The DirectoryUpload step will create all necessary directories and
5838 transfers empty directories, too.
5840 @node Steps That Run on the Master
5841 @subsection Steps That Run on the Master
5843 Occasionally, it is useful to execute some task on the master, for example to
5844 create a directory, deploy a build result, or trigger some other centralized
5845 processing.  This is possible, in a limited fashion, with the
5846 @code{MasterShellCommand} step.
5848 This step operates similarly to a regular @code{ShellCommand}, but executes on
5849 the master, instead of the slave.  To be clear, the enclosing @code{Build}
5850 object must still have a slave object, just as for any other step -- only, in
5851 this step, the slave does not do anything.
5853 In this example, the step renames a tarball based on the day of the week.
5855 @example
5856 from buildbot.steps.transfer import FileUpload
5857 from buildbot.steps.master import MasterShellCommand
5859 f.addStep(FileUpload(slavesrc="widgetsoft.tar.gz",
5860                      masterdest="/var/buildoutputs/widgetsoft-new.tar.gz"))
5861 f.addStep(MasterShellCommand(command="""
5862     cd /var/buildoutputs;
5863     mv widgetsoft-new.tar.gz widgetsoft-`date +%a`.tar.gz"""))
5864 @end example
5866 @node Triggering Schedulers
5867 @subsection Triggering Schedulers
5869 The counterpart to the Triggerable described in section
5870 @pxref{Triggerable Scheduler} is the Trigger BuildStep.
5872 @example
5873 from buildbot.steps.trigger import Trigger
5874 f.addStep(Trigger(schedulerNames=['build-prep'],
5875                   waitForFinish=True,
5876                   updateSourceStamp=True))
5877 @end example
5879 The @code{schedulerNames=} argument lists the Triggerables
5880 that should be triggered when this step is executed.  Note that
5881 it is possible, but not advisable, to create a cycle where a build
5882 continually triggers itself, because the schedulers are specified
5883 by name.
5885 If @code{waitForFinish} is True, then the step will not finish until
5886 all of the builds from the triggered schedulers have finished. If this
5887 argument is False (the default) or not given, then the buildstep
5888 succeeds immediately after triggering the schedulers.
5890 If @code{updateSourceStamp} is True (the default), then step updates
5891 the SourceStamp given to the Triggerables to include
5892 @code{got_revision} (the revision actually used in this build) as
5893 @code{revision} (the revision to use in the triggered builds). This is
5894 useful to ensure that all of the builds use exactly the same
5895 SourceStamp, even if other Changes have occurred while the build was
5896 running.
5898 @node Writing New BuildSteps
5899 @subsection Writing New BuildSteps
5901 While it is a good idea to keep your build process self-contained in
5902 the source code tree, sometimes it is convenient to put more
5903 intelligence into your Buildbot configuration. One way to do this is
5904 to write a custom BuildStep. Once written, this Step can be used in
5905 the @file{master.cfg} file.
5907 The best reason for writing a custom BuildStep is to better parse the
5908 results of the command being run. For example, a BuildStep that knows
5909 about JUnit could look at the logfiles to determine which tests had
5910 been run, how many passed and how many failed, and then report more
5911 detailed information than a simple @code{rc==0} -based ``good/bad''
5912 decision.
5914 @menu
5915 * Writing BuildStep Constructors::
5916 * BuildStep LogFiles::
5917 * Reading Logfiles::
5918 * Adding LogObservers::
5919 * BuildStep URLs::
5920 @end menu
5922 @node Writing BuildStep Constructors
5923 @subsubsection Writing BuildStep Constructors
5925 BuildStep classes have some extra equipment, because they are their own
5926 factories.  Consider the use of a BuildStep in @file{master.cfg}:
5928 @example
5929 f.addStep(MyStep(someopt="stuff", anotheropt=1))
5930 @end example
5932 This creates a single instance of class @code{MyStep}.  However, Buildbot needs
5933 a new object each time the step is executed.  this is accomplished by storing
5934 the information required to instantiate a new object in the @code{factory}
5935 attribute.  When the time comes to construct a new Build, BuildFactory consults
5936 this attribute (via @code{getStepFactory}) and instantiates a new step object.
5938 When writing a new step class, then, keep in mind are that you cannot do
5939 anything "interesting" in the constructor -- limit yourself to checking and
5940 storing arguments.  To ensure that these arguments are provided to any new
5941 objects, call @code{self.addFactoryArguments} with any keyword arguments your
5942 constructor needs.
5944 Keep a @code{**kwargs} argument on the end of your options, and pass that up to
5945 the parent class's constructor.
5947 The whole thing looks like this:
5949 @example
5950 class Frobinfy(LoggingBuildStep):
5951     def __init__(self,
5952             frob_what="frobee",
5953             frob_how_many=None,
5954             frob_how=None,
5955             **kwargs)
5957         # check
5958         if frob_how_many is None:
5959             raise TypeError("Frobinfy argument how_many is required")
5961         # call parent
5962         LoggingBuildStep.__init__(self, **kwargs)
5964         # and record arguments for later
5965         self.addFactoryArguments(
5966             frob_what=frob_what,
5967             frob_how_many=frob_how_many,
5968             frob_how=frob_how)
5970 class FastFrobnify(Frobnify):
5971     def __init__(self,
5972             speed=5,
5973             **kwargs)
5974         Frobnify.__init__(self, **kwargs)
5975         self.addFactoryArguments(
5976             speed=speed)
5977 @end example
5979 @node BuildStep LogFiles
5980 @subsubsection BuildStep LogFiles
5982 Each BuildStep has a collection of ``logfiles''. Each one has a short
5983 name, like ``stdio'' or ``warnings''. Each LogFile contains an
5984 arbitrary amount of text, usually the contents of some output file
5985 generated during a build or test step, or a record of everything that
5986 was printed to stdout/stderr during the execution of some command.
5988 These LogFiles are stored to disk, so they can be retrieved later.
5990 Each can contain multiple ``channels'', generally limited to three
5991 basic ones: stdout, stderr, and ``headers''. For example, when a
5992 ShellCommand runs, it writes a few lines to the ``headers'' channel to
5993 indicate the exact argv strings being run, which directory the command
5994 is being executed in, and the contents of the current environment
5995 variables. Then, as the command runs, it adds a lot of ``stdout'' and
5996 ``stderr'' messages. When the command finishes, a final ``header''
5997 line is added with the exit code of the process.
5999 Status display plugins can format these different channels in
6000 different ways. For example, the web page shows LogFiles as text/html,
6001 with header lines in blue text, stdout in black, and stderr in red. A
6002 different URL is available which provides a text/plain format, in
6003 which stdout and stderr are collapsed together, and header lines are
6004 stripped completely. This latter option makes it easy to save the
6005 results to a file and run @command{grep} or whatever against the
6006 output.
6008 Each BuildStep contains a mapping (implemented in a python dictionary)
6009 from LogFile name to the actual LogFile objects. Status plugins can
6010 get a list of LogFiles to display, for example, a list of HREF links
6011 that, when clicked, provide the full contents of the LogFile.
6013 @heading Using LogFiles in custom BuildSteps
6015 The most common way for a custom BuildStep to use a LogFile is to
6016 summarize the results of a ShellCommand (after the command has
6017 finished running). For example, a compile step with thousands of lines
6018 of output might want to create a summary of just the warning messages.
6019 If you were doing this from a shell, you would use something like:
6021 @example
6022 grep "warning:" output.log >warnings.log
6023 @end example
6025 In a custom BuildStep, you could instead create a ``warnings'' LogFile
6026 that contained the same text. To do this, you would add code to your
6027 @code{createSummary} method that pulls lines from the main output log
6028 and creates a new LogFile with the results:
6030 @example
6031     def createSummary(self, log):
6032         warnings = []
6033         for line in log.readlines():
6034             if "warning:" in line:
6035                 warnings.append()
6036         self.addCompleteLog('warnings', "".join(warnings))
6037 @end example
6039 This example uses the @code{addCompleteLog} method, which creates a
6040 new LogFile, puts some text in it, and then ``closes'' it, meaning
6041 that no further contents will be added. This LogFile will appear in
6042 the HTML display under an HREF with the name ``warnings'', since that
6043 is the name of the LogFile.
6045 You can also use @code{addHTMLLog} to create a complete (closed)
6046 LogFile that contains HTML instead of plain text. The normal LogFile
6047 will be HTML-escaped if presented through a web page, but the HTML
6048 LogFile will not. At the moment this is only used to present a pretty
6049 HTML representation of an otherwise ugly exception traceback when
6050 something goes badly wrong during the BuildStep.
6052 In contrast, you might want to create a new LogFile at the beginning
6053 of the step, and add text to it as the command runs. You can create
6054 the LogFile and attach it to the build by calling @code{addLog}, which
6055 returns the LogFile object. You then add text to this LogFile by
6056 calling methods like @code{addStdout} and @code{addHeader}. When you
6057 are done, you must call the @code{finish} method so the LogFile can be
6058 closed. It may be useful to create and populate a LogFile like this
6059 from a LogObserver method @xref{Adding LogObservers}.
6061 The @code{logfiles=} argument to @code{ShellCommand} (see
6062 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
6063 by asking the buildslave to watch a actual file on disk. The
6064 buildslave will look for additions in the target file and report them
6065 back to the BuildStep. These additions will be added to the LogFile by
6066 calling @code{addStdout}. These secondary LogFiles can be used as the
6067 source of a LogObserver just like the normal ``stdio'' LogFile.
6069 @node Reading Logfiles
6070 @subsubsection Reading Logfiles
6072 Once a LogFile has been added to a BuildStep with @code{addLog()},
6073 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
6074 your BuildStep can retrieve it by using @code{getLog()}:
6076 @example
6077 class MyBuildStep(ShellCommand):
6078     logfiles = @{ "nodelog": "_test/node.log" @}
6080     def evaluateCommand(self, cmd):
6081         nodelog = self.getLog("nodelog")
6082         if "STARTED" in nodelog.getText():
6083             return SUCCESS
6084         else:
6085             return FAILURE
6086 @end example
6088 For a complete list of the methods you can call on a LogFile, please
6089 see the docstrings on the @code{IStatusLog} class in
6090 @file{buildbot/interfaces.py}.
6093 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
6094 @subsubsection Adding LogObservers
6096 @cindex LogObserver
6097 @cindex LogLineObserver
6099 Most shell commands emit messages to stdout or stderr as they operate,
6100 especially if you ask them nicely with a @code{--verbose} flag of some
6101 sort. They may also write text to a log file while they run. Your
6102 BuildStep can watch this output as it arrives, to keep track of how
6103 much progress the command has made. You can get a better measure of
6104 progress by counting the number of source files compiled or test cases
6105 run than by merely tracking the number of bytes that have been written
6106 to stdout. This improves the accuracy and the smoothness of the ETA
6107 display.
6109 To accomplish this, you will need to attach a @code{LogObserver} to
6110 one of the log channels, most commonly to the ``stdio'' channel but
6111 perhaps to another one which tracks a log file. This observer is given
6112 all text as it is emitted from the command, and has the opportunity to
6113 parse that output incrementally. Once the observer has decided that
6114 some event has occurred (like a source file being compiled), it can
6115 use the @code{setProgress} method to tell the BuildStep about the
6116 progress that this event represents.
6118 There are a number of pre-built @code{LogObserver} classes that you
6119 can choose from (defined in @code{buildbot.process.buildstep}, and of
6120 course you can subclass them to add further customization. The
6121 @code{LogLineObserver} class handles the grunt work of buffering and
6122 scanning for end-of-line delimiters, allowing your parser to operate
6123 on complete stdout/stderr lines. (Lines longer than a set maximum
6124 length are dropped; the maximum defaults to 16384 bytes, but you can
6125 change it by calling @code{setMaxLineLength()} on your
6126 @code{LogLineObserver} instance.  Use @code{sys.maxint} for effective
6127 infinity.)
6129 For example, let's take a look at the @code{TrialTestCaseCounter},
6130 which is used by the Trial step to count test cases as they are run.
6131 As Trial executes, it emits lines like the following:
6133 @example
6134 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
6135 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
6136 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
6137 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
6138 @end example
6140 When the tests are finished, trial emits a long line of ``======'' and
6141 then some lines which summarize the tests that failed. We want to
6142 avoid parsing these trailing lines, because their format is less
6143 well-defined than the ``[OK]'' lines.
6145 The parser class looks like this:
6147 @example
6148 from buildbot.process.buildstep import LogLineObserver
6150 class TrialTestCaseCounter(LogLineObserver):
6151     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
6152     numTests = 0
6153     finished = False
6155     def outLineReceived(self, line):
6156         if self.finished:
6157             return
6158         if line.startswith("=" * 40):
6159             self.finished = True
6160             return
6162         m = self._line_re.search(line.strip())
6163         if m:
6164             testname, result = m.groups()
6165             self.numTests += 1
6166             self.step.setProgress('tests', self.numTests)
6167 @end example
6169 This parser only pays attention to stdout, since that's where trial
6170 writes the progress lines. It has a mode flag named @code{finished} to
6171 ignore everything after the ``===='' marker, and a scary-looking
6172 regular expression to match each line while hopefully ignoring other
6173 messages that might get displayed as the test runs.
6175 Each time it identifies a test has been completed, it increments its
6176 counter and delivers the new progress value to the step with
6177 @code{self.step.setProgress}. This class is specifically measuring
6178 progress along the ``tests'' metric, in units of test cases (as
6179 opposed to other kinds of progress like the ``output'' metric, which
6180 measures in units of bytes). The Progress-tracking code uses each
6181 progress metric separately to come up with an overall completion
6182 percentage and an ETA value.
6184 To connect this parser into the @code{Trial} BuildStep,
6185 @code{Trial.__init__} ends with the following clause:
6187 @example
6188         # this counter will feed Progress along the 'test cases' metric
6189         counter = TrialTestCaseCounter()
6190         self.addLogObserver('stdio', counter)
6191         self.progressMetrics += ('tests',)
6192 @end example
6194 This creates a TrialTestCaseCounter and tells the step that the
6195 counter wants to watch the ``stdio'' log. The observer is
6196 automatically given a reference to the step in its @code{.step}
6197 attribute.
6199 @subheading A Somewhat Whimsical Example
6201 Let's say that we've got some snazzy new unit-test framework called
6202 Framboozle. It's the hottest thing since sliced bread. It slices, it
6203 dices, it runs unit tests like there's no tomorrow. Plus if your unit
6204 tests fail, you can use its name for a Web 2.1 startup company, make
6205 millions of dollars, and hire engineers to fix the bugs for you, while
6206 you spend your afternoons lazily hang-gliding along a scenic pacific
6207 beach, blissfully unconcerned about the state of your
6208 tests.@footnote{framboozle.com is still available. Remember, I get 10%
6209 :).}
6211 To run a Framboozle-enabled test suite, you just run the 'framboozler'
6212 command from the top of your source code tree. The 'framboozler'
6213 command emits a bunch of stuff to stdout, but the most interesting bit
6214 is that it emits the line "FNURRRGH!" every time it finishes running a
6215 test case@footnote{Framboozle gets very excited about running unit
6216 tests.}. You'd like to have a test-case counting LogObserver that
6217 watches for these lines and counts them, because counting them will
6218 help the buildbot more accurately calculate how long the build will
6219 take, and this will let you know exactly how long you can sneak out of
6220 the office for your hang-gliding lessons without anyone noticing that
6221 you're gone.
6223 This will involve writing a new BuildStep (probably named
6224 "Framboozle") which inherits from ShellCommand. The BuildStep class
6225 definition itself will look something like this:
6227 @example
6228 # START
6229 from buildbot.steps.shell import ShellCommand
6230 from buildbot.process.buildstep import LogLineObserver
6232 class FNURRRGHCounter(LogLineObserver):
6233     numTests = 0
6234     def outLineReceived(self, line):
6235         if "FNURRRGH!" in line:
6236             self.numTests += 1
6237             self.step.setProgress('tests', self.numTests)
6239 class Framboozle(ShellCommand):
6240     command = ["framboozler"]
6242     def __init__(self, **kwargs):
6243         ShellCommand.__init__(self, **kwargs)   # always upcall!
6244         counter = FNURRRGHCounter())
6245         self.addLogObserver('stdio', counter)
6246         self.progressMetrics += ('tests',)
6247 # FINISH
6248 @end example
6250 So that's the code that we want to wind up using. How do we actually
6251 deploy it?
6253 You have a couple of different options.
6255 Option 1: The simplest technique is to simply put this text
6256 (everything from START to FINISH) in your master.cfg file, somewhere
6257 before the BuildFactory definition where you actually use it in a
6258 clause like:
6260 @example
6261 f = BuildFactory()
6262 f.addStep(SVN(svnurl="stuff"))
6263 f.addStep(Framboozle())
6264 @end example
6266 Remember that master.cfg is secretly just a python program with one
6267 job: populating the BuildmasterConfig dictionary. And python programs
6268 are allowed to define as many classes as they like. So you can define
6269 classes and use them in the same file, just as long as the class is
6270 defined before some other code tries to use it.
6272 This is easy, and it keeps the point of definition very close to the
6273 point of use, and whoever replaces you after that unfortunate
6274 hang-gliding accident will appreciate being able to easily figure out
6275 what the heck this stupid "Framboozle" step is doing anyways. The
6276 downside is that every time you reload the config file, the Framboozle
6277 class will get redefined, which means that the buildmaster will think
6278 that you've reconfigured all the Builders that use it, even though
6279 nothing changed. Bleh.
6281 Option 2: Instead, we can put this code in a separate file, and import
6282 it into the master.cfg file just like we would the normal buildsteps
6283 like ShellCommand and SVN.
6285 Create a directory named ~/lib/python, put everything from START to
6286 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
6288 @example
6289  PYTHONPATH=~/lib/python buildbot start MASTERDIR
6290 @end example
6292 or use the @file{Makefile.buildbot} to control the way
6293 @command{buildbot start} works. Or add something like this to
6294 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
6296 @example
6297  export PYTHONPATH=~/lib/python
6298 @end example
6300 Once we've done this, our master.cfg can look like:
6302 @example
6303 from framboozle import Framboozle
6304 f = BuildFactory()
6305 f.addStep(SVN(svnurl="stuff"))
6306 f.addStep(Framboozle())
6307 @end example
6311 @example
6312 import framboozle
6313 f = BuildFactory()
6314 f.addStep(SVN(svnurl="stuff"))
6315 f.addStep(framboozle.Framboozle())
6316 @end example
6318 (check out the python docs for details about how "import" and "from A
6319 import B" work).
6321 What we've done here is to tell python that every time it handles an
6322 "import" statement for some named module, it should look in our
6323 ~/lib/python/ for that module before it looks anywhere else. After our
6324 directories, it will try in a bunch of standard directories too
6325 (including the one where buildbot is installed). By setting the
6326 PYTHONPATH environment variable, you can add directories to the front
6327 of this search list.
6329 Python knows that once it "import"s a file, it doesn't need to
6330 re-import it again. This means that reconfiguring the buildmaster
6331 (with "buildbot reconfig", for example) won't make it think the
6332 Framboozle class has changed every time, so the Builders that use it
6333 will not be spuriously restarted. On the other hand, you either have
6334 to start your buildmaster in a slightly weird way, or you have to
6335 modify your environment to set the PYTHONPATH variable.
6338 Option 3: Install this code into a standard python library directory
6340 Find out what your python's standard include path is by asking it:
6342 @example
6343 80:warner@@luther% python
6344 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46)
6345 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
6346 Type "help", "copyright", "credits" or "license" for more information.
6347 >>> import sys
6348 >>> import pprint
6349 >>> pprint.pprint(sys.path)
6350 ['',
6351  '/usr/lib/python24.zip',
6352  '/usr/lib/python2.4',
6353  '/usr/lib/python2.4/plat-linux2',
6354  '/usr/lib/python2.4/lib-tk',
6355  '/usr/lib/python2.4/lib-dynload',
6356  '/usr/local/lib/python2.4/site-packages',
6357  '/usr/lib/python2.4/site-packages',
6358  '/usr/lib/python2.4/site-packages/Numeric',
6359  '/var/lib/python-support/python2.4',
6360  '/usr/lib/site-python']
6361 @end example
6363 In this case, putting the code into
6364 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
6365 fine. We can use the same master.cfg "import framboozle" statement as
6366 in Option 2. By putting it in a standard include directory (instead of
6367 the decidedly non-standard ~/lib/python), we don't even have to set
6368 PYTHONPATH to anything special. The downside is that you probably have
6369 to be root to write to one of those standard include directories.
6372 Option 4: Submit the code for inclusion in the Buildbot distribution
6374 Make a fork of buildbot on http://github.com/djmitche/buildbot or post a patch
6375 in a bug at http://buildbot.net.  In either case, post a note about your patch
6376 to the mailing list, so others can provide feedback and, eventually, commit it.
6378 @example
6379 from buildbot.steps import framboozle
6380 f = BuildFactory()
6381 f.addStep(SVN(svnurl="stuff"))
6382 f.addStep(framboozle.Framboozle())
6383 @end example
6385 And then you don't even have to install framboozle.py anywhere on your
6386 system, since it will ship with Buildbot. You don't have to be root,
6387 you don't have to set PYTHONPATH. But you do have to make a good case
6388 for Framboozle being worth going into the main distribution, you'll
6389 probably have to provide docs and some unit test cases, you'll need to
6390 figure out what kind of beer the author likes, and then you'll have to
6391 wait until the next release. But in some environments, all this is
6392 easier than getting root on your buildmaster box, so the tradeoffs may
6393 actually be worth it.
6397 Putting the code in master.cfg (1) makes it available to that
6398 buildmaster instance. Putting it in a file in a personal library
6399 directory (2) makes it available for any buildmasters you might be
6400 running. Putting it in a file in a system-wide shared library
6401 directory (3) makes it available for any buildmasters that anyone on
6402 that system might be running. Getting it into the buildbot's upstream
6403 repository (4) makes it available for any buildmasters that anyone in
6404 the world might be running. It's all a matter of how widely you want
6405 to deploy that new class.
6409 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
6410 @subsubsection BuildStep URLs
6412 @cindex links
6413 @cindex BuildStep URLs
6414 @cindex addURL
6416 Each BuildStep has a collection of ``links''. Like its collection of
6417 LogFiles, each link has a name and a target URL. The web status page
6418 creates HREFs for each link in the same box as it does for LogFiles,
6419 except that the target of the link is the external URL instead of an
6420 internal link to a page that shows the contents of the LogFile.
6422 These external links can be used to point at build information hosted
6423 on other servers. For example, the test process might produce an
6424 intricate description of which tests passed and failed, or some sort
6425 of code coverage data in HTML form, or a PNG or GIF image with a graph
6426 of memory usage over time. The external link can provide an easy way
6427 for users to navigate from the buildbot's status page to these
6428 external web sites or file servers. Note that the step itself is
6429 responsible for insuring that there will be a document available at
6430 the given URL (perhaps by using @command{scp} to copy the HTML output
6431 to a @file{~/public_html/} directory on a remote web server). Calling
6432 @code{addURL} does not magically populate a web server.
6434 To set one of these links, the BuildStep should call the @code{addURL}
6435 method with the name of the link and the target URL. Multiple URLs can
6436 be set.
6438 In this example, we assume that the @command{make test} command causes
6439 a collection of HTML files to be created and put somewhere on the
6440 coverage.example.org web server, in a filename that incorporates the
6441 build number.
6443 @example
6444 class TestWithCodeCoverage(BuildStep):
6445     command = ["make", "test",
6446                WithProperties("buildnum=%s" % "buildnumber")]
6448     def createSummary(self, log):
6449         buildnumber = self.getProperty("buildnumber")
6450         url = "http://coverage.example.org/builds/%s.html" % buildnumber
6451         self.addURL("coverage", url)
6452 @end example
6454 You might also want to extract the URL from some special message
6455 output by the build process itself:
6457 @example
6458 class TestWithCodeCoverage(BuildStep):
6459     command = ["make", "test",
6460                WithProperties("buildnum=%s" % "buildnumber")]
6462     def createSummary(self, log):
6463         output = StringIO(log.getText())
6464         for line in output.readlines():
6465             if line.startswith("coverage-url:"):
6466                 url = line[len("coverage-url:"):].strip()
6467                 self.addURL("coverage", url)
6468                 return
6469 @end example
6471 Note that a build process which emits both stdout and stderr might
6472 cause this line to be split or interleaved between other lines. It
6473 might be necessary to restrict the getText() call to only stdout with
6474 something like this:
6476 @example
6477         output = StringIO("".join([c[1]
6478                                    for c in log.getChunks()
6479                                    if c[0] == LOG_CHANNEL_STDOUT]))
6480 @end example
6482 Of course if the build is run under a PTY, then stdout and stderr will
6483 be merged before the buildbot ever sees them, so such interleaving
6484 will be unavoidable.
6487 @node Interlocks, Build Factories, Build Steps, Build Process
6488 @section Interlocks
6490 @cindex locks
6491 @slindex buildbot.locks.MasterLock
6492 @slindex buildbot.locks.SlaveLock
6493 @slindex buildbot.locks.LockAccess
6495 Until now, we assumed that a master can run builds at any slave whenever
6496 needed or desired.  Some times, you want to enforce additional constraints on
6497 builds. For reasons like limited network bandwidth, old slave machines, or a
6498 self-willed data base server, you may want to limit the number of builds (or
6499 build steps) that can access a resource.
6501 The mechanism used by Buildbot is known as the read/write lock.@footnote{See
6502 http://en.wikipedia.org/wiki/Read/write_lock_pattern for more information.} It
6503 allows either many readers or a single writer but not a combination of readers
6504 and writers. The general lock has been modified and extended for use in
6505 Buildbot. Firstly, the general lock allows an infinite number of readers. In
6506 Buildbot, we often want to put an upper limit on the number of readers, for
6507 example allowing two out of five possible builds at the same time. To do this,
6508 the lock counts the number of active readers. Secondly, the terms @emph{read
6509 mode} and @emph{write mode} are confusing in Buildbot context. They have been
6510 replaced by @emph{counting mode} (since the lock counts them) and @emph{exclusive
6511 mode}.  As a result of these changes, locks in Buildbot allow a number of
6512 builds (upto some fixed number) in counting mode, or they allow one build in
6513 exclusive mode.
6515 Often, not all slaves are equal. To allow for this situation, Buildbot allows
6516 to have a separate upper limit on the count for each slave. In this way, you
6517 can have at most 3 concurrent builds at a fast slave, 2 at a slightly older
6518 slave, and 1 at all other slaves.
6520 The final thing you can specify when you introduce a new lock is its scope.
6521 Some constraints are global -- they must be enforced over all slaves. Other
6522 constraints are local to each slave.  A @emph{master lock} is used for the
6523 global constraints. You can ensure for example that at most one build (of all
6524 builds running at all slaves) accesses the data base server. With a
6525 @emph{slave lock} you can add a limit local to each slave. With such a lock,
6526 you can for example enforce an upper limit to the number of active builds at a
6527 slave, like above.
6529 Time for a few examples. Below a master lock is defined to protect a data base,
6530 and a slave lock is created to limit the number of builds at each slave.
6532 @example
6533 from buildbot import locks
6535 db_lock = locks.MasterLock("database")
6536 build_lock = locks.SlaveLock("slave_builds",
6537                              maxCount = 1,
6538                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6539 @end example
6541 After importing locks from buildbot, @code{db_lock} is defined to be a master
6542 lock. The @code{"database"} string is used for uniquely identifying the lock.
6543 At the next line, a slave lock called @code{build_lock} is created. It is
6544 identified by the @code{"slave_builds"} string. Since the requirements of the
6545 lock are a bit more complicated, two optional arguments are also specified. The
6546 @code{maxCount} parameter sets the default limit for builds in counting mode to
6547 @code{1}. For the slave called @code{'fast'} however, we want to have at most
6548 three builds, and for the slave called @code{'new'} the upper limit is two
6549 builds running at the same time.
6551 The next step is using the locks in builds.  Buildbot allows a lock to be used
6552 during an entire build (from beginning to end), or only during a single build
6553 step. In the latter case, the lock is claimed for use just before the step
6554 starts, and released again when the step ends. To prevent
6555 deadlocks,@footnote{Deadlock is the situation where two or more slaves each
6556 hold a lock in exclusive mode, and in addition want to claim the lock held by
6557 the other slave exclusively as well. Since locks allow at most one exclusive
6558 user, both slaves will wait forever.} it is not possible to claim or release
6559 locks at other times.
6561 To use locks, you should add them with a @code{locks} argument.
6562 Each use of a lock is either in counting mode (that is, possibly shared with
6563 other builds) or in exclusive mode. A build or build step proceeds only when it
6564 has acquired all locks. If a build or step needs a lot of locks, it may be
6565 starved@footnote{Starving is the situation that only a few locks are available,
6566 and they are immediately grabbed by another build. As a result, it may take a
6567 long time before all locks needed by the starved build are free at the same
6568 time.} by other builds that need fewer locks.
6570 To illustrate use of locks, a few examples.
6572 @example
6573 from buildbot import locks
6574 from buildbot.steps import source, shell
6575 from buildbot.process import factory
6577 db_lock = locks.MasterLock("database")
6578 build_lock = locks.SlaveLock("slave_builds",
6579                              maxCount = 1,
6580                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6582 f = factory.BuildFactory()
6583 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
6584 f.addStep(shell.ShellCommand(command="make all"))
6585 f.addStep(shell.ShellCommand(command="make test",
6586                              locks=[db_lock.access('exclusive')]))
6588 b1 = @{'name': 'full1', 'slavename': 'fast',  'builddir': 'f1', 'factory': f,
6589        'locks': [build_lock.access('counting')] @}
6591 b2 = @{'name': 'full2', 'slavename': 'new',   'builddir': 'f2', 'factory': f.
6592        'locks': [build_lock.access('counting')] @}
6594 b3 = @{'name': 'full3', 'slavename': 'old',   'builddir': 'f3', 'factory': f.
6595        'locks': [build_lock.access('counting')] @}
6597 b4 = @{'name': 'full4', 'slavename': 'other', 'builddir': 'f4', 'factory': f.
6598        'locks': [build_lock.access('counting')] @}
6600 c['builders'] = [b1, b2, b3, b4]
6601 @end example
6603 Here we have four slaves @code{b1}, @code{b2}, @code{b3}, and @code{b4}. Each
6604 slave performs the same checkout, make, and test build step sequence.
6605 We want to enforce that at most one test step is executed between all slaves due
6606 to restrictions with the data base server. This is done by adding the
6607 @code{locks=} parameter with the third step. It takes a list of locks with their
6608 access mode. In this case only the @code{db_lock} is needed. The exclusive
6609 access mode is used to ensure there is at most one slave that executes the test
6610 step.
6612 In addition to exclusive accessing the data base, we also want slaves to stay
6613 responsive even under the load of a large number of builds being triggered.
6614 For this purpose, the slave lock called @code{build_lock} is defined. Since
6615 the restraint holds for entire builds, the lock is specified in the builder
6616 with @code{'locks': [build_lock.access('counting')]}.
6617 @node Build Factories,  , Interlocks, Build Process
6618 @section Build Factories
6621 Each Builder is equipped with a ``build factory'', which is
6622 responsible for producing the actual @code{Build} objects that perform
6623 each build. This factory is created in the configuration file, and
6624 attached to a Builder through the @code{factory} element of its
6625 dictionary.
6627 The standard @code{BuildFactory} object creates @code{Build} objects
6628 by default. These Builds will each execute a collection of BuildSteps
6629 in a fixed sequence. Each step can affect the results of the build,
6630 but in general there is little intelligence to tie the different steps
6631 together. You can create subclasses of @code{Build} to implement more
6632 sophisticated build processes, and then use a subclass of
6633 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
6634 create instances of your new Build subclass.
6637 @menu
6638 * BuildStep Objects::
6639 * BuildFactory::
6640 * Process-Specific build factories::
6641 @end menu
6643 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
6644 @subsection BuildStep Objects
6646 The steps used by these builds are all subclasses of @code{BuildStep}.
6647 The standard ones provided with Buildbot are documented later,
6648 @xref{Build Steps}. You can also write your own subclasses to use in
6649 builds.
6651 The basic behavior for a @code{BuildStep} is to:
6653 @itemize @bullet
6654 @item
6655 run for a while, then stop
6656 @item
6657 possibly invoke some RemoteCommands on the attached build slave
6658 @item
6659 possibly produce a set of log files
6660 @item
6661 finish with a status described by one of four values defined in
6662 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
6663 @item
6664 provide a list of short strings to describe the step
6665 @item
6666 define a color (generally green, orange, or red) with which the
6667 step should be displayed
6668 @end itemize
6671 More sophisticated steps may produce additional information and
6672 provide it to later build steps, or store it in the factory to provide
6673 to later builds.
6676 @menu
6677 * BuildFactory Attributes::
6678 * Quick builds::
6679 @end menu
6681 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
6682 @subsection BuildFactory
6684 @bfindex buildbot.process.factory.BuildFactory
6685 @bfindex buildbot.process.factory.BasicBuildFactory
6686 @c TODO: what is BasicSVN anyway?
6687 @bfindex buildbot.process.factory.BasicSVN
6689 The default @code{BuildFactory}, provided in the
6690 @code{buildbot.process.factory} module, contains an internal list of
6691 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
6692 tuples for each. These specification tuples are constructed when the
6693 config file is read, by asking the instances passed to @code{addStep}
6694 for their subclass and arguments.
6696 When asked to create a Build, the @code{BuildFactory} puts a copy of
6697 the list of step specifications into the new Build object. When the
6698 Build is actually started, these step specifications are used to
6699 create the actual set of BuildSteps, which are then executed one at a
6700 time. This serves to give each Build an independent copy of each step.
6701 For example, a build which consists of a CVS checkout followed by a
6702 @code{make build} would be constructed as follows:
6704 @example
6705 from buildbot.steps import source, shell
6706 from buildbot.process import factory
6708 f = factory.BuildFactory()
6709 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
6710 f.addStep(shell.Compile(command=["make", "build"]))
6711 @end example
6713 (To support config files from buildbot-0.7.5 and earlier,
6714 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
6715 command=["make","build"])} form, although its use is discouraged
6716 because then the @code{Compile} step doesn't get to validate or
6717 complain about its arguments until build time. The modern
6718 pass-by-instance approach allows this validation to occur while the
6719 config file is being loaded, where the admin has a better chance of
6720 noticing problems).
6722 It is also possible to pass a list of steps into the
6723 @code{BuildFactory} when it is created. Using @code{addStep} is
6724 usually simpler, but there are cases where is is more convenient to
6725 create the list of steps ahead of time.:
6727 @example
6728 from buildbot.steps import source, shell
6729 from buildbot.process import factory
6731 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
6732              shell.Compile(command=["make", "build"]),
6733             ]
6734 f = factory.BuildFactory(all_steps)
6735 @end example
6738 Each step can affect the build process in the following ways:
6740 @itemize @bullet
6741 @item
6742 If the step's @code{haltOnFailure} attribute is True, then a failure
6743 in the step (i.e. if it completes with a result of FAILURE) will cause
6744 the whole build to be terminated immediately: no further steps will be
6745 executed, with the exception of steps with @code{alwaysRun} set to
6746 True. @code{haltOnFailure} is useful for setup steps upon which the
6747 rest of the build depends: if the CVS checkout or @code{./configure}
6748 process fails, there is no point in trying to compile or test the
6749 resulting tree.
6751 @item
6752 If the step's @code{alwaysRun} attribute is True, then it will always
6753 be run, regardless of if previous steps have failed. This is useful
6754 for cleanup steps that should always be run to return the build
6755 directory or build slave into a good state.
6757 @item
6758 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
6759 then a result of FAILURE or WARNINGS will mark the build as a whole as
6760 FAILED. However, the remaining steps will still be executed. This is
6761 appropriate for things like multiple testing steps: a failure in any
6762 one of them will indicate that the build has failed, however it is
6763 still useful to run them all to completion.
6765 @item
6766 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
6767 is set, then a result of FAILURE or WARNINGS will mark the build as
6768 having WARNINGS, and the remaining steps will still be executed. This
6769 may be appropriate for certain kinds of optional build or test steps.
6770 For example, a failure experienced while building documentation files
6771 should be made visible with a WARNINGS result but not be serious
6772 enough to warrant marking the whole build with a FAILURE.
6774 @end itemize
6776 In addition, each Step produces its own results, may create logfiles,
6777 etc. However only the flags described above have any effect on the
6778 build as a whole.
6780 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
6781 reasonably appropriate flags set on them already. For example, without
6782 a source tree there is no point in continuing the build, so the
6783 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
6784 in @file{buildbot/steps/*.py} to see how the other Steps are
6785 marked.
6787 Each Step is created with an additional @code{workdir} argument that
6788 indicates where its actions should take place. This is specified as a
6789 subdirectory of the slave builder's base directory, with a default
6790 value of @code{build}. This is only implemented as a step argument (as
6791 opposed to simply being a part of the base directory) because the
6792 CVS/SVN steps need to perform their checkouts from the parent
6793 directory.
6795 @menu
6796 * BuildFactory Attributes::
6797 * Quick builds::
6798 @end menu
6800 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
6801 @subsubsection BuildFactory Attributes
6803 Some attributes from the BuildFactory are copied into each Build.
6805 @cindex treeStableTimer
6807 @table @code
6808 @item useProgress
6809 (defaults to True): if True, the buildmaster keeps track of how long
6810 each step takes, so it can provide estimates of how long future builds
6811 will take. If builds are not expected to take a consistent amount of
6812 time (such as incremental builds in which a random set of files are
6813 recompiled or tested each time), this should be set to False to
6814 inhibit progress-tracking.
6816 @end table
6819 @node Quick builds,  , BuildFactory Attributes, BuildFactory
6820 @subsubsection Quick builds
6822 @bfindex buildbot.process.factory.QuickBuildFactory
6824 The difference between a ``full build'' and a ``quick build'' is that
6825 quick builds are generally done incrementally, starting with the tree
6826 where the previous build was performed. That simply means that the
6827 source-checkout step should be given a @code{mode='update'} flag, to
6828 do the source update in-place.
6830 In addition to that, the @code{useProgress} flag should be set to
6831 False. Incremental builds will (or at least the ought to) compile as
6832 few files as necessary, so they will take an unpredictable amount of
6833 time to run. Therefore it would be misleading to claim to predict how
6834 long the build will take.
6837 @node Process-Specific build factories,  , BuildFactory, Build Factories
6838 @subsection Process-Specific build factories
6840 Many projects use one of a few popular build frameworks to simplify
6841 the creation and maintenance of Makefiles or other compilation
6842 structures. Buildbot provides several pre-configured BuildFactory
6843 subclasses which let you build these projects with a minimum of fuss.
6845 @menu
6846 * GNUAutoconf::
6847 * CPAN::
6848 * Python distutils::
6849 * Python/Twisted/trial projects::
6850 @end menu
6852 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
6853 @subsubsection GNUAutoconf
6855 @bfindex buildbot.process.factory.GNUAutoconf
6857 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
6858 software portability tool, intended to make it possible to write
6859 programs in C (and other languages) which will run on a variety of
6860 UNIX-like systems. Most GNU software is built using autoconf. It is
6861 frequently used in combination with GNU automake. These tools both
6862 encourage a build process which usually looks like this:
6864 @example
6865 % CONFIG_ENV=foo ./configure --with-flags
6866 % make all
6867 % make check
6868 # make install
6869 @end example
6871 (except of course the Buildbot always skips the @code{make install}
6872 part).
6874 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
6875 designed to build projects which use GNU autoconf and/or automake. The
6876 configuration environment variables, the configure flags, and command
6877 lines used for the compile and test are all configurable, in general
6878 the default values will be suitable.
6880 Example:
6882 @example
6883 # use the s() convenience function defined earlier
6884 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
6885                         flags=["--disable-nls"])
6886 @end example
6888 Required Arguments:
6890 @table @code
6891 @item source
6892 This argument must be a step specification tuple that provides a
6893 BuildStep to generate the source tree.
6894 @end table
6896 Optional Arguments:
6898 @table @code
6899 @item configure
6900 The command used to configure the tree. Defaults to
6901 @code{./configure}. Accepts either a string or a list of shell argv
6902 elements.
6904 @item configureEnv
6905 The environment used for the initial configuration step. This accepts
6906 a dictionary which will be merged into the buildslave's normal
6907 environment. This is commonly used to provide things like
6908 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
6909 Defaults to an empty dictionary.
6911 @item configureFlags
6912 A list of flags to be appended to the argument list of the configure
6913 command. This is commonly used to enable or disable specific features
6914 of the autoconf-controlled package, like @code{["--without-x"]} to
6915 disable windowing support. Defaults to an empty list.
6917 @item compile
6918 this is a shell command or list of argv values which is used to
6919 actually compile the tree. It defaults to @code{make all}. If set to
6920 None, the compile step is skipped.
6922 @item test
6923 this is a shell command or list of argv values which is used to run
6924 the tree's self-tests. It defaults to @code{make check}. If set to
6925 None, the test step is skipped.
6927 @end table
6930 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
6931 @subsubsection CPAN
6933 @bfindex buildbot.process.factory.CPAN
6935 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
6936 archive use the @code{MakeMaker} module to provide configuration,
6937 build, and test services. The standard build routine for these modules
6938 looks like:
6940 @example
6941 % perl Makefile.PL
6942 % make
6943 % make test
6944 # make install
6945 @end example
6947 (except again Buildbot skips the install step)
6949 Buildbot provides a @code{CPAN} factory to compile and test these
6950 projects.
6953 Arguments:
6954 @table @code
6955 @item source
6956 (required): A step specification tuple, like that used by GNUAutoconf.
6958 @item perl
6959 A string which specifies the @code{perl} executable to use. Defaults
6960 to just @code{perl}.
6962 @end table
6965 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
6966 @subsubsection Python distutils
6968 @bfindex buildbot.process.factory.Distutils
6970 Most Python modules use the @code{distutils} package to provide
6971 configuration and build services. The standard build process looks
6972 like:
6974 @example
6975 % python ./setup.py build
6976 % python ./setup.py install
6977 @end example
6979 Unfortunately, although Python provides a standard unit-test framework
6980 named @code{unittest}, to the best of my knowledge @code{distutils}
6981 does not provide a standardized target to run such unit tests. (Please
6982 let me know if I'm wrong, and I will update this factory.)
6984 The @code{Distutils} factory provides support for running the build
6985 part of this process. It accepts the same @code{source=} parameter as
6986 the other build factories.
6989 Arguments:
6990 @table @code
6991 @item source
6992 (required): A step specification tuple, like that used by GNUAutoconf.
6994 @item python
6995 A string which specifies the @code{python} executable to use. Defaults
6996 to just @code{python}.
6998 @item test
6999 Provides a shell command which runs unit tests. This accepts either a
7000 string or a list. The default value is None, which disables the test
7001 step (since there is no common default command to run unit tests in
7002 distutils modules).
7004 @end table
7007 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
7008 @subsubsection Python/Twisted/trial projects
7010 @bfindex buildbot.process.factory.Trial
7011 @c TODO: document these steps better
7012 @bsindex buildbot.steps.python_twisted.HLint
7013 @bsindex buildbot.steps.python_twisted.Trial
7014 @bsindex buildbot.steps.python_twisted.ProcessDocs
7015 @bsindex buildbot.steps.python_twisted.BuildDebs
7016 @bsindex buildbot.steps.python_twisted.RemovePYCs
7018 Twisted provides a unit test tool named @code{trial} which provides a
7019 few improvements over Python's built-in @code{unittest} module. Many
7020 python projects which use Twisted for their networking or application
7021 services also use trial for their unit tests. These modules are
7022 usually built and tested with something like the following:
7024 @example
7025 % python ./setup.py build
7026 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
7027 % python ./setup.py install
7028 @end example
7030 Unfortunately, the @file{build/lib} directory into which the
7031 built/copied .py files are placed is actually architecture-dependent,
7032 and I do not yet know of a simple way to calculate its value. For many
7033 projects it is sufficient to import their libraries ``in place'' from
7034 the tree's base directory (@code{PYTHONPATH=.}).
7036 In addition, the @var{PROJECTNAME} value where the test files are
7037 located is project-dependent: it is usually just the project's
7038 top-level library directory, as common practice suggests the unit test
7039 files are put in the @code{test} sub-module. This value cannot be
7040 guessed, the @code{Trial} class must be told where to find the test
7041 files.
7043 The @code{Trial} class provides support for building and testing
7044 projects which use distutils and trial. If the test module name is
7045 specified, trial will be invoked. The library path used for testing
7046 can also be set.
7048 One advantage of trial is that the Buildbot happens to know how to
7049 parse trial output, letting it identify which tests passed and which
7050 ones failed. The Buildbot can then provide fine-grained reports about
7051 how many tests have failed, when individual tests fail when they had
7052 been passing previously, etc.
7054 Another feature of trial is that you can give it a series of source
7055 .py files, and it will search them for special @code{test-case-name}
7056 tags that indicate which test cases provide coverage for that file.
7057 Trial can then run just the appropriate tests. This is useful for
7058 quick builds, where you want to only run the test cases that cover the
7059 changed functionality.
7061 Arguments:
7062 @table @code
7063 @item source
7064 (required): A step specification tuple, like that used by GNUAutoconf.
7066 @item buildpython
7067 A list (argv array) of strings which specifies the @code{python}
7068 executable to use when building the package. Defaults to just
7069 @code{['python']}. It may be useful to add flags here, to supress
7070 warnings during compilation of extension modules. This list is
7071 extended with @code{['./setup.py', 'build']} and then executed in a
7072 ShellCommand.
7074 @item testpath
7075 Provides a directory to add to @code{PYTHONPATH} when running the unit
7076 tests, if tests are being run. Defaults to @code{.} to include the
7077 project files in-place. The generated build library is frequently
7078 architecture-dependent, but may simply be @file{build/lib} for
7079 pure-python modules.
7081 @item trialpython
7082 Another list of strings used to build the command that actually runs
7083 trial. This is prepended to the contents of the @code{trial} argument
7084 below. It may be useful to add @code{-W} flags here to supress
7085 warnings that occur while tests are being run. Defaults to an empty
7086 list, meaning @code{trial} will be run without an explicit
7087 interpreter, which is generally what you want if you're using
7088 @file{/usr/bin/trial} instead of, say, the @file{./bin/trial} that
7089 lives in the Twisted source tree.
7091 @item trial
7092 provides the name of the @code{trial} command. It is occasionally
7093 useful to use an alternate executable, such as @code{trial2.2} which
7094 might run the tests under an older version of Python. Defaults to
7095 @code{trial}.
7097 @item tests
7098 Provides a module name or names which contain the unit tests for this
7099 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
7100 list of strings. Defaults to None, indicating that no tests should be
7101 run. You must either set this or @code{useTestCaseNames} to do anyting
7102 useful with the Trial factory.
7104 @item useTestCaseNames
7105 Tells the Step to provide the names of all changed .py files to trial,
7106 so it can look for test-case-name tags and run just the matching test
7107 cases. Suitable for use in quick builds. Defaults to False.
7109 @item randomly
7110 If @code{True}, tells Trial (with the @code{--random=0} argument) to
7111 run the test cases in random order, which sometimes catches subtle
7112 inter-test dependency bugs. Defaults to @code{False}.
7114 @item recurse
7115 If @code{True}, tells Trial (with the @code{--recurse} argument) to
7116 look in all subdirectories for additional test cases. It isn't clear
7117 to me how this works, but it may be useful to deal with the
7118 unknown-PROJECTNAME problem described above, and is currently used in
7119 the Twisted buildbot to accomodate the fact that test cases are now
7120 distributed through multiple twisted.SUBPROJECT.test directories.
7122 @end table
7124 Unless one of @code{trialModule} or @code{useTestCaseNames}
7125 are set, no tests will be run.
7127 Some quick examples follow. Most of these examples assume that the
7128 target python code (the ``code under test'') can be reached directly
7129 from the root of the target tree, rather than being in a @file{lib/}
7130 subdirectory.
7132 @example
7133 #  Trial(source, tests="toplevel.test") does:
7134 #   python ./setup.py build
7135 #   PYTHONPATH=. trial -to toplevel.test
7137 #  Trial(source, tests=["toplevel.test", "other.test"]) does:
7138 #   python ./setup.py build
7139 #   PYTHONPATH=. trial -to toplevel.test other.test
7141 #  Trial(source, useTestCaseNames=True) does:
7142 #   python ./setup.py build
7143 #   PYTHONPATH=. trial -to --testmodule=foo/bar.py..  (from Changes)
7145 #  Trial(source, buildpython=["python2.3", "-Wall"], tests="foo.tests"):
7146 #   python2.3 -Wall ./setup.py build
7147 #   PYTHONPATH=. trial -to foo.tests
7149 #  Trial(source, trialpython="python2.3", trial="/usr/bin/trial",
7150 #        tests="foo.tests") does:
7151 #   python2.3 -Wall ./setup.py build
7152 #   PYTHONPATH=. python2.3 /usr/bin/trial -to foo.tests
7154 # For running trial out of the tree being tested (only useful when the
7155 # tree being built is Twisted itself):
7156 #  Trial(source, trialpython=["python2.3", "-Wall"], trial="./bin/trial",
7157 #        tests="foo.tests") does:
7158 #   python2.3 -Wall ./setup.py build
7159 #   PYTHONPATH=. python2.3 -Wall ./bin/trial -to foo.tests
7160 @end example
7162 If the output directory of @code{./setup.py build} is known, you can
7163 pull the python code from the built location instead of the source
7164 directories. This should be able to handle variations in where the
7165 source comes from, as well as accomodating binary extension modules:
7167 @example
7168 # Trial(source,tests="toplevel.test",testpath='build/lib.linux-i686-2.3')
7169 # does:
7170 #  python ./setup.py build
7171 #  PYTHONPATH=build/lib.linux-i686-2.3 trial -to toplevel.test
7172 @end example
7175 @node Status Delivery, Command-line tool, Build Process, Top
7176 @chapter Status Delivery
7178 More details are available in the docstrings for each class, use a
7179 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
7180 Most status delivery objects take a @code{categories=} argument, which
7181 can contain a list of ``category'' names: in this case, it will only
7182 show status for Builders that are in one of the named categories.
7184 (implementor's note: each of these objects should be a
7185 service.MultiService which will be attached to the BuildMaster object
7186 when the configuration is processed. They should use
7187 @code{self.parent.getStatus()} to get access to the top-level IStatus
7188 object, either inside @code{startService} or later. They may call
7189 @code{status.subscribe()} in @code{startService} to receive
7190 notifications of builder events, in which case they must define
7191 @code{builderAdded} and related methods. See the docstrings in
7192 @file{buildbot/interfaces.py} for full details.)
7194 @menu
7195 * WebStatus::
7196 * MailNotifier::
7197 * IRC Bot::
7198 * PBListener::
7199 * Writing New Status Plugins::
7200 @end menu
7202 @c @node Email Delivery,  , Status Delivery, Status Delivery
7203 @c @subsection Email Delivery
7205 @c DOCUMENT THIS
7208 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
7209 @section WebStatus
7211 @cindex WebStatus
7212 @stindex buildbot.status.web.baseweb.WebStatus
7214 The @code{buildbot.status.html.WebStatus} status target runs a small
7215 web server inside the buildmaster. You can point a browser at this web
7216 server and retrieve information about every build the buildbot knows
7217 about, as well as find out what the buildbot is currently working on.
7219 The first page you will see is the ``Welcome Page'', which contains
7220 links to all the other useful pages. This page is simply served from
7221 the @file{public_html/index.html} file in the buildmaster's base
7222 directory, where it is created by the @command{buildbot create-master}
7223 command along with the rest of the buildmaster.
7225 The most complex resource provided by @code{WebStatus} is the
7226 ``Waterfall Display'', which shows a time-based chart of events. This
7227 somewhat-busy display provides detailed information about all steps of
7228 all recent builds, and provides hyperlinks to look at individual build
7229 logs and source changes. By simply reloading this page on a regular
7230 basis, you will see a complete description of everything the buildbot
7231 is currently working on.
7233 There are also pages with more specialized information. For example,
7234 there is a page which shows the last 20 builds performed by the
7235 buildbot, one line each. Each line is a link to detailed information
7236 about that build. By adding query arguments to the URL used to reach
7237 this page, you can narrow the display to builds that involved certain
7238 branches, or which ran on certain Builders. These pages are described
7239 in great detail below.
7242 When the buildmaster is created, a subdirectory named
7243 @file{public_html/} is created in its base directory. By default, @code{WebStatus}
7244 will serve files from this directory: for example, when a user points
7245 their browser at the buildbot's @code{WebStatus} URL, they will see
7246 the contents of the @file{public_html/index.html} file. Likewise,
7247 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
7248 @file{public_html/favicon.ico} are all useful things to have in there.
7249 The first time a buildmaster is created, the @file{public_html}
7250 directory is populated with some sample files, which you will probably
7251 want to customize for your own project. These files are all static:
7252 the buildbot does not modify them in any way as it serves them to HTTP
7253 clients.
7255 @example
7256 from buildbot.status.html import WebStatus
7257 c['status'].append(WebStatus(8080))
7258 @end example
7260 Note that the initial robots.txt file has Disallow lines for all of
7261 the dynamically-generated buildbot pages, to discourage web spiders
7262 and search engines from consuming a lot of CPU time as they crawl
7263 through the entire history of your buildbot. If you are running the
7264 buildbot behind a reverse proxy, you'll probably need to put the
7265 robots.txt file somewhere else (at the top level of the parent web
7266 server), and replace the URL prefixes in it with more suitable values.
7268 If you would like to use an alternative root directory, add the
7269 @code{public_html=..} option to the @code{WebStatus} creation:
7271 @example
7272 c['status'].append(WebStatus(8080, public_html="/var/www/buildbot"))
7273 @end example
7275 In addition, if you are familiar with twisted.web @emph{Resource
7276 Trees}, you can write code to add additional pages at places inside
7277 this web space. Just use @code{webstatus.putChild} to place these
7278 resources.
7280 The following section describes the special URLs and the status views
7281 they provide.
7284 @menu
7285 * WebStatus Configuration Parameters::
7286 * Buildbot Web Resources::
7287 * XMLRPC server::
7288 * HTML Waterfall::
7289 @end menu
7291 @node WebStatus Configuration Parameters, Buildbot Web Resources, WebStatus, WebStatus
7292 @subsection WebStatus Configuration Parameters
7294 The most common way to run a @code{WebStatus} is on a regular TCP
7295 port. To do this, just pass in the TCP port number when you create the
7296 @code{WebStatus} instance; this is called the @code{http_port} argument:
7298 @example
7299 from buildbot.status.html import WebStatus
7300 c['status'].append(WebStatus(8080))
7301 @end example
7303 The @code{http_port} argument is actually a ``strports specification''
7304 for the port that the web server should listen on. This can be a
7305 simple port number, or a string like
7306 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
7307 loopback interface, and therefore to clients running on the same
7308 host)@footnote{It may even be possible to provide SSL access by using
7309 a specification like
7310 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
7311 completely untested}.
7313 If instead (or in addition) you provide the @code{distrib_port}
7314 argument, a twisted.web distributed server will be started either on a
7315 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
7316 likely on a UNIX socket (if @code{distrib_port} is like
7317 @code{"unix:/path/to/socket"}).
7319 The @code{distrib_port} option means that, on a host with a
7320 suitably-configured twisted-web server, you do not need to consume a
7321 separate TCP port for the buildmaster's status web page. When the web
7322 server is constructed with @code{mktap web --user}, URLs that point to
7323 @code{http://host/~username/} are dispatched to a sub-server that is
7324 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
7325 such a system, it is convenient to create a dedicated @code{buildbot}
7326 user, then set @code{distrib_port} to
7327 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
7328 configuration will make the HTML status page available at
7329 @code{http://host/~buildbot/} . Suitable URL remapping can make it
7330 appear at @code{http://host/buildbot/}, and the right virtual host
7331 setup can even place it at @code{http://buildbot.host/} .
7333 The other @code{WebStatus} argument is @code{allowForce}. If set to
7334 True, then the web page will provide a ``Force Build'' button that
7335 allows visitors to manually trigger builds. This is useful for
7336 developers to re-run builds that have failed because of intermittent
7337 problems in the test suite, or because of libraries that were not
7338 installed at the time of the previous build. You may not wish to allow
7339 strangers to cause a build to run: in that case, set this to False to
7340 remove these buttons. The default value is False.
7344 @node Buildbot Web Resources, XMLRPC server, WebStatus Configuration Parameters, WebStatus
7345 @subsection Buildbot Web Resources
7347 Certain URLs are ``magic'', and the pages they serve are created by
7348 code in various classes in the @file{buildbot.status.web} package
7349 instead of being read from disk. The most common way to access these
7350 pages is for the buildmaster admin to write or modify the
7351 @file{index.html} page to contain links to them. Of course other
7352 project web pages can contain links to these buildbot pages as well.
7354 Many pages can be modified by adding query arguments to the URL. For
7355 example, a page which shows the results of the most recent build
7356 normally does this for all builders at once. But by appending
7357 ``?builder=i386'' to the end of the URL, the page will show only the
7358 results for the ``i386'' builder. When used in this way, you can add
7359 multiple ``builder='' arguments to see multiple builders. Remembering
7360 that URL query arguments are separated @emph{from each other} with
7361 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
7362 show builds for just those two Builders.
7364 The @code{branch=} query argument can be used on some pages. This
7365 filters the information displayed by that page down to only the builds
7366 or changes which involved the given branch. Use @code{branch=trunk} to
7367 reference the trunk: if you aren't intentionally using branches,
7368 you're probably using trunk. Multiple @code{branch=} arguments can be
7369 used to examine multiple branches at once (so appending
7370 @code{?branch=foo&branch=bar} to the URL will show builds involving
7371 either branch). No @code{branch=} arguments means to show builds and
7372 changes for all branches.
7374 Some pages may include the Builder name or the build number in the
7375 main part of the URL itself. For example, a page that describes Build
7376 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
7378 The table below lists all of the internal pages and the URLs that can
7379 be used to access them.
7381 NOTE: of the pages described here, @code{/slave_status_timeline} and
7382 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
7383 has only a few methods so far. Future releases will improve this.
7385 @table @code
7387 @item /waterfall
7389 This provides a chronologically-oriented display of the activity of
7390 all builders. It is the same display used by the Waterfall display.
7392 By adding one or more ``builder='' query arguments, the Waterfall is
7393 restricted to only showing information about the given Builders. By
7394 adding one or more ``branch='' query arguments, the display is
7395 restricted to showing information about the given branches. In
7396 addition, adding one or more ``category='' query arguments to the URL
7397 will limit the display to Builders that were defined with one of the
7398 given categories.
7400 A 'show_events=true' query argument causes the display to include
7401 non-Build events, like slaves attaching and detaching, as well as
7402 reconfiguration events. 'show_events=false' hides these events. The
7403 default is to show them.
7405 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
7406 arguments will control what interval of time is displayed. The default
7407 is to show the latest events, but these can be used to look at earlier
7408 periods in history. The @code{num_events=} argument also provides a
7409 limit on the size of the displayed page.
7411 The Waterfall has references to resources many of the other portions
7412 of the URL space: @file{/builders} for access to individual builds,
7413 @file{/changes} for access to information about source code changes,
7414 etc.
7416 @item /rss
7418 This provides a rss feed summarizing all failed builds. The same
7419 query-arguments used by 'waterfall' can be added to filter the
7420 feed output.
7422 @item /atom
7424 This provides an atom feed summarizing all failed builds. The same
7425 query-arguments used by 'waterfall' can be added to filter the feed
7426 output.
7428 @item /builders/$BUILDERNAME
7430 This describes the given Builder, and provides buttons to force a build.
7432 @item /builders/$BUILDERNAME/builds/$BUILDNUM
7434 This describes a specific Build.
7436 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
7438 This describes a specific BuildStep.
7440 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
7442 This provides an HTML representation of a specific logfile.
7444 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
7446 This returns the logfile as plain text, without any HTML coloring
7447 markup. It also removes the ``headers'', which are the lines that
7448 describe what command was run and what the environment variable
7449 settings were like. This maybe be useful for saving to disk and
7450 feeding to tools like 'grep'.
7452 @item /changes
7454 This provides a brief description of the ChangeSource in use
7455 (@pxref{Change Sources}).
7457 @item /changes/NN
7459 This shows detailed information about the numbered Change: who was the
7460 author, what files were changed, what revision number was represented,
7461 etc.
7463 @item /buildslaves
7465 This summarizes each BuildSlave, including which Builders are
7466 configured to use it, whether the buildslave is currently connected or
7467 not, and host information retrieved from the buildslave itself.
7469 @item /one_line_per_build
7471 This page shows one line of text for each build, merging information
7472 from all Builders@footnote{Apparently this is the same way
7473 http://buildd.debian.org displays build status}. Each line specifies
7474 the name of the Builder, the number of the Build, what revision it
7475 used, and a summary of the results. Successful builds are in green,
7476 while failing builds are in red. The date and time of the build are
7477 added to the right-hand edge of the line. The lines are ordered by
7478 build finish timestamp.
7480 One or more @code{builder=} or @code{branch=} arguments can be used to
7481 restrict the list. In addition, a @code{numbuilds=} argument will
7482 control how many lines are displayed (20 by default).
7484 @item /one_box_per_builder
7486 This page shows a small table, with one box for each Builder,
7487 containing the results of the most recent Build. It does not show the
7488 individual steps, or the current status. This is a simple summary of
7489 buildbot status: if this page is green, then all tests are passing.
7491 As with @code{/one_line_per_build}, this page will also honor
7492 @code{builder=} and @code{branch=} arguments.
7494 @item /about
7496 This page gives a brief summary of the Buildbot itself: software
7497 version, versions of some libraries that the Buildbot depends upon,
7498 etc. It also contains a link to the buildbot.net home page.
7500 @item /slave_status_timeline
7502 (note: this page has not yet been implemented)
7504 This provides a chronological display of configuration and operational
7505 events: master startup/shutdown, slave connect/disconnect, and
7506 config-file changes. When a config-file reload is abandoned because of
7507 an error in the config file, the error is displayed on this page.
7509 This page does not show any builds.
7511 @item /last_build/$BUILDERNAME/status.png
7513 This returns a PNG image that describes the results of the most recent
7514 build, which can be referenced in an IMG tag by other pages, perhaps
7515 from a completely different site. Use it as you would a webcounter.
7517 @end table
7519 There are also a set of web-status resources that are intended for use
7520 by other programs, rather than humans.
7522 @table @code
7524 @item /xmlrpc
7526 This runs an XML-RPC server which can be used to query status
7527 information about various builds. See @ref{XMLRPC server} for more
7528 details.
7530 @end table
7532 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
7533 @subsection XMLRPC server
7535 When using WebStatus, the buildbot runs an XML-RPC server at
7536 @file{/xmlrpc} that can be used by other programs to query build
7537 status. The following table lists the methods that can be invoked
7538 using this interface.
7540 @table @code
7541 @item getAllBuildsInInterval(start, stop)
7543 Return a list of builds that have completed after the 'start'
7544 timestamp and before the 'stop' timestamp. This looks at all Builders.
7546 The timestamps are integers, interpreted as standard unix timestamps
7547 (seconds since epoch).
7549 Each Build is returned as a tuple in the form: @code{(buildername,
7550 buildnumber, build_end, branchname, revision, results, text)}
7552 The buildnumber is an integer. 'build_end' is an integer (seconds
7553 since epoch) specifying when the build finished.
7555 The branchname is a string, which may be an empty string to indicate
7556 None (i.e. the default branch). The revision is a string whose meaning
7557 is specific to the VC system in use, and comes from the 'got_revision'
7558 build property. The results are expressed as a string, one of
7559 ('success', 'warnings', 'failure', 'exception'). The text is a list of
7560 short strings that ought to be joined by spaces and include slightly
7561 more data about the results of the build.
7563 @item getBuild(builder_name, build_number)
7565 Return information about a specific build.
7567 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
7568 complete information about the build. It does not include the contents
7569 of the log files, but it has just about everything else.
7571 @end table
7573 @node HTML Waterfall,  , XMLRPC server, WebStatus
7574 @subsection HTML Waterfall
7576 @cindex Waterfall
7577 @stindex buildbot.status.html.Waterfall
7579 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
7580 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
7581 This section (and the @code{Waterfall} class itself) will be removed
7582 from a future release.
7584 @example
7585 from buildbot.status import html
7586 w = html.WebStatus(http_port=8080)
7587 c['status'].append(w)
7588 @end example
7592 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
7593 @section MailNotifier
7595 @cindex email
7596 @cindex mail
7597 @stindex buildbot.status.mail.MailNotifier
7599 The buildbot can also send email when builds finish. The most common
7600 use of this is to tell developers when their change has caused the
7601 build to fail. It is also quite common to send a message to a mailing
7602 list (usually named ``builds'' or similar) about every build.
7604 The @code{MailNotifier} status target is used to accomplish this. You
7605 configure it by specifying who mail should be sent to, under what
7606 circumstances mail should be sent, and how to deliver the mail. It can
7607 be configured to only send out mail for certain builders, and only
7608 send messages when the build fails, or when the builder transitions
7609 from success to failure. It can also be configured to include various
7610 build logs in each message.
7613 By default, the message will be sent to the Interested Users list
7614 (@pxref{Doing Things With Users}), which includes all developers who
7615 made changes in the build. You can add additional recipients with the
7616 extraRecipients argument.
7618 Each MailNotifier sends mail to a single set of recipients. To send
7619 different kinds of mail to different recipients, use multiple
7620 MailNotifiers.
7622 The following simple example will send an email upon the completion of
7623 each build, to just those developers whose Changes were included in
7624 the build. The email contains a description of the Build, its results,
7625 and URLs where more information can be obtained.
7627 @example
7628 from buildbot.status.mail import MailNotifier
7629 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
7630 c['status'].append(mn)
7631 @end example
7633 To get a simple one-message-per-build (say, for a mailing list), use
7634 the following form instead. This form does not send mail to individual
7635 developers (and thus does not need the @code{lookup=} argument,
7636 explained below), instead it only ever sends mail to the ``extra
7637 recipients'' named in the arguments:
7639 @example
7640 mn = MailNotifier(fromaddr="buildbot@@example.org",
7641                   sendToInterestedUsers=False,
7642                   extraRecipients=['listaddr@@example.org'])
7643 @end example
7645 In some cases it is desirable to have different information then what
7646 is provided in a standard MailNotifier message. For this purpose 
7647 MailNotifier provides the argument customMesg (a function) which allows 
7648 for the creation of messages with unique content.
7650 For example it can be useful to display the last few lines of a log file 
7651 and recent changes when a builder fails:
7653 @example
7654 def message(attrs):
7655     logLines = 10
7656     text = list()
7657     text.append("STATUS: %s" % attrs['result'].title())
7658     text.append("")
7659     text.extend([c.asText() for c in attrs['changes']])
7660     text.append("")
7661     name, url, lines = attrs['logs'][-1]
7662     text.append("Last %d lines of '%s':" % (logLines, name))
7663     text.extend(["\t%s\n" % line for line in lines[len(lines)-logLines:]])
7664     text.append("")
7665     text.append("-buildbot")
7666     return ("\n".join(text), 'plain')
7668 mn = MailNotifier(fromaddr="buildbot@@example.org",
7669                   sendToInterestedUsers=False,
7670                   mode='problem',
7671                   extraRecipients=['listaddr@@example.org'],
7672                   customMesg=message)
7673 @end example
7675 A customMesg function takes a single dict argument (see below) and returns a 
7676 tuple of strings. The first string is the complete text of the message and the
7677 second is the message type ('plain' or 'html'). The 'html' type should be used
7678 when generating an HTML message: 
7680 @example
7681 def message(attrs):
7682     logLines = 10
7683     text = list()
7684     text.append('<h4>Build status %s.</h4>' % (attrs['result'].title()))
7685     if attrs['changes']:
7686         text.append('<h4>Recent Changes:</h4>')
7687         text.extend([c.asHTML() for c in attrs['changes']])
7688     name, url, lines = attrs['logs'][-1]
7689     text.append('<h4>Last %d lines of "%s":</h4>' % (logLines, name))
7690     text.append('<p>')
7691     text.append('<br>'.join([line for line in lines[len(lines)-logLines:]]))
7692     text.append('</p>')
7693     text.append('<br><br>')
7694     text.append('Full log at: %s' % url)
7695     text.append('<br><br>')
7696     text.append('<b>-buildbot</b>')
7697     return ('\n'.join(text), 'html')
7698 @end example 
7700 @heading MailNotifier arguments
7702 @table @code
7703 @item fromaddr
7704 The email address to be used in the 'From' header.
7706 @item sendToInterestedUsers
7707 (boolean). If True (the default), send mail to all of the Interested
7708 Users. If False, only send mail to the extraRecipients list.
7710 @item extraRecipients
7711 (tuple of strings). A list of email addresses to which messages should
7712 be sent (in addition to the InterestedUsers list, which includes any
7713 developers who made Changes that went into this build). It is a good
7714 idea to create a small mailing list and deliver to that, then let
7715 subscribers come and go as they please.
7717 @item subject
7718 (string). A string to be used as the subject line of the message.
7719 @code{%(builder)s} will be replaced with the name of the builder which
7720 provoked the message.
7722 @item mode
7723 (string). Default to 'all'. One of:
7724 @table @code
7725 @item all
7726 Send mail about all builds, bothpassing and failing
7727 @item failing
7728 Only send mail about builds which fail
7729 @item problem
7730 Only send mail about a build which failed when the previous build has passed.
7731 If your builds usually pass, then this will only send mail when a problem
7732 occurs.
7733 @end table
7735 @item builders
7736 (list of strings). A list of builder names for which mail should be
7737 sent. Defaults to None (send mail for all builds). Use either builders
7738 or categories, but not both.
7740 @item categories
7741 (list of strings). A list of category names to serve status
7742 information for. Defaults to None (all categories). Use either
7743 builders or categories, but not both.
7745 @item addLogs
7746 (boolean). If True, include all build logs as attachments to the
7747 messages. These can be quite large. This can also be set to a list of
7748 log names, to send a subset of the logs. Defaults to False.
7750 @item relayhost
7751 (string). The host to which the outbound SMTP connection should be
7752 made. Defaults to 'localhost'
7754 @item lookup
7755 (implementor of @code{IEmailLookup}). Object which provides
7756 IEmailLookup, which is responsible for mapping User names (which come
7757 from the VC system) into valid email addresses. If not provided, the
7758 notifier will only be able to send mail to the addresses in the
7759 extraRecipients list. Most of the time you can use a simple Domain
7760 instance. As a shortcut, you can pass as string: this will be treated
7761 as if you had provided Domain(str). For example,
7762 lookup='twistedmatrix.com' will allow mail to be sent to all
7763 developers whose SVN usernames match their twistedmatrix.com account
7764 names. See buildbot/status/mail.py for more details.
7766 @item customMesg
7767 This is a optional function that can be used to generate a custom mail 
7768 message. The customMesg function takes a single dict and must return a 
7769 tuple containing the message text and type ('html' or 'plain'). Below is a list 
7770 of availale keys in the dict passed to customMesg:
7772 @table @code
7773 @item builderName 
7774 (str) Name of the builder that generated this event.
7775 @item projectName 
7776 (str) Name of the project.
7777 @item mode 
7778 (str) Mode set in MailNotifier. (failing, passing, problem).
7779 @item result 
7780 (str) Builder result as a string. 'success', 'warnings', 'failure', 'skipped', or 'exception'
7781 @item buildURL 
7782 (str) URL to build page.
7783 @item buildbotURL 
7784 (str) URL to buildbot main page.
7785 @item buildText 
7786 (str) Build text from build.getText().
7787 @item slavename 
7788 (str) Slavename.
7789 @item reason 
7790 (str) Build reason from build.getReason().
7791 @item responsibleUsers 
7792 (List of str) List of responsible users.
7793 @item branch 
7794 (str) Name of branch used. If no SourceStamp exists branch
7795 is an empty string.
7796 @item revision 
7797 (str) Name of revision used. If no SourceStamp exists revision
7798 is an empty string.
7799 @item patch 
7800 (str) Name of patch used. If no SourceStamp exists patch
7801 is an empty string.
7802 @item changes
7803 (list of objs) List of change objects from SourceStamp. A change
7804 object has the following useful information:
7805 @table @code
7806 @item who
7807 (str) who made this change
7808 @item revision 
7809 (str) what VC revision is this change
7810 @item branch 
7811 (str) on what branch did this change occur
7812 @item when 
7813 (str) when did this change occur
7814 @item files 
7815 (list of str) what files were affected in this change
7816 @item comments 
7817 (str) comments reguarding the change.
7818 @end table
7819 The functions asText and asHTML return a list of strings with
7820 the above information formatted. 
7821 @item logs
7822 (List of Tuples) List of tuples where each tuple contains the log name, log url,
7823 and log contents as a list of strings.
7824 @end table
7825 @end table
7827 @node IRC Bot, PBListener, MailNotifier, Status Delivery
7828 @section IRC Bot
7830 @cindex IRC
7831 @stindex buildbot.status.words.IRC
7834 The @code{buildbot.status.words.IRC} status target creates an IRC bot
7835 which will attach to certain channels and be available for status
7836 queries. It can also be asked to announce builds as they occur, or be
7837 told to shut up.
7839 @example
7840 from buildbot.status import words
7841 irc = words.IRC("irc.example.org", "botnickname",
7842                 channels=["channel1", "channel2"],
7843                 password="mysecretpassword",
7844                 notify_events=@{
7845                   'exception': 1,
7846                   'successToFailure': 1,
7847                   'failureToSuccess': 1,
7848                 @})
7849 c['status'].append(irc)
7850 @end example
7852 Take a look at the docstring for @code{words.IRC} for more details on
7853 configuring this service. The @code{password} argument, if provided,
7854 will be sent to Nickserv to claim the nickname: some IRC servers will
7855 not allow clients to send private messages until they have logged in
7856 with a password.
7858 To use the service, you address messages at the buildbot, either
7859 normally (@code{botnickname: status}) or with private messages
7860 (@code{/msg botnickname status}). The buildbot will respond in kind.
7862 Some of the commands currently available:
7864 @table @code
7866 @item list builders
7867 Emit a list of all configured builders
7868 @item status BUILDER
7869 Announce the status of a specific Builder: what it is doing right now.
7870 @item status all
7871 Announce the status of all Builders
7872 @item watch BUILDER
7873 If the given Builder is currently running, wait until the Build is
7874 finished and then announce the results.
7875 @item last BUILDER
7876 Return the results of the last build to run on the given Builder.
7877 @item join CHANNEL
7878 Join the given IRC channel
7879 @item leave CHANNEL
7880 Leave the given IRC channel
7881 @item notify on|off|list EVENT
7882 Report events relating to builds.  If the command is issued as a
7883 private message, then the report will be sent back as a private
7884 message to the user who issued the command.  Otherwise, the report
7885 will be sent to the channel.  Available events to be notified are:
7887 @table @code
7888 @item started
7889 A build has started
7890 @item finished
7891 A build has finished
7892 @item success
7893 A build finished successfully
7894 @item failed
7895 A build failed
7896 @item exception
7897 A build generated and exception
7898 @item xToY
7899 The previous build was x, but this one is Y, where x and Y are each
7900 one of success, warnings, failure, exception (except Y is
7901 capitalized).  For example: successToFailure will notify if the
7902 previous build was successful, but this one failed
7903 @end table
7905 @item help COMMAND
7906 Describe a command. Use @code{help commands} to get a list of known
7907 commands.
7908 @item source
7909 Announce the URL of the Buildbot's home page.
7910 @item version
7911 Announce the version of this Buildbot.
7912 @end table
7914 Additionally, the config file may specify default notification options
7915 as shown in the example earlier.
7917 If the @code{allowForce=True} option was used, some addtional commands
7918 will be available:
7920 @table @code
7921 @item force build BUILDER REASON
7922 Tell the given Builder to start a build of the latest code. The user
7923 requesting the build and REASON are recorded in the Build status. The
7924 buildbot will announce the build's status when it finishes.
7926 @item stop build BUILDER REASON
7927 Terminate any running build in the given Builder. REASON will be added
7928 to the build status to explain why it was stopped. You might use this
7929 if you committed a bug, corrected it right away, and don't want to
7930 wait for the first build (which is destined to fail) to complete
7931 before starting the second (hopefully fixed) build.
7932 @end table
7934 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
7935 @section PBListener
7937 @cindex PBListener
7938 @stindex buildbot.status.client.PBListener
7941 @example
7942 import buildbot.status.client
7943 pbl = buildbot.status.client.PBListener(port=int, user=str,
7944                                         passwd=str)
7945 c['status'].append(pbl)
7946 @end example
7948 This sets up a PB listener on the given TCP port, to which a PB-based
7949 status client can connect and retrieve status information.
7950 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
7951 status client. The @code{port} argument can also be a strports
7952 specification string.
7954 @node Writing New Status Plugins,  , PBListener, Status Delivery
7955 @section Writing New Status Plugins
7957 TODO: this needs a lot more examples
7959 Each status plugin is an object which provides the
7960 @code{twisted.application.service.IService} interface, which creates a
7961 tree of Services with the buildmaster at the top [not strictly true].
7962 The status plugins are all children of an object which implements
7963 @code{buildbot.interfaces.IStatus}, the main status object. From this
7964 object, the plugin can retrieve anything it wants about current and
7965 past builds. It can also subscribe to hear about new and upcoming
7966 builds.
7968 Status plugins which only react to human queries (like the Waterfall
7969 display) never need to subscribe to anything: they are idle until
7970 someone asks a question, then wake up and extract the information they
7971 need to answer it, then they go back to sleep. Plugins which need to
7972 act spontaneously when builds complete (like the MailNotifier plugin)
7973 need to subscribe to hear about new builds.
7975 If the status plugin needs to run network services (like the HTTP
7976 server used by the Waterfall plugin), they can be attached as Service
7977 children of the plugin itself, using the @code{IServiceCollection}
7978 interface.
7982 @node Command-line tool, Resources, Status Delivery, Top
7983 @chapter Command-line tool
7985 The @command{buildbot} command-line tool can be used to start or stop a
7986 buildmaster or buildbot, and to interact with a running buildmaster.
7987 Some of its subcommands are intended for buildmaster admins, while
7988 some are for developers who are editing the code that the buildbot is
7989 monitoring.
7991 @menu
7992 * Administrator Tools::
7993 * Developer Tools::
7994 * Other Tools::
7995 * .buildbot config directory::
7996 @end menu
7998 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
7999 @section Administrator Tools
8001 The following @command{buildbot} sub-commands are intended for
8002 buildmaster administrators:
8004 @heading create-master
8006 This creates a new directory and populates it with files that allow it
8007 to be used as a buildmaster's base directory.
8009 @example
8010 buildbot create-master BASEDIR
8011 @end example
8013 @heading create-slave
8015 This creates a new directory and populates it with files that let it
8016 be used as a buildslave's base directory. You must provide several
8017 arguments, which are used to create the initial @file{buildbot.tac}
8018 file.
8020 @example
8021 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
8022 @end example
8024 @heading start
8026 This starts a buildmaster or buildslave which was already created in
8027 the given base directory. The daemon is launched in the background,
8028 with events logged to a file named @file{twistd.log}.
8030 @example
8031 buildbot start BASEDIR
8032 @end example
8034 @heading stop
8036 This terminates the daemon (either buildmaster or buildslave) running
8037 in the given directory.
8039 @example
8040 buildbot stop BASEDIR
8041 @end example
8043 @heading sighup
8045 This sends a SIGHUP to the buildmaster running in the given directory,
8046 which causes it to re-read its @file{master.cfg} file.
8048 @example
8049 buildbot sighup BASEDIR
8050 @end example
8052 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
8053 @section Developer Tools
8055 These tools are provided for use by the developers who are working on
8056 the code that the buildbot is monitoring.
8058 @menu
8059 * statuslog::
8060 * statusgui::
8061 * try::
8062 @end menu
8064 @node statuslog, statusgui, Developer Tools, Developer Tools
8065 @subsection statuslog
8067 @example
8068 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
8069 @end example
8071 This command starts a simple text-based status client, one which just
8072 prints out a new line each time an event occurs on the buildmaster.
8074 The @option{--master} option provides the location of the
8075 @code{buildbot.status.client.PBListener} status port, used to deliver
8076 build information to realtime status clients. The option is always in
8077 the form of a string, with hostname and port number separated by a
8078 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
8079 same as the slaveport (although a future version may allow the same
8080 port number to be used for both purposes). If you get an error message
8081 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
8082 this may indicate that you are connecting to the slaveport rather than
8083 a @code{PBListener} port.
8085 The @option{--master} option can also be provided by the
8086 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
8087 config directory}).
8089 @node statusgui, try, statuslog, Developer Tools
8090 @subsection statusgui
8092 @cindex statusgui
8094 If you have set up a PBListener (@pxref{PBListener}), you will be able
8095 to monitor your Buildbot using a simple Gtk+ application invoked with
8096 the @code{buildbot statusgui} command:
8098 @example
8099 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
8100 @end example
8102 This command starts a simple Gtk+-based status client, which contains
8103 a few boxes for each Builder that change color as events occur. It
8104 uses the same @option{--master} argument as the @command{buildbot
8105 statuslog} command (@pxref{statuslog}).
8107 @node try,  , statusgui, Developer Tools
8108 @subsection try
8110 This lets a developer to ask the question ``What would happen if I
8111 committed this patch right now?''. It runs the unit test suite (across
8112 multiple build platforms) on the developer's current code, allowing
8113 them to make sure they will not break the tree when they finally
8114 commit their changes.
8116 The @command{buildbot try} command is meant to be run from within a
8117 developer's local tree, and starts by figuring out the base revision
8118 of that tree (what revision was current the last time the tree was
8119 updated), and a patch that can be applied to that revision of the tree
8120 to make it match the developer's copy. This (revision, patch) pair is
8121 then sent to the buildmaster, which runs a build with that
8122 SourceStamp. If you want, the tool will emit status messages as the
8123 builds run, and will not terminate until the first failure has been
8124 detected (or the last success).
8126 There is an alternate form which accepts a pre-made patch file
8127 (typically the output of a command like 'svn diff'). This ``--diff''
8128 form does not require a local tree to run from. See @xref{try --diff}.
8130 For this command to work, several pieces must be in place:
8133 @heading TryScheduler
8135 @slindex buildbot.scheduler.Try_Jobdir
8136 @slindex buildbot.scheduler.Try_Userpass
8138 The buildmaster must have a @code{scheduler.Try} instance in
8139 the config file's @code{c['schedulers']} list. This lets the
8140 administrator control who may initiate these ``trial'' builds, which
8141 branches are eligible for trial builds, and which Builders should be
8142 used for them.
8144 The @code{TryScheduler} has various means to accept build requests:
8145 all of them enforce more security than the usual buildmaster ports do.
8146 Any source code being built can be used to compromise the buildslave
8147 accounts, but in general that code must be checked out from the VC
8148 repository first, so only people with commit privileges can get
8149 control of the buildslaves. The usual force-build control channels can
8150 waste buildslave time but do not allow arbitrary commands to be
8151 executed by people who don't have those commit privileges. However,
8152 the source code patch that is provided with the trial build does not
8153 have to go through the VC system first, so it is important to make
8154 sure these builds cannot be abused by a non-committer to acquire as
8155 much control over the buildslaves as a committer has. Ideally, only
8156 developers who have commit access to the VC repository would be able
8157 to start trial builds, but unfortunately the buildmaster does not, in
8158 general, have access to VC system's user list.
8160 As a result, the @code{TryScheduler} requires a bit more
8161 configuration. There are currently two ways to set this up:
8163 @table @strong
8164 @item jobdir (ssh)
8166 This approach creates a command queue directory, called the
8167 ``jobdir'', in the buildmaster's working directory. The buildmaster
8168 admin sets the ownership and permissions of this directory to only
8169 grant write access to the desired set of developers, all of whom must
8170 have accounts on the machine. The @code{buildbot try} command creates
8171 a special file containing the source stamp information and drops it in
8172 the jobdir, just like a standard maildir. When the buildmaster notices
8173 the new file, it unpacks the information inside and starts the builds.
8175 The config file entries used by 'buildbot try' either specify a local
8176 queuedir (for which write and mv are used) or a remote one (using scp
8177 and ssh).
8179 The advantage of this scheme is that it is quite secure, the
8180 disadvantage is that it requires fiddling outside the buildmaster
8181 config (to set the permissions on the jobdir correctly). If the
8182 buildmaster machine happens to also house the VC repository, then it
8183 can be fairly easy to keep the VC userlist in sync with the
8184 trial-build userlist. If they are on different machines, this will be
8185 much more of a hassle. It may also involve granting developer accounts
8186 on a machine that would not otherwise require them.
8188 To implement this, the buildslave invokes 'ssh -l username host
8189 buildbot tryserver ARGS', passing the patch contents over stdin. The
8190 arguments must include the inlet directory and the revision
8191 information.
8193 @item user+password (PB)
8195 In this approach, each developer gets a username/password pair, which
8196 are all listed in the buildmaster's configuration file. When the
8197 developer runs @code{buildbot try}, their machine connects to the
8198 buildmaster via PB and authenticates themselves using that username
8199 and password, then sends a PB command to start the trial build.
8201 The advantage of this scheme is that the entire configuration is
8202 performed inside the buildmaster's config file. The disadvantages are
8203 that it is less secure (while the ``cred'' authentication system does
8204 not expose the password in plaintext over the wire, it does not offer
8205 most of the other security properties that SSH does). In addition, the
8206 buildmaster admin is responsible for maintaining the username/password
8207 list, adding and deleting entries as developers come and go.
8209 @end table
8212 For example, to set up the ``jobdir'' style of trial build, using a
8213 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
8214 all your project developers were members of the @code{developers} unix
8215 group), you would first create that directory (with @command{mkdir
8216 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
8217 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
8218 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
8219 MASTERDIR/jobdir/*}), and then use the following scheduler in the
8220 buildmaster's config file:
8222 @example
8223 from buildbot.scheduler import Try_Jobdir
8224 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
8225                jobdir="jobdir")
8226 c['schedulers'] = [s]
8227 @end example
8229 Note that you must create the jobdir before telling the buildmaster to
8230 use this configuration, otherwise you will get an error. Also remember
8231 that the buildmaster must be able to read and write to the jobdir as
8232 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
8233 as you start using the jobdir, to make sure the buildmaster is happy
8234 with it.
8236 To use the username/password form of authentication, create a
8237 @code{Try_Userpass} instance instead. It takes the same
8238 @code{builderNames} argument as the @code{Try_Jobdir} form, but
8239 accepts an addtional @code{port} argument (to specify the TCP port to
8240 listen on) and a @code{userpass} list of username/password pairs to
8241 accept. Remember to use good passwords for this: the security of the
8242 buildslave accounts depends upon it:
8244 @example
8245 from buildbot.scheduler import Try_Userpass
8246 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
8247                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
8248 c['schedulers'] = [s]
8249 @end example
8251 Like most places in the buildbot, the @code{port} argument takes a
8252 strports specification. See @code{twisted.application.strports} for
8253 details.
8256 @heading locating the master
8258 The @command{try} command needs to be told how to connect to the
8259 @code{TryScheduler}, and must know which of the authentication
8260 approaches described above is in use by the buildmaster. You specify
8261 the approach by using @option{--connect=ssh} or @option{--connect=pb}
8262 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
8263 @file{.buildbot/options}).
8265 For the PB approach, the command must be given a @option{--master}
8266 argument (in the form HOST:PORT) that points to TCP port that you
8267 picked in the @code{Try_Userpass} scheduler. It also takes a
8268 @option{--username} and @option{--passwd} pair of arguments that match
8269 one of the entries in the buildmaster's @code{userpass} list. These
8270 arguments can also be provided as @code{try_master},
8271 @code{try_username}, and @code{try_password} entries in the
8272 @file{.buildbot/options} file.
8274 For the SSH approach, the command must be given @option{--tryhost},
8275 @option{--username}, and optionally @option{--password} (TODO:
8276 really?) to get to the buildmaster host. It must also be given
8277 @option{--trydir}, which points to the inlet directory configured
8278 above. The trydir can be relative to the user's home directory, but
8279 most of the time you will use an explicit path like
8280 @file{~buildbot/project/trydir}. These arguments can be provided in
8281 @file{.buildbot/options} as @code{try_host}, @code{try_username},
8282 @code{try_password}, and @code{try_dir}.
8284 In addition, the SSH approach needs to connect to a PBListener status
8285 port, so it can retrieve and report the results of the build (the PB
8286 approach uses the existing connection to retrieve status information,
8287 so this step is not necessary). This requires a @option{--master}
8288 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
8289 in the form of a HOSTNAME:PORT string.
8292 @heading choosing the Builders
8294 A trial build is performed on multiple Builders at the same time, and
8295 the developer gets to choose which Builders are used (limited to a set
8296 selected by the buildmaster admin with the TryScheduler's
8297 @code{builderNames=} argument). The set you choose will depend upon
8298 what your goals are: if you are concerned about cross-platform
8299 compatibility, you should use multiple Builders, one from each
8300 platform of interest. You might use just one builder if that platform
8301 has libraries or other facilities that allow better test coverage than
8302 what you can accomplish on your own machine, or faster test runs.
8304 The set of Builders to use can be specified with multiple
8305 @option{--builder} arguments on the command line. It can also be
8306 specified with a single @code{try_builders} option in
8307 @file{.buildbot/options} that uses a list of strings to specify all
8308 the Builder names:
8310 @example
8311 try_builders = ["full-OSX", "full-win32", "full-linux"]
8312 @end example
8314 @heading specifying the VC system
8316 The @command{try} command also needs to know how to take the
8317 developer's current tree and extract the (revision, patch)
8318 source-stamp pair. Each VC system uses a different process, so you
8319 start by telling the @command{try} command which VC system you are
8320 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
8321 This can also be provided as @code{try_vc} in
8322 @file{.buildbot/options}.
8324 The following names are recognized: @code{cvs} @code{svn} @code{baz}
8325 @code{tla} @code{hg} @code{darcs}
8328 @heading finding the top of the tree
8330 Some VC systems (notably CVS and SVN) track each directory
8331 more-or-less independently, which means the @command{try} command
8332 needs to move up to the top of the project tree before it will be able
8333 to construct a proper full-tree patch. To accomplish this, the
8334 @command{try} command will crawl up through the parent directories
8335 until it finds a marker file. The default name for this marker file is
8336 @file{.buildbot-top}, so when you are using CVS or SVN you should
8337 @code{touch .buildbot-top} from the top of your tree before running
8338 @command{buildbot try}. Alternatively, you can use a filename like
8339 @file{ChangeLog} or @file{README}, since many projects put one of
8340 these files in their top-most directory (and nowhere else). To set
8341 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
8342 options file with @code{try_topfile = 'ChangeLog'}.
8344 You can also manually set the top of the tree with
8345 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
8346 '~/trees/mytree'}. If you use @code{try_topdir}, in a
8347 @file{.buildbot/options} file, you will need a separate options file
8348 for each tree you use, so it may be more convenient to use the
8349 @code{try_topfile} approach instead.
8351 Other VC systems which work on full projects instead of individual
8352 directories (tla, baz, darcs, monotone, mercurial, git) do not require
8353 @command{try} to know the top directory, so the @option{--try-topfile}
8354 and @option{--try-topdir} arguments will be ignored.
8355 @c is this true? I think I currently require topdirs all the time.
8357 If the @command{try} command cannot find the top directory, it will
8358 abort with an error message.
8360 @heading determining the branch name
8362 Some VC systems record the branch information in a way that ``try''
8363 can locate it, in particular Arch (both @command{tla} and
8364 @command{baz}). For the others, if you are using something other than
8365 the default branch, you will have to tell the buildbot which branch
8366 your tree is using. You can do this with either the @option{--branch}
8367 argument, or a @option{try_branch} entry in the
8368 @file{.buildbot/options} file.
8370 @heading determining the revision and patch
8372 Each VC system has a separate approach for determining the tree's base
8373 revision and computing a patch.
8375 @table @code
8377 @item CVS
8379 @command{try} pretends that the tree is up to date. It converts the
8380 current time into a @code{-D} time specification, uses it as the base
8381 revision, and computes the diff between the upstream tree as of that
8382 point in time versus the current contents. This works, more or less,
8383 but requires that the local clock be in reasonably good sync with the
8384 repository.
8386 @item SVN
8387 @command{try} does a @code{svn status -u} to find the latest
8388 repository revision number (emitted on the last line in the ``Status
8389 against revision: NN'' message). It then performs an @code{svn diff
8390 -rNN} to find out how your tree differs from the repository version,
8391 and sends the resulting patch to the buildmaster. If your tree is not
8392 up to date, this will result in the ``try'' tree being created with
8393 the latest revision, then @emph{backwards} patches applied to bring it
8394 ``back'' to the version you actually checked out (plus your actual
8395 code changes), but this will still result in the correct tree being
8396 used for the build.
8398 @item baz
8399 @command{try} does a @code{baz tree-id} to determine the
8400 fully-qualified version and patch identifier for the tree
8401 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
8402 as the base revision. It then does a @code{baz diff} to obtain the
8403 patch.
8405 @item tla
8406 @command{try} does a @code{tla tree-version} to get the
8407 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
8408 first line of @code{tla logs --reverse} to figure out the base
8409 revision. Then it does @code{tla changes --diffs} to obtain the patch.
8411 @item Darcs
8412 @code{darcs changes --context} emits a text file that contains a list
8413 of all patches back to and including the last tag was made. This text
8414 file (plus the location of a repository that contains all these
8415 patches) is sufficient to re-create the tree. Therefore the contents
8416 of this ``context'' file @emph{are} the revision stamp for a
8417 Darcs-controlled source tree.
8419 So @command{try} does a @code{darcs changes --context} to determine
8420 what your tree's base revision is, and then does a @code{darcs diff
8421 -u} to compute the patch relative to that revision.
8423 @item Mercurial
8424 @code{hg identify} emits a short revision ID (basically a truncated
8425 SHA1 hash of the current revision's contents), which is used as the
8426 base revision. @code{hg diff} then provides the patch relative to that
8427 revision. For @command{try} to work, your working directory must only
8428 have patches that are available from the same remotely-available
8429 repository that the build process' @code{step.Mercurial} will use.
8431 @item Git
8432 @code{git branch -v} lists all the branches available in the local
8433 repository along with the revision ID it points to and a short summary
8434 of the last commit. The line containing the currently checked out
8435 branch begins with '* ' (star and space) while all the others start
8436 with '  ' (two spaces). @command{try} scans for this line and extracts
8437 the branch name and revision from it. Then it generates a diff against
8438 the base revision.
8439 @c TODO: I'm not sure if this actually works the way it's intended
8440 @c since the extracted base revision might not actually exist in the
8441 @c upstream repository. Perhaps we need to add a --remote option to
8442 @c specify the remote tracking branch to generate a diff against.
8444 @c TODO: monotone
8445 @end table
8447 @heading waiting for results
8449 If you provide the @option{--wait} option (or @code{try_wait = True}
8450 in @file{.buildbot/options}), the @command{buildbot try} command will
8451 wait until your changes have either been proven good or bad before
8452 exiting. Unless you use the @option{--quiet} option (or
8453 @code{try_quiet=True}), it will emit a progress message every 60
8454 seconds until the builds have completed.
8456 @menu
8457 * try --diff::
8458 @end menu
8460 @node try --diff,  , try, try
8461 @subsubsection try --diff
8463 Sometimes you might have a patch from someone else that you want to
8464 submit to the buildbot. For example, a user may have created a patch
8465 to fix some specific bug and sent it to you by email. You've inspected
8466 the patch and suspect that it might do the job (and have at least
8467 confirmed that it doesn't do anything evil). Now you want to test it
8468 out.
8470 One approach would be to check out a new local tree, apply the patch,
8471 run your local tests, then use ``buildbot try'' to run the tests on
8472 other platforms. An alternate approach is to use the @command{buildbot
8473 try --diff} form to have the buildbot test the patch without using a
8474 local tree.
8476 This form takes a @option{--diff} argument which points to a file that
8477 contains the patch you want to apply. By default this patch will be
8478 applied to the TRUNK revision, but if you give the optional
8479 @option{--baserev} argument, a tree of the given revision will be used
8480 as a starting point instead of TRUNK.
8482 You can also use @command{buildbot try --diff=-} to read the patch
8483 from stdin.
8485 Each patch has a ``patchlevel'' associated with it. This indicates the
8486 number of slashes (and preceding pathnames) that should be stripped
8487 before applying the diff. This exactly corresponds to the @option{-p}
8488 or @option{--strip} argument to the @command{patch} utility. By
8489 default @command{buildbot try --diff} uses a patchlevel of 0, but you
8490 can override this with the @option{-p} argument.
8492 When you use @option{--diff}, you do not need to use any of the other
8493 options that relate to a local tree, specifically @option{--vc},
8494 @option{--try-topfile}, or @option{--try-topdir}. These options will
8495 be ignored. Of course you must still specify how to get to the
8496 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
8499 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
8500 @section Other Tools
8502 These tools are generally used by buildmaster administrators.
8504 @menu
8505 * sendchange::
8506 * debugclient::
8507 @end menu
8509 @node sendchange, debugclient, Other Tools, Other Tools
8510 @subsection sendchange
8512 This command is used to tell the buildmaster about source changes. It
8513 is intended to be used from within a commit script, installed on the
8514 VC server. It requires that you have a PBChangeSource
8515 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
8516 @code{c['change_source']}).
8519 @example
8520 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
8521 @end example
8523 There are other (optional) arguments which can influence the
8524 @code{Change} that gets submitted:
8526 @table @code
8527 @item --branch
8528 This provides the (string) branch specifier. If omitted, it defaults
8529 to None, indicating the ``default branch''. All files included in this
8530 Change must be on the same branch.
8532 @item --category
8533 This provides the (string) category specifier. If omitted, it defaults
8534 to None, indicating ``no category''. The category property is used
8535 by Schedulers to filter what changes they listen to.
8537 @item --revision_number
8538 This provides a (numeric) revision number for the change, used for VC systems
8539 that use numeric transaction numbers (like Subversion).
8541 @item --revision
8542 This provides a (string) revision specifier, for VC systems that use
8543 strings (Arch would use something like patch-42 etc).
8545 @item --revision_file
8546 This provides a filename which will be opened and the contents used as
8547 the revision specifier. This is specifically for Darcs, which uses the
8548 output of @command{darcs changes --context} as a revision specifier.
8549 This context file can be a couple of kilobytes long, spanning a couple
8550 lines per patch, and would be a hassle to pass as a command-line
8551 argument.
8553 @item --comments
8554 This provides the change comments as a single argument. You may want
8555 to use @option{--logfile} instead.
8557 @item --logfile
8558 This instructs the tool to read the change comments from the given
8559 file. If you use @code{-} as the filename, the tool will read the
8560 change comments from stdin.
8561 @end table
8564 @node debugclient,  , sendchange, Other Tools
8565 @subsection debugclient
8567 @example
8568 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
8569 @end example
8571 This launches a small Gtk+/Glade-based debug tool, connecting to the
8572 buildmaster's ``debug port''. This debug port shares the same port
8573 number as the slaveport (@pxref{Setting the slaveport}), but the
8574 @code{debugPort} is only enabled if you set a debug password in the
8575 buildmaster's config file (@pxref{Debug options}). The
8576 @option{--passwd} option must match the @code{c['debugPassword']}
8577 value.
8579 @option{--master} can also be provided in @file{.debug/options} by the
8580 @code{master} key. @option{--passwd} can be provided by the
8581 @code{debugPassword} key.
8583 The @code{Connect} button must be pressed before any of the other
8584 buttons will be active. This establishes the connection to the
8585 buildmaster. The other sections of the tool are as follows:
8587 @table @code
8588 @item Reload .cfg
8589 Forces the buildmaster to reload its @file{master.cfg} file. This is
8590 equivalent to sending a SIGHUP to the buildmaster, but can be done
8591 remotely through the debug port. Note that it is a good idea to be
8592 watching the buildmaster's @file{twistd.log} as you reload the config
8593 file, as any errors which are detected in the config file will be
8594 announced there.
8596 @item Rebuild .py
8597 (not yet implemented). The idea here is to use Twisted's ``rebuild''
8598 facilities to replace the buildmaster's running code with a new
8599 version. Even if this worked, it would only be used by buildbot
8600 developers.
8602 @item poke IRC
8603 This locates a @code{words.IRC} status target and causes it to emit a
8604 message on all the channels to which it is currently connected. This
8605 was used to debug a problem in which the buildmaster lost the
8606 connection to the IRC server and did not attempt to reconnect.
8608 @item Commit
8609 This allows you to inject a Change, just as if a real one had been
8610 delivered by whatever VC hook you are using. You can set the name of
8611 the committed file and the name of the user who is doing the commit.
8612 Optionally, you can also set a revision for the change. If the
8613 revision you provide looks like a number, it will be sent as an
8614 integer, otherwise it will be sent as a string.
8616 @item Force Build
8617 This lets you force a Builder (selected by name) to start a build of
8618 the current source tree.
8620 @item Currently
8621 (obsolete). This was used to manually set the status of the given
8622 Builder, but the status-assignment code was changed in an incompatible
8623 way and these buttons are no longer meaningful.
8625 @end table
8628 @node .buildbot config directory,  , Other Tools, Command-line tool
8629 @section .buildbot config directory
8631 Many of the @command{buildbot} tools must be told how to contact the
8632 buildmaster that they interact with. This specification can be
8633 provided as a command-line argument, but most of the time it will be
8634 easier to set them in an ``options'' file. The @command{buildbot}
8635 command will look for a special directory named @file{.buildbot},
8636 starting from the current directory (where the command was run) and
8637 crawling upwards, eventually looking in the user's home directory. It
8638 will look for a file named @file{options} in this directory, and will
8639 evaluate it as a python script, looking for certain names to be set.
8640 You can just put simple @code{name = 'value'} pairs in this file to
8641 set the options.
8643 For a description of the names used in this file, please see the
8644 documentation for the individual @command{buildbot} sub-commands. The
8645 following is a brief sample of what this file's contents could be.
8647 @example
8648 # for status-reading tools
8649 masterstatus = 'buildbot.example.org:12345'
8650 # for 'sendchange' or the debug port
8651 master = 'buildbot.example.org:18990'
8652 debugPassword = 'eiv7Po'
8653 @end example
8655 @table @code
8656 @item masterstatus
8657 Location of the @code{client.PBListener} status port, used by
8658 @command{statuslog} and @command{statusgui}.
8660 @item master
8661 Location of the @code{debugPort} (for @command{debugclient}). Also the
8662 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
8663 Usually shares the slaveport, but a future version may make it
8664 possible to have these listen on a separate port number.
8666 @item debugPassword
8667 Must match the value of @code{c['debugPassword']}, used to protect the
8668 debug port, for the @command{debugclient} command.
8670 @item username
8671 Provides a default username for the @command{sendchange} command.
8673 @end table
8676 The following options are used by the @code{buildbot try} command
8677 (@pxref{try}):
8679 @table @code
8680 @item try_connect
8681 This specifies how the ``try'' command should deliver its request to
8682 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
8683 @item try_builders
8684 Which builders should be used for the ``try'' build.
8685 @item try_vc
8686 This specifies the version control system being used.
8687 @item try_branch
8688 This indicates that the current tree is on a non-trunk branch.
8689 @item try_topdir
8690 @item try_topfile
8691 Use @code{try_topdir} to explicitly indicate the top of your working
8692 tree, or @code{try_topfile} to name a file that will only be found in
8693 that top-most directory.
8695 @item try_host
8696 @item try_username
8697 @item try_dir
8698 When try_connect is ``ssh'', the command will pay attention to
8699 @code{try_host}, @code{try_username}, and @code{try_dir}.
8701 @item try_username
8702 @item try_password
8703 @item try_master
8704 Instead, when @code{try_connect} is ``pb'', the command will pay
8705 attention to @code{try_username}, @code{try_password}, and
8706 @code{try_master}.
8708 @item try_wait
8709 @item masterstatus
8710 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
8711 command to wait for the requested build to complete.
8713 @end table
8717 @node Resources, Developer's Appendix, Command-line tool, Top
8718 @chapter Resources
8720 The Buildbot's home page is at @uref{http://buildbot.sourceforge.net/}
8722 For configuration questions and general discussion, please use the
8723 @code{buildbot-devel} mailing list. The subscription instructions and
8724 archives are available at
8725 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
8727 @node Developer's Appendix, Index of Useful Classes, Resources, Top
8728 @unnumbered Developer's Appendix
8730 This appendix contains random notes about the implementation of the
8731 Buildbot, and is likely to only be of use to people intending to
8732 extend the Buildbot's internals.
8734 The buildmaster consists of a tree of Service objects, which is shaped
8735 as follows:
8737 @example
8738 BuildMaster
8739  ChangeMaster  (in .change_svc)
8740   [IChangeSource instances]
8741  [IScheduler instances]  (in .schedulers)
8742  BotMaster  (in .botmaster)
8743   [IBuildSlave instances]
8744  [IStatusTarget instances]  (in .statusTargets)
8745 @end example
8747 The BotMaster has a collection of Builder objects as values of its
8748 @code{.builders} dictionary.
8751 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
8752 @unnumbered Index of Useful Classes
8754 This is a list of all user-visible classes. There are the ones that
8755 are useful in @file{master.cfg}, the buildmaster's configuration file.
8756 Classes that are not listed here are generally internal things that
8757 admins are unlikely to have much use for.
8760 @heading Change Sources
8761 @printindex cs
8763 @heading Schedulers and Locks
8764 @printindex sl
8766 @heading Build Factories
8767 @printindex bf
8769 @heading Build Steps
8770 @printindex bs
8772 @c undocumented steps
8773 @bsindex buildbot.steps.source.Git
8774 @bsindex buildbot.steps.maxq.MaxQ
8777 @heading Status Targets
8778 @printindex st
8780 @c TODO: undocumented targets
8782 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
8783 @unnumbered Index of master.cfg keys
8785 This is a list of all of the significant keys in master.cfg . Recall
8786 that master.cfg is effectively a small python program with exactly one
8787 responsibility: create a dictionary named @code{BuildmasterConfig}.
8788 The keys of this dictionary are listed here. The beginning of the
8789 master.cfg file typically starts with something like:
8791 @example
8792 BuildmasterConfig = c = @{@}
8793 @end example
8795 Therefore a config key of @code{change_source} will usually appear in
8796 master.cfg as @code{c['change_source']}.
8798 @printindex bc
8801 @node Index,  , Index of master.cfg keys, Top
8802 @unnumbered Index
8804 @printindex cp
8807 @bye