fix Trial step use in sample.cfg and fix texinfo documentation of same to match the...
[buildbot.git] / docs / buildbot.texinfo
blobdb288dccc58fc754134e5ba21e5e9fe2111f5e4b
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 be run on
1250 your build slave if you set the option @code{allowForce=True} in your
1251 @code{master.cfg} file @pxref{Enabling the "Force Build" Button}.
1253 Figure out which column is for a builder that runs on your slave, click on that
1254 builder's name, and the page that comes up will have a "Force Build" button.
1255 Fill in the form, hit the button, and a moment later you should see your
1256 slave's @file{twistd.log} filling with commands being run. Using @code{pstree}
1257 or @code{top} should also reveal the cvs/make/gcc/etc processes being run by
1258 the buildslave. Note that the same web page should also show the @file{admin}
1259 and @file{host} information files that you configured earlier.
1261 @node Concepts, Configuration, Installation, Top
1262 @chapter Concepts
1264 This chapter defines some of the basic concepts that the Buildbot
1265 uses. You'll need to understand how the Buildbot sees the world to
1266 configure it properly.
1268 @menu
1269 * Version Control Systems::
1270 * Schedulers::
1271 * BuildSet::
1272 * BuildRequest::
1273 * Builder::
1274 * Users::
1275 * Build Properties::
1276 @end menu
1278 @node Version Control Systems, Schedulers, Concepts, Concepts
1279 @section Version Control Systems
1281 @cindex Version Control
1283 These source trees come from a Version Control System of some kind.
1284 CVS and Subversion are two popular ones, but the Buildbot supports
1285 others. All VC systems have some notion of an upstream
1286 @code{repository} which acts as a server@footnote{except Darcs, but
1287 since the Buildbot never modifies its local source tree we can ignore
1288 the fact that Darcs uses a less centralized model}, from which clients
1289 can obtain source trees according to various parameters. The VC
1290 repository provides source trees of various projects, for different
1291 branches, and from various points in time. The first thing we have to
1292 do is to specify which source tree we want to get.
1294 @menu
1295 * Generalizing VC Systems::
1296 * Source Tree Specifications::
1297 * How Different VC Systems Specify Sources::
1298 * Attributes of Changes::
1299 @end menu
1301 @node Generalizing VC Systems, Source Tree Specifications, Version Control Systems, Version Control Systems
1302 @subsection Generalizing VC Systems
1304 For the purposes of the Buildbot, we will try to generalize all VC
1305 systems as having repositories that each provide sources for a variety
1306 of projects. Each project is defined as a directory tree with source
1307 files. The individual files may each have revisions, but we ignore
1308 that and treat the project as a whole as having a set of revisions
1309 (CVS is really the only VC system still in widespread use that has
1310 per-file revisions.. everything modern has moved to atomic tree-wide
1311 changesets). Each time someone commits a change to the project, a new
1312 revision becomes available. These revisions can be described by a
1313 tuple with two items: the first is a branch tag, and the second is
1314 some kind of revision stamp or timestamp. Complex projects may have
1315 multiple branch tags, but there is always a default branch. The
1316 timestamp may be an actual timestamp (such as the -D option to CVS),
1317 or it may be a monotonically-increasing transaction number (such as
1318 the change number used by SVN and P4, or the revision number used by
1319 Arch/Baz/Bazaar, or a labeled tag used in CVS)@footnote{many VC
1320 systems provide more complexity than this: in particular the local
1321 views that P4 and ClearCase can assemble out of various source
1322 directories are more complex than we're prepared to take advantage of
1323 here}. The SHA1 revision ID used by Monotone, Mercurial, and Git is
1324 also a kind of revision stamp, in that it specifies a unique copy of
1325 the source tree, as does a Darcs ``context'' file.
1327 When we aren't intending to make any changes to the sources we check out
1328 (at least not any that need to be committed back upstream), there are two
1329 basic ways to use a VC system:
1331 @itemize @bullet
1332 @item
1333 Retrieve a specific set of source revisions: some tag or key is used
1334 to index this set, which is fixed and cannot be changed by subsequent
1335 developers committing new changes to the tree. Releases are built from
1336 tagged revisions like this, so that they can be rebuilt again later
1337 (probably with controlled modifications).
1338 @item
1339 Retrieve the latest sources along a specific branch: some tag is used
1340 to indicate which branch is to be used, but within that constraint we want
1341 to get the latest revisions.
1342 @end itemize
1344 Build personnel or CM staff typically use the first approach: the
1345 build that results is (ideally) completely specified by the two
1346 parameters given to the VC system: repository and revision tag. This
1347 gives QA and end-users something concrete to point at when reporting
1348 bugs. Release engineers are also reportedly fond of shipping code that
1349 can be traced back to a concise revision tag of some sort.
1351 Developers are more likely to use the second approach: each morning
1352 the developer does an update to pull in the changes committed by the
1353 team over the last day. These builds are not easy to fully specify: it
1354 depends upon exactly when you did a checkout, and upon what local
1355 changes the developer has in their tree. Developers do not normally
1356 tag each build they produce, because there is usually significant
1357 overhead involved in creating these tags. Recreating the trees used by
1358 one of these builds can be a challenge. Some VC systems may provide
1359 implicit tags (like a revision number), while others may allow the use
1360 of timestamps to mean ``the state of the tree at time X'' as opposed
1361 to a tree-state that has been explicitly marked.
1363 The Buildbot is designed to help developers, so it usually works in
1364 terms of @emph{the latest} sources as opposed to specific tagged
1365 revisions. However, it would really prefer to build from reproducible
1366 source trees, so implicit revisions are used whenever possible.
1368 @node Source Tree Specifications, How Different VC Systems Specify Sources, Generalizing VC Systems, Version Control Systems
1369 @subsection Source Tree Specifications
1371 So for the Buildbot's purposes we treat each VC system as a server
1372 which can take a list of specifications as input and produce a source
1373 tree as output. Some of these specifications are static: they are
1374 attributes of the builder and do not change over time. Others are more
1375 variable: each build will have a different value. The repository is
1376 changed over time by a sequence of Changes, each of which represents a
1377 single developer making changes to some set of files. These Changes
1378 are cumulative@footnote{Monotone's @emph{multiple heads} feature
1379 violates this assumption of cumulative Changes, but in most situations
1380 the changes don't occur frequently enough for this to be a significant
1381 problem}.
1383 For normal builds, the Buildbot wants to get well-defined source trees
1384 that contain specific Changes, and exclude other Changes that may have
1385 occurred after the desired ones. We assume that the Changes arrive at
1386 the buildbot (through one of the mechanisms described in @pxref{Change
1387 Sources}) in the same order in which they are committed to the
1388 repository. The Buildbot waits for the tree to become ``stable''
1389 before initiating a build, for two reasons. The first is that
1390 developers frequently make multiple related commits in quick
1391 succession, even when the VC system provides ways to make atomic
1392 transactions involving multiple files at the same time. Running a
1393 build in the middle of these sets of changes would use an inconsistent
1394 set of source files, and is likely to fail (and is certain to be less
1395 useful than a build which uses the full set of changes). The
1396 tree-stable-timer is intended to avoid these useless builds that
1397 include some of the developer's changes but not all. The second reason
1398 is that some VC systems (i.e. CVS) do not provide repository-wide
1399 transaction numbers, so that timestamps are the only way to refer to
1400 a specific repository state. These timestamps may be somewhat
1401 ambiguous, due to processing and notification delays. By waiting until
1402 the tree has been stable for, say, 10 minutes, we can choose a
1403 timestamp from the middle of that period to use for our source
1404 checkout, and then be reasonably sure that any clock-skew errors will
1405 not cause the build to be performed on an inconsistent set of source
1406 files.
1408 The Schedulers always use the tree-stable-timer, with a timeout that
1409 is configured to reflect a reasonable tradeoff between build latency
1410 and change frequency. When the VC system provides coherent
1411 repository-wide revision markers (such as Subversion's revision
1412 numbers, or in fact anything other than CVS's timestamps), the
1413 resulting Build is simply performed against a source tree defined by
1414 that revision marker. When the VC system does not provide this, a
1415 timestamp from the middle of the tree-stable period is used to
1416 generate the source tree@footnote{this @code{checkoutDelay} defaults
1417 to half the tree-stable timer, but it can be overridden with an
1418 argument to the Source Step}.
1420 @node How Different VC Systems Specify Sources, Attributes of Changes, Source Tree Specifications, Version Control Systems
1421 @subsection How Different VC Systems Specify Sources
1423 For CVS, the static specifications are @code{repository} and
1424 @code{module}. In addition to those, each build uses a timestamp (or
1425 omits the timestamp to mean @code{the latest}) and @code{branch tag}
1426 (which defaults to HEAD). These parameters collectively specify a set
1427 of sources from which a build may be performed.
1429 @uref{http://subversion.tigris.org, Subversion} combines the
1430 repository, module, and branch into a single @code{Subversion URL}
1431 parameter. Within that scope, source checkouts can be specified by a
1432 numeric @code{revision number} (a repository-wide
1433 monotonically-increasing marker, such that each transaction that
1434 changes the repository is indexed by a different revision number), or
1435 a revision timestamp. When branches are used, the repository and
1436 module form a static @code{baseURL}, while each build has a
1437 @code{revision number} and a @code{branch} (which defaults to a
1438 statically-specified @code{defaultBranch}). The @code{baseURL} and
1439 @code{branch} are simply concatenated together to derive the
1440 @code{svnurl} to use for the checkout.
1442 @uref{http://www.perforce.com/, Perforce} is similar. The server
1443 is specified through a @code{P4PORT} parameter. Module and branch
1444 are specified in a single depot path, and revisions are
1445 depot-wide. When branches are used, the @code{p4base} and
1446 @code{defaultBranch} are concatenated together to produce the depot
1447 path.
1449 @uref{http://wiki.gnuarch.org/, Arch} and
1450 @uref{http://bazaar.canonical.com/, Bazaar} specify a repository by
1451 URL, as well as a @code{version} which is kind of like a branch name.
1452 Arch uses the word @code{archive} to represent the repository. Arch
1453 lets you push changes from one archive to another, removing the strict
1454 centralization required by CVS and SVN. It retains the distinction
1455 between repository and working directory that most other VC systems
1456 use. For complex multi-module directory structures, Arch has a
1457 built-in @code{build config} layer with which the checkout process has
1458 two steps. First, an initial bootstrap checkout is performed to
1459 retrieve a set of build-config files. Second, one of these files is
1460 used to figure out which archives/modules should be used to populate
1461 subdirectories of the initial checkout.
1463 Builders which use Arch and Bazaar therefore have a static archive
1464 @code{url}, and a default ``branch'' (which is a string that specifies
1465 a complete category--branch--version triple). Each build can have its
1466 own branch (the category--branch--version string) to override the
1467 default, as well as a revision number (which is turned into a
1468 --patch-NN suffix when performing the checkout).
1471 @uref{http://bazaar-vcs.org, Bzr} (which is a descendant of
1472 Arch/Bazaar, and is frequently referred to as ``Bazaar'') has the same
1473 sort of repository-vs-workspace model as Arch, but the repository data
1474 can either be stored inside the working directory or kept elsewhere
1475 (either on the same machine or on an entirely different machine). For
1476 the purposes of Buildbot (which never commits changes), the repository
1477 is specified with a URL and a revision number.
1479 The most common way to obtain read-only access to a bzr tree is via
1480 HTTP, simply by making the repository visible through a web server
1481 like Apache. Bzr can also use FTP and SFTP servers, if the buildslave
1482 process has sufficient privileges to access them. Higher performance
1483 can be obtained by running a special Bazaar-specific server. None of
1484 these matter to the buildbot: the repository URL just has to match the
1485 kind of server being used. The @code{repoURL} argument provides the
1486 location of the repository.
1488 Branches are expressed as subdirectories of the main central
1489 repository, which means that if branches are being used, the BZR step
1490 is given a @code{baseURL} and @code{defaultBranch} instead of getting
1491 the @code{repoURL} argument.
1494 @uref{http://darcs.net/, Darcs} doesn't really have the
1495 notion of a single master repository. Nor does it really have
1496 branches. In Darcs, each working directory is also a repository, and
1497 there are operations to push and pull patches from one of these
1498 @code{repositories} to another. For the Buildbot's purposes, all you
1499 need to do is specify the URL of a repository that you want to build
1500 from. The build slave will then pull the latest patches from that
1501 repository and build them. Multiple branches are implemented by using
1502 multiple repositories (possibly living on the same server).
1504 Builders which use Darcs therefore have a static @code{repourl} which
1505 specifies the location of the repository. If branches are being used,
1506 the source Step is instead configured with a @code{baseURL} and a
1507 @code{defaultBranch}, and the two strings are simply concatenated
1508 together to obtain the repository's URL. Each build then has a
1509 specific branch which replaces @code{defaultBranch}, or just uses the
1510 default one. Instead of a revision number, each build can have a
1511 ``context'', which is a string that records all the patches that are
1512 present in a given tree (this is the output of @command{darcs changes
1513 --context}, and is considerably less concise than, e.g. Subversion's
1514 revision number, but the patch-reordering flexibility of Darcs makes
1515 it impossible to provide a shorter useful specification).
1517 @uref{http://selenic.com/mercurial, Mercurial} is like Darcs, in that
1518 each branch is stored in a separate repository. The @code{repourl},
1519 @code{baseURL}, and @code{defaultBranch} arguments are all handled the
1520 same way as with Darcs. The ``revision'', however, is the hash
1521 identifier returned by @command{hg identify}.
1523 @uref{http://git.or.cz/, Git} also follows a decentralized model, and
1524 each repository can have several branches and tags. The source Step is
1525 configured with a static @code{repourl} which specifies the location
1526 of the repository. In addition, an optional @code{branch} parameter
1527 can be specified to check out code from a specific branch instead of
1528 the default ``master'' branch. The ``revision'' is specified as a SHA1
1529 hash as returned by e.g. @command{git rev-parse}. No attempt is made
1530 to ensure that the specified revision is actually a subset of the
1531 specified branch.
1534 @node Attributes of Changes,  , How Different VC Systems Specify Sources, Version Control Systems
1535 @subsection Attributes of Changes
1537 @heading Who
1539 Each Change has a @code{who} attribute, which specifies which
1540 developer is responsible for the change. This is a string which comes
1541 from a namespace controlled by the VC repository. Frequently this
1542 means it is a username on the host which runs the repository, but not
1543 all VC systems require this (Arch, for example, uses a fully-qualified
1544 @code{Arch ID}, which looks like an email address, as does Darcs).
1545 Each StatusNotifier will map the @code{who} attribute into something
1546 appropriate for their particular means of communication: an email
1547 address, an IRC handle, etc.
1549 @heading Files
1551 It also has a list of @code{files}, which are just the tree-relative
1552 filenames of any files that were added, deleted, or modified for this
1553 Change. These filenames are used by the @code{fileIsImportant}
1554 function (in the Scheduler) to decide whether it is worth triggering a
1555 new build or not, e.g. the function could use the following function
1556 to only run a build if a C file were checked in:
1558 @example
1559 def has_C_files(change):
1560     for name in change.files:
1561         if name.endswith(".c"):
1562             return True
1563     return False
1564 @end example
1566 Certain BuildSteps can also use the list of changed files
1567 to run a more targeted series of tests, e.g. the
1568 @code{python_twisted.Trial} step can run just the unit tests that
1569 provide coverage for the modified .py files instead of running the
1570 full test suite.
1572 @heading Comments
1574 The Change also has a @code{comments} attribute, which is a string
1575 containing any checkin comments.
1577 @heading Revision
1579 Each Change can have a @code{revision} attribute, which describes how
1580 to get a tree with a specific state: a tree which includes this Change
1581 (and all that came before it) but none that come after it. If this
1582 information is unavailable, the @code{.revision} attribute will be
1583 @code{None}. These revisions are provided by the ChangeSource, and
1584 consumed by the @code{computeSourceRevision} method in the appropriate
1585 @code{step.Source} class.
1587 @table @samp
1588 @item CVS
1589 @code{revision} is an int, seconds since the epoch
1590 @item SVN
1591 @code{revision} is an int, the changeset number (r%d)
1592 @item Darcs
1593 @code{revision} is a large string, the output of @code{darcs changes --context}
1594 @item Mercurial
1595 @code{revision} is a short string (a hash ID), the output of @code{hg identify}
1596 @item Arch/Bazaar
1597 @code{revision} is the full revision ID (ending in --patch-%d)
1598 @item P4
1599 @code{revision} is an int, the transaction number
1600 @item Git
1601 @code{revision} is a short string (a SHA1 hash), the output of e.g.
1602 @code{git rev-parse}
1603 @end table
1605 @heading Branches
1607 The Change might also have a @code{branch} attribute. This indicates
1608 that all of the Change's files are in the same named branch. The
1609 Schedulers get to decide whether the branch should be built or not.
1611 For VC systems like CVS, Arch, Monotone, and Git, the @code{branch}
1612 name is unrelated to the filename. (that is, the branch name and the
1613 filename inhabit unrelated namespaces). For SVN, branches are
1614 expressed as subdirectories of the repository, so the file's
1615 ``svnurl'' is a combination of some base URL, the branch name, and the
1616 filename within the branch. (In a sense, the branch name and the
1617 filename inhabit the same namespace). Darcs branches are
1618 subdirectories of a base URL just like SVN. Mercurial branches are the
1619 same as Darcs.
1621 @table @samp
1622 @item CVS
1623 branch='warner-newfeature', files=['src/foo.c']
1624 @item SVN
1625 branch='branches/warner-newfeature', files=['src/foo.c']
1626 @item Darcs
1627 branch='warner-newfeature', files=['src/foo.c']
1628 @item Mercurial
1629 branch='warner-newfeature', files=['src/foo.c']
1630 @item Arch/Bazaar
1631 branch='buildbot--usebranches--0', files=['buildbot/master.py']
1632 @item Git
1633 branch='warner-newfeature', files=['src/foo.c']
1634 @end table
1636 @heading Links
1638 @c TODO: who is using 'links'? how is it being used?
1640 Finally, the Change might have a @code{links} list, which is intended
1641 to provide a list of URLs to a @emph{viewcvs}-style web page that
1642 provides more detail for this Change, perhaps including the full file
1643 diffs.
1646 @node Schedulers, BuildSet, Version Control Systems, Concepts
1647 @section Schedulers
1649 @cindex Scheduler
1651 Each Buildmaster has a set of @code{Scheduler} objects, each of which
1652 gets a copy of every incoming Change. The Schedulers are responsible
1653 for deciding when Builds should be run. Some Buildbot installations
1654 might have a single Scheduler, while others may have several, each for
1655 a different purpose.
1657 For example, a ``quick'' scheduler might exist to give immediate
1658 feedback to developers, hoping to catch obvious problems in the code
1659 that can be detected quickly. These typically do not run the full test
1660 suite, nor do they run on a wide variety of platforms. They also
1661 usually do a VC update rather than performing a brand-new checkout
1662 each time. You could have a ``quick'' scheduler which used a 30 second
1663 timeout, and feeds a single ``quick'' Builder that uses a VC
1664 @code{mode='update'} setting.
1666 A separate ``full'' scheduler would run more comprehensive tests a
1667 little while later, to catch more subtle problems. This scheduler
1668 would have a longer tree-stable-timer, maybe 30 minutes, and would
1669 feed multiple Builders (with a @code{mode=} of @code{'copy'},
1670 @code{'clobber'}, or @code{'export'}).
1672 The @code{tree-stable-timer} and @code{fileIsImportant} decisions are
1673 made by the Scheduler. Dependencies are also implemented here.
1674 Periodic builds (those which are run every N seconds rather than after
1675 new Changes arrive) are triggered by a special @code{Periodic}
1676 Scheduler subclass. The default Scheduler class can also be told to
1677 watch for specific branches, ignoring Changes on other branches. This
1678 may be useful if you have a trunk and a few release branches which
1679 should be tracked, but when you don't want to have the Buildbot pay
1680 attention to several dozen private user branches.
1682 When the setup has multiple sources of Changes the @code{category}
1683 can be used for @code{Scheduler} objects to filter out a subset
1684 of the Changes.  Note that not all change sources can attach a category.
1686 Some Schedulers may trigger builds for other reasons, other than
1687 recent Changes. For example, a Scheduler subclass could connect to a
1688 remote buildmaster and watch for builds of a library to succeed before
1689 triggering a local build that uses that library.
1691 Each Scheduler creates and submits @code{BuildSet} objects to the
1692 @code{BuildMaster}, which is then responsible for making sure the
1693 individual @code{BuildRequests} are delivered to the target
1694 @code{Builders}.
1696 @code{Scheduler} instances are activated by placing them in the
1697 @code{c['schedulers']} list in the buildmaster config file. Each
1698 Scheduler has a unique name.
1701 @node BuildSet, BuildRequest, Schedulers, Concepts
1702 @section BuildSet
1704 @cindex BuildSet
1706 A @code{BuildSet} is the name given to a set of Builds that all
1707 compile/test the same version of the tree on multiple Builders. In
1708 general, all these component Builds will perform the same sequence of
1709 Steps, using the same source code, but on different platforms or
1710 against a different set of libraries.
1712 The @code{BuildSet} is tracked as a single unit, which fails if any of
1713 the component Builds have failed, and therefore can succeed only if
1714 @emph{all} of the component Builds have succeeded. There are two kinds
1715 of status notification messages that can be emitted for a BuildSet:
1716 the @code{firstFailure} type (which fires as soon as we know the
1717 BuildSet will fail), and the @code{Finished} type (which fires once
1718 the BuildSet has completely finished, regardless of whether the
1719 overall set passed or failed).
1721 A @code{BuildSet} is created with a @emph{source stamp} tuple of
1722 (branch, revision, changes, patch), some of which may be None, and a
1723 list of Builders on which it is to be run. They are then given to the
1724 BuildMaster, which is responsible for creating a separate
1725 @code{BuildRequest} for each Builder.
1727 There are a couple of different likely values for the
1728 @code{SourceStamp}:
1730 @table @code
1731 @item (revision=None, changes=[CHANGES], patch=None)
1732 This is a @code{SourceStamp} used when a series of Changes have
1733 triggered a build. The VC step will attempt to check out a tree that
1734 contains CHANGES (and any changes that occurred before CHANGES, but
1735 not any that occurred after them).
1737 @item (revision=None, changes=None, patch=None)
1738 This builds the most recent code on the default branch. This is the
1739 sort of @code{SourceStamp} that would be used on a Build that was
1740 triggered by a user request, or a Periodic scheduler. It is also
1741 possible to configure the VC Source Step to always check out the
1742 latest sources rather than paying attention to the Changes in the
1743 SourceStamp, which will result in same behavior as this.
1745 @item (branch=BRANCH, revision=None, changes=None, patch=None)
1746 This builds the most recent code on the given BRANCH. Again, this is
1747 generally triggered by a user request or Periodic build.
1749 @item (revision=REV, changes=None, patch=(LEVEL, DIFF))
1750 This checks out the tree at the given revision REV, then applies a
1751 patch (using @code{patch -pLEVEL <DIFF}). The @ref{try} feature uses
1752 this kind of @code{SourceStamp}. If @code{patch} is None, the patching
1753 step is bypassed.
1755 @end table
1757 The buildmaster is responsible for turning the @code{BuildSet} into a
1758 set of @code{BuildRequest} objects and queueing them on the
1759 appropriate Builders.
1762 @node BuildRequest, Builder, BuildSet, Concepts
1763 @section BuildRequest
1765 @cindex BuildRequest
1767 A @code{BuildRequest} is a request to build a specific set of sources
1768 on a single specific @code{Builder}. Each @code{Builder} runs the
1769 @code{BuildRequest} as soon as it can (i.e. when an associated
1770 buildslave becomes free). @code{BuildRequest}s are prioritized from
1771 oldest to newest, so when a buildslave becomes free, the
1772 @code{Builder} with the oldest @code{BuildRequest} is run.
1774 The @code{BuildRequest} contains the @code{SourceStamp} specification.
1775 The actual process of running the build (the series of Steps that will
1776 be executed) is implemented by the @code{Build} object. In this future
1777 this might be changed, to have the @code{Build} define @emph{what}
1778 gets built, and a separate @code{BuildProcess} (provided by the
1779 Builder) to define @emph{how} it gets built.
1781 @code{BuildRequest} is created with optional @code{Properties}.  One
1782 of these, @code{owner}, is collected by the resultant @code{Build} and
1783 added to the set of @emph{interested users} to which status
1784 notifications will be sent, depending on the configuration for each
1785 status object.
1787 The @code{BuildRequest} may be mergeable with other compatible
1788 @code{BuildRequest}s. Builds that are triggered by incoming Changes
1789 will generally be mergeable. Builds that are triggered by user
1790 requests are generally not, unless they are multiple requests to build
1791 the @emph{latest sources} of the same branch.
1793 @node Builder, Users, BuildRequest, Concepts
1794 @section Builder
1796 @cindex Builder
1798 The @code{Builder} is a long-lived object which controls all Builds of
1799 a given type. Each one is created when the config file is first
1800 parsed, and lives forever (or rather until it is removed from the
1801 config file). It mediates the connections to the buildslaves that do
1802 all the work, and is responsible for creating the @code{Build} objects
1803 that decide @emph{how} a build is performed (i.e., which steps are
1804 executed in what order).
1806 Each @code{Builder} gets a unique name, and the path name of a
1807 directory where it gets to do all its work (there is a
1808 buildmaster-side directory for keeping status information, as well as
1809 a buildslave-side directory where the actual checkout/compile/test
1810 commands are executed). It also gets a @code{BuildFactory}, which is
1811 responsible for creating new @code{Build} instances: because the
1812 @code{Build} instance is what actually performs each build, choosing
1813 the @code{BuildFactory} is the way to specify what happens each time a
1814 build is done.
1816 Each @code{Builder} is associated with one of more @code{BuildSlaves}.
1817 A @code{Builder} which is used to perform OS-X builds (as opposed to
1818 Linux or Solaris builds) should naturally be associated with an
1819 OS-X-based buildslave.
1821 A @code{Builder} may be given a set of environment variables to be used
1822 in its @pxref{ShellCommand}s. These variables will override anything in the
1823 buildslave's environment. Variables passed directly to a ShellCommand will
1824 override variables of the same name passed to the Builder.
1826 For example, if you a pool of identical slaves it is often easier to manage
1827 variables like PATH from Buildbot rather than manually editing it inside of
1828 the slaves' environment.
1830 @example
1831 f = factory.BuildFactory
1832 f.addStep(ShellCommand(
1833               command=['bash', './configure']))
1834 f.addStep(Compile())
1836 c['builders'] = [
1837   @{'name': 'test', 'slavenames': ['slave1', 'slave2', 'slave3', 'slave4',
1838                                    'slave5', 'slave6'],
1839     'builddir': 'test', 'factory': f',
1840     'env': @{'PATH': '/opt/local/bin:/opt/app/bin:/usr/local/bin:/usr/bin'@}@}
1842 @end example
1844 @node Users, Build Properties, Builder, Concepts
1845 @section Users
1847 @cindex Users
1849 Buildbot has a somewhat limited awareness of @emph{users}. It assumes
1850 the world consists of a set of developers, each of whom can be
1851 described by a couple of simple attributes. These developers make
1852 changes to the source code, causing builds which may succeed or fail.
1854 Each developer is primarily known through the source control system. Each
1855 Change object that arrives is tagged with a @code{who} field that
1856 typically gives the account name (on the repository machine) of the user
1857 responsible for that change. This string is the primary key by which the
1858 User is known, and is displayed on the HTML status pages and in each Build's
1859 ``blamelist''.
1861 To do more with the User than just refer to them, this username needs to
1862 be mapped into an address of some sort. The responsibility for this mapping
1863 is left up to the status module which needs the address. The core code knows
1864 nothing about email addresses or IRC nicknames, just user names.
1866 @menu
1867 * Doing Things With Users::
1868 * Email Addresses::
1869 * IRC Nicknames::
1870 * Live Status Clients::
1871 @end menu
1873 @node Doing Things With Users, Email Addresses, Users, Users
1874 @subsection Doing Things With Users
1876 Each Change has a single User who is responsible for that Change. Most
1877 Builds have a set of Changes: the Build represents the first time these
1878 Changes have been built and tested by the Buildbot. The build has a
1879 ``blamelist'' that consists of a simple union of the Users responsible
1880 for all the Build's Changes.
1882 The Build provides (through the IBuildStatus interface) a list of Users
1883 who are ``involved'' in the build. For now this is equal to the
1884 blamelist, but in the future it will be expanded to include a ``build
1885 sheriff'' (a person who is ``on duty'' at that time and responsible for
1886 watching over all builds that occur during their shift), as well as
1887 per-module owners who simply want to keep watch over their domain (chosen by
1888 subdirectory or a regexp matched against the filenames pulled out of the
1889 Changes). The Involved Users are those who probably have an interest in the
1890 results of any given build.
1892 In the future, Buildbot will acquire the concept of ``Problems'',
1893 which last longer than builds and have beginnings and ends. For example, a
1894 test case which passed in one build and then failed in the next is a
1895 Problem. The Problem lasts until the test case starts passing again, at
1896 which point the Problem is said to be ``resolved''.
1898 If there appears to be a code change that went into the tree at the
1899 same time as the test started failing, that Change is marked as being
1900 resposible for the Problem, and the user who made the change is added
1901 to the Problem's ``Guilty'' list. In addition to this user, there may
1902 be others who share responsibility for the Problem (module owners,
1903 sponsoring developers). In addition to the Responsible Users, there
1904 may be a set of Interested Users, who take an interest in the fate of
1905 the Problem.
1907 Problems therefore have sets of Users who may want to be kept aware of
1908 the condition of the problem as it changes over time. If configured, the
1909 Buildbot can pester everyone on the Responsible list with increasing
1910 harshness until the problem is resolved, with the most harshness reserved
1911 for the Guilty parties themselves. The Interested Users may merely be told
1912 when the problem starts and stops, as they are not actually responsible for
1913 fixing anything.
1915 @node Email Addresses, IRC Nicknames, Doing Things With Users, Users
1916 @subsection Email Addresses
1918 The @code{buildbot.status.mail.MailNotifier} class
1919 (@pxref{MailNotifier}) provides a status target which can send email
1920 about the results of each build. It accepts a static list of email
1921 addresses to which each message should be delivered, but it can also
1922 be configured to send mail to the Build's Interested Users. To do
1923 this, it needs a way to convert User names into email addresses.
1925 For many VC systems, the User Name is actually an account name on the
1926 system which hosts the repository. As such, turning the name into an
1927 email address is a simple matter of appending
1928 ``@@repositoryhost.com''. Some projects use other kinds of mappings
1929 (for example the preferred email address may be at ``project.org''
1930 despite the repository host being named ``cvs.project.org''), and some
1931 VC systems have full separation between the concept of a user and that
1932 of an account on the repository host (like Perforce). Some systems
1933 (like Arch) put a full contact email address in every change.
1935 To convert these names to addresses, the MailNotifier uses an EmailLookup
1936 object. This provides a .getAddress method which accepts a name and
1937 (eventually) returns an address. The default @code{MailNotifier}
1938 module provides an EmailLookup which simply appends a static string,
1939 configurable when the notifier is created. To create more complex behaviors
1940 (perhaps using an LDAP lookup, or using ``finger'' on a central host to
1941 determine a preferred address for the developer), provide a different object
1942 as the @code{lookup} argument.
1944 In the future, when the Problem mechanism has been set up, the Buildbot
1945 will need to send mail to arbitrary Users. It will do this by locating a
1946 MailNotifier-like object among all the buildmaster's status targets, and
1947 asking it to send messages to various Users. This means the User-to-address
1948 mapping only has to be set up once, in your MailNotifier, and every email
1949 message the buildbot emits will take advantage of it.
1951 @node IRC Nicknames, Live Status Clients, Email Addresses, Users
1952 @subsection IRC Nicknames
1954 Like MailNotifier, the @code{buildbot.status.words.IRC} class
1955 provides a status target which can announce the results of each build. It
1956 also provides an interactive interface by responding to online queries
1957 posted in the channel or sent as private messages.
1959 In the future, the buildbot can be configured map User names to IRC
1960 nicknames, to watch for the recent presence of these nicknames, and to
1961 deliver build status messages to the interested parties. Like
1962 @code{MailNotifier} does for email addresses, the @code{IRC} object
1963 will have an @code{IRCLookup} which is responsible for nicknames. The
1964 mapping can be set up statically, or it can be updated by online users
1965 themselves (by claiming a username with some kind of ``buildbot: i am
1966 user warner'' commands).
1968 Once the mapping is established, the rest of the buildbot can ask the
1969 @code{IRC} object to send messages to various users. It can report on
1970 the likelihood that the user saw the given message (based upon how long the
1971 user has been inactive on the channel), which might prompt the Problem
1972 Hassler logic to send them an email message instead.
1974 @node Live Status Clients,  , IRC Nicknames, Users
1975 @subsection Live Status Clients
1977 The Buildbot also offers a PB-based status client interface which can
1978 display real-time build status in a GUI panel on the developer's desktop.
1979 This interface is normally anonymous, but it could be configured to let the
1980 buildmaster know @emph{which} developer is using the status client. The
1981 status client could then be used as a message-delivery service, providing an
1982 alternative way to deliver low-latency high-interruption messages to the
1983 developer (like ``hey, you broke the build'').
1985 @node Build Properties,  , Users, Concepts
1986 @section Build Properties
1987 @cindex Properties
1989 Each build has a set of ``Build Properties'', which can be used by its
1990 BuildStep to modify their actions.  These properties, in the form of
1991 key-value pairs, provide a general framework for dynamically altering
1992 the behavior of a build based on its circumstances.
1994 Properties come from a number of places:
1995 @itemize
1996 @item global configuration --
1997 These properties apply to all builds.
1998 @item schedulers --
1999 A scheduler can specify properties available to all the builds it
2000 starts.
2001 @item buildslaves --
2002 A buildslave can pass properties on to the builds it performs.
2003 @item builds --
2004 A build automatically sets a number of properties on itself.
2005 @item steps --
2006 Steps of a build can set properties that are available to subsequent
2007 steps.  In particular, source steps set a number of properties.
2008 @end itemize
2010 Properties are very flexible, and can be used to implement all manner
2011 of functionality.  Here are some examples:
2013 Most Source steps record the revision that they checked out in
2014 the @code{got_revision} property.  A later step could use this
2015 property to specify the name of a fully-built tarball, dropped in an
2016 easily-acessible directory for later testing.
2018 Some projects want to perform nightly builds as well as in response
2019 to committed changes.  Such a project would run two schedulers,
2020 both pointing to the same set of builders, but could provide an
2021 @code{is_nightly} property so that steps can distinguish the nightly
2022 builds, perhaps to run more resource-intensive tests.
2024 Some projects have different build processes on different systems.
2025 Rather than create a build factory for each slave, the steps can use
2026 buildslave properties to identify the unique aspects of each slave
2027 and adapt the build process dynamically.
2029 @node Configuration, Getting Source Code Changes, Concepts, Top
2030 @chapter Configuration
2032 @cindex Configuration
2034 The buildbot's behavior is defined by the ``config file'', which
2035 normally lives in the @file{master.cfg} file in the buildmaster's base
2036 directory (but this can be changed with an option to the
2037 @code{buildbot create-master} command). This file completely specifies
2038 which Builders are to be run, which slaves they should use, how
2039 Changes should be tracked, and where the status information is to be
2040 sent. The buildmaster's @file{buildbot.tac} file names the base
2041 directory; everything else comes from the config file.
2043 A sample config file was installed for you when you created the
2044 buildmaster, but you will need to edit it before your buildbot will do
2045 anything useful.
2047 This chapter gives an overview of the format of this file and the
2048 various sections in it. You will need to read the later chapters to
2049 understand how to fill in each section properly.
2051 @menu
2052 * Config File Format::
2053 * Loading the Config File::
2054 * Testing the Config File::
2055 * Defining the Project::
2056 * Change Sources and Schedulers::
2057 * Merging BuildRequests::
2058 * Prioritizing Builders::
2059 * Setting the slaveport::
2060 * Buildslave Specifiers::
2061 * On-Demand ("Latent") Buildslaves::
2062 * Defining Global Properties::
2063 * Defining Builders::
2064 * Defining Status Targets::
2065 * Limiting Memory and Disk Usage::
2066 * Debug options::
2067 @end menu
2069 @node Config File Format, Loading the Config File, Configuration, Configuration
2070 @section Config File Format
2072 The config file is, fundamentally, just a piece of Python code which
2073 defines a dictionary named @code{BuildmasterConfig}, with a number of
2074 keys that are treated specially. You don't need to know Python to do
2075 basic configuration, though, you can just copy the syntax of the
2076 sample file. If you @emph{are} comfortable writing Python code,
2077 however, you can use all the power of a full programming language to
2078 achieve more complicated configurations.
2080 The @code{BuildmasterConfig} name is the only one which matters: all
2081 other names defined during the execution of the file are discarded.
2082 When parsing the config file, the Buildmaster generally compares the
2083 old configuration with the new one and performs the minimum set of
2084 actions necessary to bring the buildbot up to date: Builders which are
2085 not changed are left untouched, and Builders which are modified get to
2086 keep their old event history.
2088 Basic Python syntax: comments start with a hash character (``#''),
2089 tuples are defined with @code{(parenthesis, pairs)}, arrays are
2090 defined with @code{[square, brackets]}, tuples and arrays are mostly
2091 interchangeable. Dictionaries (data structures which map ``keys'' to
2092 ``values'') are defined with curly braces: @code{@{'key1': 'value1',
2093 'key2': 'value2'@} }. Function calls (and object instantiation) can use
2094 named parameters, like @code{w = html.Waterfall(http_port=8010)}.
2096 The config file starts with a series of @code{import} statements,
2097 which make various kinds of Steps and Status targets available for
2098 later use. The main @code{BuildmasterConfig} dictionary is created,
2099 then it is populated with a variety of keys. These keys are broken
2100 roughly into the following sections, each of which is documented in
2101 the rest of this chapter:
2103 @itemize @bullet
2104 @item
2105 Project Definitions
2106 @item
2107 Change Sources / Schedulers
2108 @item
2109 Slaveport
2110 @item
2111 Buildslave Configuration
2112 @item
2113 Builders / Interlocks
2114 @item
2115 Status Targets
2116 @item
2117 Debug options
2118 @end itemize
2120 The config file can use a few names which are placed into its namespace:
2122 @table @code
2123 @item basedir
2124 the base directory for the buildmaster. This string has not been
2125 expanded, so it may start with a tilde. It needs to be expanded before
2126 use. The config file is located in
2127 @code{os.path.expanduser(os.path.join(basedir, 'master.cfg'))}
2129 @end table
2132 @node Loading the Config File, Testing the Config File, Config File Format, Configuration
2133 @section Loading the Config File
2135 The config file is only read at specific points in time. It is first
2136 read when the buildmaster is launched. Once it is running, there are
2137 various ways to ask it to reload the config file. If you are on the
2138 system hosting the buildmaster, you can send a @code{SIGHUP} signal to
2139 it: the @command{buildbot} tool has a shortcut for this:
2141 @example
2142 buildbot reconfig @var{BASEDIR}
2143 @end example
2145 This command will show you all of the lines from @file{twistd.log}
2146 that relate to the reconfiguration. If there are any problems during
2147 the config-file reload, they will be displayed in these lines.
2149 The debug tool (@code{buildbot debugclient --master HOST:PORT}) has a
2150 ``Reload .cfg'' button which will also trigger a reload. In the
2151 future, there will be other ways to accomplish this step (probably a
2152 password-protected button on the web page, as well as a privileged IRC
2153 command).
2155 When reloading the config file, the buildmaster will endeavor to
2156 change as little as possible about the running system. For example,
2157 although old status targets may be shut down and new ones started up,
2158 any status targets that were not changed since the last time the
2159 config file was read will be left running and untouched. Likewise any
2160 Builders which have not been changed will be left running. If a
2161 Builder is modified (say, the build process is changed) while a Build
2162 is currently running, that Build will keep running with the old
2163 process until it completes. Any previously queued Builds (or Builds
2164 which get queued after the reconfig) will use the new process.
2166 @node Testing the Config File, Defining the Project, Loading the Config File, Configuration
2167 @section Testing the Config File
2169 To verify that the config file is well-formed and contains no deprecated or
2170 invalid elements, use the ``checkconfig'' command, passing it either a master
2171 directory or a config file.
2173 @example
2174 % buildbot checkconfig master.cfg
2175 Config file is good!
2176 # or
2177 % buildbot checkconfig /tmp/masterdir
2178 Config file is good!
2179 @end example
2181 If the config file has deprecated features (perhaps because you've
2182 upgraded the buildmaster and need to update the config file to match),
2183 they will be announced by checkconfig. In this case, the config file
2184 will work, but you should really remove the deprecated items and use
2185 the recommended replacements instead:
2187 @example
2188 % buildbot checkconfig master.cfg
2189 /usr/lib/python2.4/site-packages/buildbot/master.py:559: DeprecationWarning: c['sources'] is
2190 deprecated as of 0.7.6 and will be removed by 0.8.0 . Please use c['change_source'] instead.
2191   warnings.warn(m, DeprecationWarning)
2192 Config file is good!
2193 @end example
2195 If the config file is simply broken, that will be caught too:
2197 @example
2198 % buildbot checkconfig master.cfg
2199 Traceback (most recent call last):
2200   File "/usr/lib/python2.4/site-packages/buildbot/scripts/runner.py", line 834, in doCheckConfig
2201     ConfigLoader(configFile)
2202   File "/usr/lib/python2.4/site-packages/buildbot/scripts/checkconfig.py", line 31, in __init__
2203     self.loadConfig(configFile)
2204   File "/usr/lib/python2.4/site-packages/buildbot/master.py", line 480, in loadConfig
2205     exec f in localDict
2206   File "/home/warner/BuildBot/master/foolscap/master.cfg", line 90, in ?
2207     c[bogus] = "stuff"
2208 NameError: name 'bogus' is not defined
2209 @end example
2212 @node Defining the Project, Change Sources and Schedulers, Testing the Config File, Configuration
2213 @section Defining the Project
2215 There are a couple of basic settings that you use to tell the buildbot
2216 what project it is working on. This information is used by status
2217 reporters to let users find out more about the codebase being
2218 exercised by this particular Buildbot installation.
2220 @example
2221 c['projectName'] = "Buildbot"
2222 c['projectURL'] = "http://buildbot.sourceforge.net/"
2223 c['buildbotURL'] = "http://localhost:8010/"
2224 @end example
2226 @bcindex c['projectName']
2227 @code{projectName} is a short string will be used to describe the
2228 project that this buildbot is working on. For example, it is used as
2229 the title of the waterfall HTML page.
2231 @bcindex c['projectURL']
2232 @code{projectURL} is a string that gives a URL for the project as a
2233 whole. HTML status displays will show @code{projectName} as a link to
2234 @code{projectURL}, to provide a link from buildbot HTML pages to your
2235 project's home page.
2237 @bcindex c['buildbotURL']
2238 The @code{buildbotURL} string should point to the location where the
2239 buildbot's internal web server (usually the @code{html.Waterfall}
2240 page) is visible. This typically uses the port number set when you
2241 create the @code{Waterfall} object: the buildbot needs your help to
2242 figure out a suitable externally-visible host name.
2244 When status notices are sent to users (either by email or over IRC),
2245 @code{buildbotURL} will be used to create a URL to the specific build
2246 or problem that they are being notified about. It will also be made
2247 available to queriers (over IRC) who want to find out where to get
2248 more information about this buildbot.
2250 @bcindex c['logCompressionLimit']
2251 The @code{logCompressionLimit} enables bz2-compression of build logs on
2252 disk for logs that are bigger than the given size, or disables that
2253 completely if given @code{False}. The default value is 4k, which should
2254 be a reasonable default on most file systems. This setting has no impact
2255 on status plugins, and merely affects the required disk space on the
2256 master for build logs.
2259 @node Change Sources and Schedulers, Merging BuildRequests, Defining the Project, Configuration
2260 @section Change Sources and Schedulers
2262 @bcindex c['sources']
2263 @bcindex c['change_source']
2265 The @code{c['change_source']} key is the ChangeSource
2266 instance@footnote{To be precise, it is an object or a list of objects
2267 which all implement the @code{buildbot.interfaces.IChangeSource}
2268 Interface. It is unusual to have multiple ChangeSources, so this key
2269 accepts either a single ChangeSource or a sequence of them.} that
2270 defines how the buildmaster learns about source code changes. More
2271 information about what goes here is available in @xref{Getting Source
2272 Code Changes}.
2274 @example
2275 from buildbot.changes.pb import PBChangeSource
2276 c['change_source'] = PBChangeSource()
2277 @end example
2279 (note: in buildbot-0.7.5 and earlier, this key was named
2280 @code{c['sources']}, and required a list. @code{c['sources']} is
2281 deprecated as of buildbot-0.7.6 and is scheduled to be removed in a
2282 future release).
2284 @bcindex c['changeHorizon']
2286 The @code{c['changeHorizon']} key determines how many changes the master will
2287 keep a record of. One place these changes are displayed is on the waterfall
2288 page.  This parameter defaults to 0, which means keep all changes indefinitely.
2291 @bcindex c['schedulers']
2292 @code{c['schedulers']} is a list of Scheduler instances, each
2293 of which causes builds to be started on a particular set of
2294 Builders. The two basic Scheduler classes you are likely to start
2295 with are @code{Scheduler} and @code{Periodic}, but you can write a
2296 customized subclass to implement more complicated build scheduling.
2298 Scheduler arguments
2299 should always be specified by name (as keyword arguments), to allow
2300 for future expansion:
2302 @example
2303 sched = Scheduler(name="quick", builderNames=['lin', 'win'])
2304 @end example
2306 All schedulers have several arguments in common:
2308 @table @code
2309 @item name
2311 Each Scheduler must have a unique name. This is used in status
2312 displays, and is also available in the build property @code{scheduler}.
2314 @item builderNames
2316 This is the set of builders which this scheduler should trigger, specified
2317 as a list of names (strings).
2319 @item properties
2320 @cindex Properties
2322 This is a dictionary specifying properties that will be transmitted
2323 to all builds started by this scheduler.
2325 @end table
2327 Here is a brief catalog of the available Scheduler types. All these
2328 Schedulers are classes in @code{buildbot.scheduler}, and the
2329 docstrings there are the best source of documentation on the arguments
2330 taken by each one.
2332 @menu
2333 * Scheduler Scheduler::
2334 * AnyBranchScheduler::
2335 * Dependent Scheduler::
2336 * Periodic Scheduler::
2337 * Nightly Scheduler::
2338 * Try Schedulers::
2339 * Triggerable Scheduler::
2340 @end menu
2342 @node Scheduler Scheduler, AnyBranchScheduler, Change Sources and Schedulers, Change Sources and Schedulers
2343 @subsection Scheduler Scheduler
2344 @slindex buildbot.scheduler.Scheduler
2346 This is the original and still most popular Scheduler class. It follows
2347 exactly one branch, and starts a configurable tree-stable-timer after
2348 each change on that branch. When the timer expires, it starts a build
2349 on some set of Builders. The Scheduler accepts a @code{fileIsImportant}
2350 function which can be used to ignore some Changes if they do not
2351 affect any ``important'' files.
2353 The arguments to this scheduler are:
2355 @table @code
2356 @item name
2358 @item builderNames
2360 @item properties
2362 @item branch
2363 This Scheduler will pay attention to a single branch, ignoring Changes
2364 that occur on other branches. Setting @code{branch} equal to the
2365 special value of @code{None} means it should only pay attention to
2366 the default branch. Note that @code{None} is a keyword, not a string,
2367 so you want to use @code{None} and not @code{"None"}.
2369 @item treeStableTimer
2370 The Scheduler will wait for this many seconds before starting the
2371 build. If new changes are made during this interval, the timer will be
2372 restarted, so really the build will be started after a change and then
2373 after this many seconds of inactivity.
2375 @item fileIsImportant
2376 A callable which takes one argument, a Change instance, and returns
2377 @code{True} if the change is worth building, and @code{False} if
2378 it is not.  Unimportant Changes are accumulated until the build is
2379 triggered by an important change.  The default value of None means
2380 that all Changes are important.
2382 @item categories
2383 A list of categories of changes that this scheduler will respond to.  If this
2384 is specified, then any non-matching changes are ignored.
2386 @end table
2388 Example:
2390 @example
2391 from buildbot import scheduler
2392 quick = scheduler.Scheduler(name="quick",
2393                     branch=None,
2394                     treeStableTimer=60,
2395                     builderNames=["quick-linux", "quick-netbsd"])
2396 full = scheduler.Scheduler(name="full",
2397                     branch=None,
2398                     treeStableTimer=5*60,
2399                     builderNames=["full-linux", "full-netbsd", "full-OSX"])
2400 c['schedulers'] = [quick, full]
2401 @end example
2403 In this example, the two ``quick'' builders are triggered 60 seconds
2404 after the tree has been changed. The ``full'' builds do not run quite
2405 so quickly (they wait 5 minutes), so hopefully if the quick builds
2406 fail due to a missing file or really simple typo, the developer can
2407 discover and fix the problem before the full builds are started. Both
2408 Schedulers only pay attention to the default branch: any changes
2409 on other branches are ignored by these Schedulers. Each Scheduler
2410 triggers a different set of Builders, referenced by name.
2412 @node AnyBranchScheduler, Dependent Scheduler, Scheduler Scheduler, Change Sources and Schedulers
2413 @subsection AnyBranchScheduler
2414 @slindex buildbot.scheduler.AnyBranchScheduler
2416 This scheduler uses a tree-stable-timer like the default one, but
2417 follows multiple branches at once. Each branch gets a separate timer.
2419 The arguments to this scheduler are:
2421 @table @code
2422 @item name
2424 @item builderNames
2426 @item properties
2428 @item branches
2429 This Scheduler will pay attention to any number of branches, ignoring
2430 Changes that occur on other branches. Branches are specified just as
2431 for the @code{Scheduler} class.
2433 @item treeStableTimer
2434 The Scheduler will wait for this many seconds before starting the
2435 build. If new changes are made during this interval, the timer will be
2436 restarted, so really the build will be started after a change and then
2437 after this many seconds of inactivity.
2439 @item fileIsImportant
2440 A callable which takes one argument, a Change instance, and returns
2441 @code{True} if the change is worth building, and @code{False} if
2442 it is not.  Unimportant Changes are accumulated until the build is
2443 triggered by an important change.  The default value of None means
2444 that all Changes are important.
2445 @end table
2447 @node Dependent Scheduler, Periodic Scheduler, AnyBranchScheduler, Change Sources and Schedulers
2448 @subsection Dependent Scheduler
2449 @cindex Dependent
2450 @cindex Dependencies
2451 @slindex buildbot.scheduler.Dependent
2453 It is common to wind up with one kind of build which should only be
2454 performed if the same source code was successfully handled by some
2455 other kind of build first. An example might be a packaging step: you
2456 might only want to produce .deb or RPM packages from a tree that was
2457 known to compile successfully and pass all unit tests. You could put
2458 the packaging step in the same Build as the compile and testing steps,
2459 but there might be other reasons to not do this (in particular you
2460 might have several Builders worth of compiles/tests, but only wish to
2461 do the packaging once). Another example is if you want to skip the
2462 ``full'' builds after a failing ``quick'' build of the same source
2463 code. Or, if one Build creates a product (like a compiled library)
2464 that is used by some other Builder, you'd want to make sure the
2465 consuming Build is run @emph{after} the producing one.
2467 You can use ``Dependencies'' to express this relationship
2468 to the Buildbot. There is a special kind of Scheduler named
2469 @code{scheduler.Dependent} that will watch an ``upstream'' Scheduler
2470 for builds to complete successfully (on all of its Builders). Each time
2471 that happens, the same source code (i.e. the same @code{SourceStamp})
2472 will be used to start a new set of builds, on a different set of
2473 Builders. This ``downstream'' scheduler doesn't pay attention to
2474 Changes at all. It only pays attention to the upstream scheduler.
2476 If the build fails on any of the Builders in the upstream set,
2477 the downstream builds will not fire.  Note that, for SourceStamps
2478 generated by a ChangeSource, the @code{revision} is None, meaning HEAD.
2479 If any changes are committed between the time the upstream scheduler
2480 begins its build and the time the dependent scheduler begins its
2481 build, then those changes will be included in the downstream build.
2482 See the @pxref{Triggerable Scheduler} for a more flexible dependency
2483 mechanism that can avoid this problem.
2485 The arguments to this scheduler are:
2487 @table @code
2488 @item name
2490 @item builderNames
2492 @item properties
2494 @item upstream
2495 The upstream scheduler to watch.  Note that this is an ``instance'',
2496 not the name of the scheduler.
2497 @end table
2499 Example:
2501 @example
2502 from buildbot import scheduler
2503 tests = scheduler.Scheduler("just-tests", None, 5*60,
2504                             ["full-linux", "full-netbsd", "full-OSX"])
2505 package = scheduler.Dependent("build-package",
2506                               tests, # upstream scheduler -- no quotes!
2507                               ["make-tarball", "make-deb", "make-rpm"])
2508 c['schedulers'] = [tests, package]
2509 @end example
2511 @node Periodic Scheduler, Nightly Scheduler, Dependent Scheduler, Change Sources and Schedulers
2512 @subsection Periodic Scheduler
2513 @slindex buildbot.scheduler.Periodic
2515 This simple scheduler just triggers a build every N seconds.
2517 The arguments to this scheduler are:
2519 @table @code
2520 @item name
2522 @item builderNames
2524 @item properties
2526 @item periodicBuildTimer
2527 The time, in seconds, after which to start a build.
2528 @end table
2530 Example:
2532 @example
2533 from buildbot import scheduler
2534 nightly = scheduler.Periodic(name="nightly",
2535                 builderNames=["full-solaris"],
2536                 periodicBuildTimer=24*60*60)
2537 c['schedulers'] = [nightly]
2538 @end example
2540 The Scheduler in this example just runs the full solaris build once
2541 per day. Note that this Scheduler only lets you control the time
2542 between builds, not the absolute time-of-day of each Build, so this
2543 could easily wind up a ``daily'' or ``every afternoon'' scheduler
2544 depending upon when it was first activated.
2546 @node Nightly Scheduler, Try Schedulers, Periodic Scheduler, Change Sources and Schedulers
2547 @subsection Nightly Scheduler
2548 @slindex buildbot.scheduler.Nightly
2550 This is highly configurable periodic build scheduler, which triggers
2551 a build at particular times of day, week, month, or year. The
2552 configuration syntax is very similar to the well-known @code{crontab}
2553 format, in which you provide values for minute, hour, day, and month
2554 (some of which can be wildcards), and a build is triggered whenever
2555 the current time matches the given constraints. This can run a build
2556 every night, every morning, every weekend, alternate Thursdays,
2557 on your boss's birthday, etc.
2559 Pass some subset of @code{minute}, @code{hour}, @code{dayOfMonth},
2560 @code{month}, and @code{dayOfWeek}; each may be a single number or
2561 a list of valid values. The builds will be triggered whenever the
2562 current time matches these values. Wildcards are represented by a
2563 '*' string. All fields default to a wildcard except 'minute', so
2564 with no fields this defaults to a build every hour, on the hour.
2565 The full list of parameters is:
2567 @table @code
2568 @item name
2570 @item builderNames
2572 @item properties
2574 @item branch
2575 The branch to build, just as for @code{Scheduler}.
2577 @item minute
2578 The minute of the hour on which to start the build.  This defaults
2579 to 0, meaning an hourly build.
2581 @item hour
2582 The hour of the day on which to start the build, in 24-hour notation.
2583 This defaults to *, meaning every hour.
2585 @item month
2586 The month in which to start the build, with January = 1.  This defaults
2587 to *, meaning every month.
2589 @item dayOfWeek
2590 The day of the week to start a build, with Monday = 0.  This defauls
2591 to *, meaning every day of the week.
2593 @item onlyIfChanged
2594 If this is true, then builds will not be scheduled at the designated time
2595 unless the source has changed since the previous build.
2596 @end table
2598 For example, the following master.cfg clause will cause a build to be
2599 started every night at 3:00am:
2601 @example
2602 s = scheduler.Nightly(name='nightly',
2603         builderNames=['builder1', 'builder2'],
2604         hour=3,
2605         minute=0)
2606 @end example
2608 This scheduler will perform a build each monday morning at 6:23am and
2609 again at 8:23am, but only if someone has committed code in the interim:
2611 @example
2612 s = scheduler.Nightly(name='BeforeWork',
2613          builderNames=['builder1'],
2614          dayOfWeek=0,
2615          hour=[6,8],
2616          minute=23,
2617          onlyIfChanged=True)
2618 @end example
2620 The following runs a build every two hours, using Python's @code{range}
2621 function:
2623 @example
2624 s = Nightly(name='every2hours',
2625         builderNames=['builder1'],
2626         hour=range(0, 24, 2))
2627 @end example
2629 Finally, this example will run only on December 24th:
2631 @example
2632 s = Nightly(name='SleighPreflightCheck',
2633         builderNames=['flying_circuits', 'radar'],
2634         month=12,
2635         dayOfMonth=24,
2636         hour=12,
2637         minute=0)
2638 @end example
2640 @node Try Schedulers, Triggerable Scheduler, Nightly Scheduler, Change Sources and Schedulers
2641 @subsection Try Schedulers
2642 @slindex buildbot.scheduler.Try_Jobdir
2643 @slindex buildbot.scheduler.Try_Userpass
2645 This scheduler allows developers to use the @code{buildbot try}
2646 command to trigger builds of code they have not yet committed. See
2647 @ref{try} for complete details.
2649 Two implementations are available: @code{Try_Jobdir} and
2650 @code{Try_Userpass}.  The former monitors a job directory, specified
2651 by the @code{jobdir} parameter, while the latter listens for PB
2652 connections on a specific @code{port}, and authenticates against
2653 @code{userport}.
2655 @node Triggerable Scheduler,  , Try Schedulers, Change Sources and Schedulers
2656 @subsection Triggerable Scheduler
2657 @cindex Triggers
2658 @slindex buildbot.scheduler.Triggerable
2660 The @code{Triggerable} scheduler waits to be triggered by a Trigger
2661 step (see @ref{Triggering Schedulers}) in another build. That step
2662 can optionally wait for the scheduler's builds to complete. This
2663 provides two advantages over Dependent schedulers. First, the same
2664 scheduler can be triggered from multiple builds. Second, the ability
2665 to wait for a Triggerable's builds to complete provides a form of
2666 "subroutine call", where one or more builds can "call" a scheduler
2667 to perform some work for them, perhaps on other buildslaves.
2669 The parameters are just the basics:
2671 @table @code
2672 @item name
2673 @item builderNames
2674 @item properties
2675 @end table
2677 This class is only useful in conjunction with the @code{Trigger} step.
2678 Here is a fully-worked example:
2680 @example
2681 from buildbot import scheduler
2682 from buildbot.process import factory
2683 from buildbot.steps import trigger
2685 checkin = scheduler.Scheduler(name="checkin",
2686             branch=None,
2687             treeStableTimer=5*60,
2688             builderNames=["checkin"])
2689 nightly = scheduler.Nightly(name='nightly',
2690             builderNames=['nightly'],
2691             hour=3,
2692             minute=0)
2694 mktarball = scheduler.Triggerable(name="mktarball",
2695                 builderNames=["mktarball"])
2696 build = scheduler.Triggerable(name="build-all-platforms",
2697                 builderNames=["build-all-platforms"])
2698 test = scheduler.Triggerable(name="distributed-test",
2699                 builderNames=["distributed-test"])
2700 package = scheduler.Triggerable(name="package-all-platforms",
2701                 builderNames=["package-all-platforms"])
2703 c['schedulers'] = [checkin, nightly, build, test, package]
2705 # on checkin, make a tarball, build it, and test it
2706 checkin_factory = factory.BuildFactory()
2707 checkin_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2708                                        waitForFinish=True))
2709 checkin_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2710                                    waitForFinish=True))
2711 checkin_factory.addStep(trigger.Trigger(schedulerNames=['distributed-test'],
2712                                   waitForFinish=True))
2714 # and every night, make a tarball, build it, and package it
2715 nightly_factory = factory.BuildFactory()
2716 nightly_factory.addStep(trigger.Trigger(schedulerNames=['mktarball'],
2717                                        waitForFinish=True))
2718 nightly_factory.addStep(trigger.Trigger(schedulerNames=['build-all-platforms'],
2719                                    waitForFinish=True))
2720 nightly_factory.addStep(trigger.Trigger(schedulerNames=['package-all-platforms'],
2721                                      waitForFinish=True))
2722 @end example
2724 @node Merging BuildRequests, Prioritizing Builders, Change Sources and Schedulers, Configuration
2725 @section Merging BuildRequests
2727 @bcindex c['mergeRequests']
2729 By default, buildbot merges BuildRequests that have the compatible
2730 SourceStamps. This behaviour can be customized with the
2731 @code{c['mergeRequests']} configuration key.  This key specifies a function
2732 which is called with three arguments: a @code{Builder} and two
2733 @code{BuildRequest} objects.  It should return true if the requests can be
2734 merged.  For example:
2736 @example
2737 def mergeRequests(builder, req1, req2):
2738     """Don't merge buildrequest at all"""
2739     return False
2740 c['mergeRequests'] = mergeRequests
2741 @end example
2743 In many cases, the details of the SourceStamps and BuildRequests are important.
2744 In this example, only BuildRequests with the same "reason" are merged; thus
2745 developers forcing builds for different reasons will see distinct builds.
2747 @example
2748 def mergeRequests(builder, req1, req2):
2749     if req1.source.canBeMergedWith(req2.source) and  req1.reason == req2.reason:
2750        return True
2751     return False
2752 c['mergeRequests'] = mergeRequests
2753 @end example
2755 @node Prioritizing Builders, Setting the slaveport, Merging BuildRequests, Configuration
2756 @section Prioritizing Builders
2758 @bcindex c['prioritizeBuilders']
2760 By default, buildbot will attempt to start builds on builders in order from the
2761 builder with the oldest pending request to the newest. This behaviour can be
2762 customized with the @code{c['prioritizeBuilders']} configuration key.
2763 This key specifies a function which is called with two arguments: a
2764 @code{BuildMaster} and a list of @code{Builder} objects. It
2765 should return a list of @code{Builder} objects in the desired order.
2766 It may also remove items from the list if builds should not be started
2767 on those builders.
2769 @example
2770 def prioritizeBuilders(buildmaster, builders):
2771     """Prioritize builders.  'finalRelease' builds have the highest
2772     priority, so they should be built before running tests, or
2773     creating builds."""
2774     builderPriorities = @{
2775         "finalRelease": 0,
2776         "test": 1,
2777         "build": 2,
2778     @}
2779     builders.sort(key=lambda b: builderPriorities.get(b.name, 0))
2780     return builders
2782 c['prioritizeBuilders'] = prioritizeBuilders
2783 @end example
2784             
2786 @node Setting the slaveport, Buildslave Specifiers, Prioritizing Builders, Configuration
2787 @section Setting the slaveport
2789 @bcindex c['slavePortnum']
2791 The buildmaster will listen on a TCP port of your choosing for
2792 connections from buildslaves. It can also use this port for
2793 connections from remote Change Sources, status clients, and debug
2794 tools. This port should be visible to the outside world, and you'll
2795 need to tell your buildslave admins about your choice.
2797 It does not matter which port you pick, as long it is externally
2798 visible, however you should probably use something larger than 1024,
2799 since most operating systems don't allow non-root processes to bind to
2800 low-numbered ports. If your buildmaster is behind a firewall or a NAT
2801 box of some sort, you may have to configure your firewall to permit
2802 inbound connections to this port.
2804 @example
2805 c['slavePortnum'] = 10000
2806 @end example
2808 @code{c['slavePortnum']} is a @emph{strports} specification string,
2809 defined in the @code{twisted.application.strports} module (try
2810 @command{pydoc twisted.application.strports} to get documentation on
2811 the format). This means that you can have the buildmaster listen on a
2812 localhost-only port by doing:
2814 @example
2815 c['slavePortnum'] = "tcp:10000:interface=127.0.0.1"
2816 @end example
2818 This might be useful if you only run buildslaves on the same machine,
2819 and they are all configured to contact the buildmaster at
2820 @code{localhost:10000}.
2823 @node Buildslave Specifiers, On-Demand ("Latent") Buildslaves, Setting the slaveport, Configuration
2824 @section Buildslave Specifiers
2825 @bcindex c['slaves']
2827 The @code{c['slaves']} key is a list of known buildslaves. In the common case,
2828 each buildslave is defined by an instance of the BuildSlave class.  It
2829 represents a standard, manually started machine that will try to connect to
2830 the buildbot master as a slave.  Contrast these with the "on-demand" latent
2831 buildslaves, such as the Amazon Web Service Elastic Compute Cloud latent
2832 buildslave discussed below.
2834 The BuildSlave class is instantiated with two values: (slavename,
2835 slavepassword). These are the same two values that need to be provided to the
2836 buildslave administrator when they create the buildslave.
2838 The slavenames must be unique, of course. The password exists to
2839 prevent evildoers from interfering with the buildbot by inserting
2840 their own (broken) buildslaves into the system and thus displacing the
2841 real ones.
2843 Buildslaves with an unrecognized slavename or a non-matching password
2844 will be rejected when they attempt to connect, and a message
2845 describing the problem will be put in the log file (see @ref{Logfiles}).
2847 @example
2848 from buildbot.buildslave import BuildSlave
2849 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd')
2850                BuildSlave('bot-bsd', 'bsdpasswd')
2851               ]
2852 @end example
2854 @cindex Properties
2855 @code{BuildSlave} objects can also be created with an optional
2856 @code{properties} argument, a dictionary specifying properties that
2857 will be available to any builds performed on this slave.  For example:
2859 @example
2860 from buildbot.buildslave import BuildSlave
2861 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2862                     properties=@{'os':'solaris'@}),
2863               ]
2864 @end example
2866 The @code{BuildSlave} constructor can also take an optional
2867 @code{max_builds} parameter to limit the number of builds that it
2868 will execute simultaneously:
2870 @example
2871 from buildbot.buildslave import BuildSlave
2872 c['slaves'] = [BuildSlave("bot-linux", "linuxpassword", max_builds=2)]
2873 @end example
2875 Historical note: in buildbot-0.7.5 and earlier, the @code{c['bots']}
2876 key was used instead, and it took a list of (name, password) tuples.
2877 This key is accepted for backwards compatibility, but is deprecated as
2878 of 0.7.6 and will go away in some future release.
2880 @menu
2881 * When Buildslaves Go Missing::
2882 @end menu
2884 @node When Buildslaves Go Missing, , , Buildslave Specifiers
2885 @subsection When Buildslaves Go Missing
2887 Sometimes, the buildslaves go away. One very common reason for this is
2888 when the buildslave process is started once (manually) and left
2889 running, but then later the machine reboots and the process is not
2890 automatically restarted.
2892 If you'd like to have the administrator of the buildslave (or other
2893 people) be notified by email when the buildslave has been missing for
2894 too long, just add the @code{notify_on_missing=} argument to the
2895 @code{BuildSlave} definition:
2897 @example
2898 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2899                           notify_on_missing="bob@@example.com"),
2900               ]
2901 @end example
2903 By default, this will send email when the buildslave has been
2904 disconnected for more than one hour. Only one email per
2905 connection-loss event will be sent. To change the timeout, use
2906 @code{missing_timeout=} and give it a number of seconds (the default
2907 is 3600).
2909 You can have the buildmaster send email to multiple recipients: just
2910 provide a list of addresses instead of a single one:
2912 @example
2913 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2914                           notify_on_missing=["bob@@example.com",
2915                                              "alice@@example.org"],
2916                           missing_timeout=300, # notify after 5 minutes
2917                           ),
2918               ]
2919 @end example
2921 The email sent this way will use a MailNotifier (@pxref{MailNotifier})
2922 status target, if one is configured. This provides a way for you to
2923 control the ``from'' address of the email, as well as the relayhost
2924 (aka ``smarthost'') to use as an SMTP server. If no MailNotifier is
2925 configured on this buildmaster, the buildslave-missing emails will be
2926 sent using a default configuration.
2928 Note that if you want to have a MailNotifier for buildslave-missing
2929 emails but not for regular build emails, just create one with
2930 builders=[], as follows:
2932 @example
2933 from buildbot.status import mail
2934 m = mail.MailNotifier(fromaddr="buildbot@@localhost", builders=[],
2935                       relayhost="smtp.example.org")
2936 c['status'].append(m)
2937 c['slaves'] = [BuildSlave('bot-solaris', 'solarispasswd',
2938                           notify_on_missing="bob@@example.com"),
2939               ]
2940 @end example
2942 @node On-Demand ("Latent") Buildslaves, Defining Global Properties, Buildslave Specifiers, Configuration
2943 @section On-Demand ("Latent") Buildslaves
2945 The standard buildbot model has slaves started manually.  The previous section
2946 described how to configure the master for this approach.
2948 Another approach is to let the buildbot master start slaves when builds are
2949 ready, on-demand.  Thanks to services such as Amazon Web Services' Elastic
2950 Compute Cloud ("AWS EC2"), this is relatively easy to set up, and can be
2951 very useful for some situations.
2953 The buildslaves that are started on-demand are called "latent" buildslaves.
2954 As of this writing, buildbot ships with an abstract base class for building
2955 latent buildslaves, and a concrete implementation for AWS EC2.
2957 @menu
2958 * Amazon Web Services Elastic Compute Cloud ("AWS EC2")::
2959 * Dangers with Latent Buildslaves::
2960 * Writing New Latent Buildslaves::
2961 @end menu
2963 @node Amazon Web Services Elastic Compute Cloud ("AWS EC2"), Dangers with Latent Buildslaves, , On-Demand ("Latent") Buildslaves
2964 @subsection Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2966 @url{http://aws.amazon.com/ec2/,,AWS EC2} is a web service that allows you to
2967 start virtual machines in an Amazon data center. Please see their website for
2968 details, incuding costs. Using the AWS EC2 latent buildslaves involves getting
2969 an EC2 account with AWS and setting up payment; customizing one or more EC2
2970 machine images ("AMIs") on your desired operating system(s) and publishing
2971 them (privately if needed); and configuring the buildbot master to know how to
2972 start your customized images for "substantiating" your latent slaves.
2974 @menu
2975 * Get an AWS EC2 Account::
2976 * Create an AMI::
2977 * Configure the Master with an EC2LatentBuildSlave::
2978 @end menu
2980 @node Get an AWS EC2 Account, Create an AMI, , Amazon Web Services Elastic Compute Cloud ("AWS EC2")
2981 @subsubsection Get an AWS EC2 Account
2983 To start off, to use the AWS EC2 latent buildslave, you need to get an AWS
2984 developer account and sign up for EC2. These instructions may help you get
2985 started:
2987 @itemize @bullet
2988 @item
2989 Go to http://aws.amazon.com/ and click to "Sign Up Now" for an AWS account.
2991 @item
2992 Once you are logged into your account, you need to sign up for EC2.
2993 Instructions for how to do this have changed over time because Amazon changes
2994 their website, so the best advice is to hunt for it. After signing up for EC2,
2995 it may say it wants you to upload an x.509 cert. You will need this to create
2996 images (see below) but it is not technically necessary for the buildbot master
2997 configuration.
2999 @item
3000 You must enter a valid credit card before you will be able to use EC2. Do that
3001 under 'Payment Method'.
3003 @item
3004 Make sure you're signed up for EC2 by going to 'Your Account'->'Account
3005 Activity' and verifying EC2 is listed.
3006 @end itemize
3008 @node Create an AMI, Configure the Master with an EC2LatentBuildSlave, Get an AWS EC2 Account, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
3009 @subsubsection Create an AMI
3011 Now you need to create an AMI and configure the master.  You may need to
3012 run through this cycle a few times to get it working, but these instructions
3013 should get you started.
3015 Creating an AMI is out of the scope of this document.  The
3016 @url{http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/,,EC2 Getting Started Guide}
3017 is a good resource for this task.  Here are a few additional hints.
3019 @itemize @bullet
3020 @item
3021 When an instance of the image starts, it needs to automatically start a
3022 buildbot slave that connects to your master (to create a buildbot slave,
3023 @pxref{Creating a buildslave}; to make a daemon,
3024 @pxref{Launching the daemons}).
3026 @item
3027 You may want to make an instance of the buildbot slave, configure it as a
3028 standard buildslave in the master (i.e., not as a latent slave), and test and
3029 debug it that way before you turn it into an AMI and convert to a latent
3030 slave in the master.
3031 @end itemize
3033 @node Configure the Master with an EC2LatentBuildSlave, , Create an AMI, Amazon Web Services Elastic Compute Cloud ("AWS EC2")
3034 @subsubsection Configure the Master with an EC2LatentBuildSlave
3036 Now let's assume you have an AMI that should work with the
3037 EC2LatentBuildSlave.  It's now time to set up your buildbot master
3038 configuration.
3040 You will need some information from your AWS account: the "Access Key Id" and
3041 the "Secret Access Key".  If you've built the AMI yourself, you probably
3042 already are familiar with these values.  If you have not, and someone has
3043 given you access to an AMI, these hints may help you find the necessary
3044 values:
3046 @itemize @bullet
3047 @item
3048 While logged into your AWS account, find the "Access Identifiers" link (either
3049 on the left, or via "Your Account" -> "Access Identifiers".
3051 @item
3052 On the page, you'll see alphanumeric values for "Your Access Key Id:" and
3053 "Your Secret Access Key:". Make a note of these. Later on, we'll call the
3054 first one your "identifier" and the second one your "secret_identifier."
3055 @end itemize
3057 When creating an EC2LatentBuildSlave in the buildbot master configuration,
3058 the first three arguments are required.  The name and password are the first
3059 two arguments, and work the same as with normal buildslaves.  The next
3060 argument specifies the type of the EC2 virtual machine (available options as
3061 of this writing include "m1.small", "m1.large", 'm1.xlarge", "c1.medium",
3062 and "c1.xlarge"; see the EC2 documentation for descriptions of these
3063 machines).
3065 Here is the simplest example of configuring an EC2 latent buildslave. It
3066 specifies all necessary remaining values explicitly in the instantiation.
3068 @example
3069 from buildbot.ec2buildslave import EC2LatentBuildSlave
3070 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3071                                    ami='ami-12345',
3072                                    identifier='publickey',
3073                                    secret_identifier='privatekey'
3074                                    )]
3075 @end example
3077 The "ami" argument specifies the AMI that the master should start.  The
3078 "identifier" argument specifies the AWS "Access Key Id," and the
3079 "secret_identifier" specifies the AWS "Secret Access Key." Both the AMI and
3080 the account information can be specified in alternate ways.
3082 Note that whoever has your identifier and secret_identifier values can request
3083 AWS work charged to your account, so these values need to be carefully
3084 protected. Another way to specify these access keys is to put them in a
3085 separate file. You can then make the access privileges stricter for this
3086 separate file, and potentially let more people read your main configuration
3087 file.
3089 By default, you can make an .ec2 directory in the home folder of the user
3090 running the buildbot master. In that directory, create a file called aws_id.
3091 The first line of that file should be your access key id; the second line
3092 should be your secret access key id. Then you can instantiate the build slave
3093 as follows.
3095 @example
3096 from buildbot.ec2buildslave import EC2LatentBuildSlave
3097 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3098                                    ami='ami-12345')]
3099 @end example
3101 If you want to put the key information in another file, use the
3102 "aws_id_file_path" initialization argument.
3104 Previous examples used a particular AMI.  If the Buildbot master will be
3105 deployed in a process-controlled environment, it may be convenient to
3106 specify the AMI more flexibly.  Rather than specifying an individual AMI,
3107 specify one or two AMI filters.
3109 In all cases, the AMI that sorts last by its location (the S3 bucket and
3110 manifest name) will be preferred.
3112 One available filter is to specify the acceptable AMI owners, by AWS account
3113 number (the 12 digit number, usually rendered in AWS with hyphens like
3114 "1234-5678-9012", should be entered as in integer).
3116 @example
3117 from buildbot.ec2buildslave import EC2LatentBuildSlave
3118 bot1 = EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3119                            valid_ami_owners=[11111111111,
3120                                              22222222222],
3121                            identifier='publickey',
3122                            secret_identifier='privatekey'
3123                            )
3124 @end example
3126 The other available filter is to provide a regular expression string that
3127 will be matched against each AMI's location (the S3 bucket and manifest name).
3129 @example
3130 from buildbot.ec2buildslave import EC2LatentBuildSlave
3131 bot1 = EC2LatentBuildSlave(
3132     'bot1', 'sekrit', 'm1.large',
3133     valid_ami_location_regex=r'buildbot\-.*/image.manifest.xml',
3134     identifier='publickey', secret_identifier='privatekey')
3135 @end example
3137 The regular expression can specify a group, which will be preferred for the
3138 sorting.  Only the first group is used; subsequent groups are ignored.
3140 @example
3141 from buildbot.ec2buildslave import EC2LatentBuildSlave
3142 bot1 = EC2LatentBuildSlave(
3143     'bot1', 'sekrit', 'm1.large',
3144     valid_ami_location_regex=r'buildbot\-.*\-(.*)/image.manifest.xml',
3145     identifier='publickey', secret_identifier='privatekey')
3146 @end example
3148 If the group can be cast to an integer, it will be.  This allows 10 to sort
3149 after 1, for instance.
3151 @example
3152 from buildbot.ec2buildslave import EC2LatentBuildSlave
3153 bot1 = EC2LatentBuildSlave(
3154     'bot1', 'sekrit', 'm1.large',
3155     valid_ami_location_regex=r'buildbot\-.*\-(\d+)/image.manifest.xml',
3156     identifier='publickey', secret_identifier='privatekey')
3157 @end example
3159 In addition to using the password as a handshake between the master and the
3160 slave, you may want to use a firewall to assert that only machines from a
3161 specific IP can connect as slaves.  This is possible with AWS EC2 by using
3162 the Elastic IP feature.  To configure, generate a Elastic IP in AWS, and then
3163 specify it in your configuration using the "elastic_ip" argument.
3165 @example
3166 from buildbot.ec2buildslave import EC2LatentBuildSlave
3167 c['slaves'] = [EC2LatentBuildSlave('bot1', 'sekrit', 'm1.large',
3168                                    'ami-12345',
3169                                    identifier='publickey',
3170                                    secret_identifier='privatekey',
3171                                    elastic_ip='208.77.188.166'
3172                                    )]
3173 @end example
3175 The EC2LatentBuildSlave supports all other configuration from the standard
3176 BuildSlave.  The "missing_timeout" and "notify_on_missing" specify how long
3177 to wait for an EC2 instance to attach before considering the attempt to have
3178 failed, and email addresses to alert, respectively.  "missing_timeout"
3179 defaults to 20 minutes.
3181 The "build_wait_timeout" allows you to specify how long an EC2LatentBuildSlave
3182 should wait after a build for another build before it shuts down the EC2
3183 instance.  It defaults to 10 minutes.
3185 "keypair_name" and "security_name" allow you to specify different names for
3186 these AWS EC2 values.  They both default to "latent_buildbot_slave".
3188 @node Dangers with Latent Buildslaves, Writing New Latent Buildslaves, Amazon Web Services Elastic Compute Cloud ("AWS EC2"), On-Demand ("Latent") Buildslaves
3189 @subsection Dangers with Latent Buildslaves
3191 Any latent build slave that interacts with a for-fee service, such as the
3192 EC2LatentBuildSlave, brings significant risks. As already identified, the
3193 configuraton will need access to account information that, if obtained by a
3194 criminal, can be used to charge services to your account. Also, bugs in the
3195 buildbot software may lead to unnecessary charges. In particular, if the
3196 master neglects to shut down an instance for some reason, a virtual machine
3197 may be running unnecessarily, charging against your account. Manual and/or
3198 automatic (e.g. nagios with a plugin using a library like boto)
3199 double-checking may be appropriate.
3201 A comparitively trivial note is that currently if two instances try to attach
3202 to the same latent buildslave, it is likely that the system will become
3203 confused.  This should not occur, unless, for instance, you configure a normal
3204 build slave to connect with the authentication of a latent buildbot.  If the
3205 situation occurs, stop all attached instances and restart the master.
3207 @node Writing New Latent Buildslaves, , Dangers with Latent Buildslaves, On-Demand ("Latent") Buildslaves
3208 @subsection Writing New Latent Buildslaves
3210 Writing a new latent buildslave should only require subclassing
3211 @code{buildbot.buildslave.AbstractLatentBuildSlave} and implementing
3212 start_instance and stop_instance.
3214 @example
3215 def start_instance(self):
3216     # responsible for starting instance that will try to connect with this
3217     # master. Should return deferred. Problems should use an errback. The
3218     # callback value can be None, or can be an iterable of short strings to
3219     # include in the "substantiate success" status message, such as
3220     # identifying the instance that started.
3221     raise NotImplementedError
3223 def stop_instance(self, fast=False):
3224     # responsible for shutting down instance. Return a deferred. If `fast`,
3225     # we're trying to shut the master down, so callback as soon as is safe.
3226     # Callback value is ignored.
3227     raise NotImplementedError
3228 @end example
3230 See @code{buildbot.ec2buildslave.EC2LatentBuildSlave} for an example, or see the
3231 test example @code{buildbot.test_slaves.FakeLatentBuildSlave}.
3233 @node Defining Global Properties, Defining Builders, On-Demand ("Latent") Buildslaves, Configuration
3234 @section Defining Global Properties
3235 @bcindex c['properties']
3236 @cindex Properties
3238 The @code{'properties'} configuration key defines a dictionary
3239 of properties that will be available to all builds started by the
3240 buildmaster:
3242 @example
3243 c['properties'] = @{
3244     'Widget-version' : '1.2',
3245     'release-stage' : 'alpha'
3247 @end example
3249 @node Defining Builders
3250 @section Defining Builders
3252 @bcindex c['builders']
3254 The @code{c['builders']} key is a list of dictionaries which specify
3255 the Builders. The Buildmaster runs a collection of Builders, each of
3256 which handles a single type of build (e.g. full versus quick), on a
3257 single build slave. A Buildbot which makes sure that the latest code
3258 (``HEAD'') compiles correctly across four separate architecture will
3259 have four Builders, each performing the same build but on different
3260 slaves (one per platform).
3262 Each Builder gets a separate column in the waterfall display. In
3263 general, each Builder runs independently (although various kinds of
3264 interlocks can cause one Builder to have an effect on another).
3266 Each Builder specification dictionary has several required keys:
3268 @table @code
3269 @item name
3270 This specifies the Builder's name, which is used in status
3271 reports.
3273 @item slavename
3274 This specifies which buildslave will be used by this Builder.
3275 @code{slavename} must appear in the @code{c['slaves']} list. Each
3276 buildslave can accomodate multiple Builders.
3278 @item slavenames
3279 If you provide @code{slavenames} instead of @code{slavename}, you can
3280 give a list of buildslaves which are capable of running this Builder.
3281 If multiple buildslaves are available for any given Builder, you will
3282 have some measure of redundancy: in case one slave goes offline, the
3283 others can still keep the Builder working. In addition, multiple
3284 buildslaves will allow multiple simultaneous builds for the same
3285 Builder, which might be useful if you have a lot of forced or ``try''
3286 builds taking place.
3288 If you use this feature, it is important to make sure that the
3289 buildslaves are all, in fact, capable of running the given build. The
3290 slave hosts should be configured similarly, otherwise you will spend a
3291 lot of time trying (unsuccessfully) to reproduce a failure that only
3292 occurs on some of the buildslaves and not the others. Different
3293 platforms, operating systems, versions of major programs or libraries,
3294 all these things mean you should use separate Builders.
3296 @item builddir
3297 This specifies the name of a subdirectory (under the base directory)
3298 in which everything related to this builder will be placed. On the
3299 buildmaster, this holds build status information. On the buildslave,
3300 this is where checkouts, compiles, and tests are run.
3302 @item factory
3303 This is a @code{buildbot.process.factory.BuildFactory} instance which
3304 controls how the build is performed. Full details appear in their own
3305 chapter, @xref{Build Process}. Parameters like the location of the CVS
3306 repository and the compile-time options used for the build are
3307 generally provided as arguments to the factory's constructor.
3309 @end table
3311 Other optional keys may be set on each Builder:
3313 @table @code
3315 @item category
3316 If provided, this is a string that identifies a category for the
3317 builder to be a part of. Status clients can limit themselves to a
3318 subset of the available categories. A common use for this is to add
3319 new builders to your setup (for a new module, or for a new buildslave)
3320 that do not work correctly yet and allow you to integrate them with
3321 the active builders. You can put these new builders in a test
3322 category, make your main status clients ignore them, and have only
3323 private status clients pick them up. As soon as they work, you can
3324 move them over to the active category.
3326 @item nextSlave
3327 If provided, this is a function that controls which slave will be assigned
3328 future jobs. The function is passed two arguments, the @code{Builder}
3329 object which is assigning a new job, and a list of @code{BuildSlave}
3330 objects. The function should return one of the @code{BuildSlave}
3331 objects, or @code{None} if none of the available slaves should be
3332 used.
3334 @item nextBuild
3335 If provided, this is a function that controls which build request will be
3336 handled next. The function is passed two arguments, the @code{Builder}
3337 object which is assigning a new job, and a list of @code{BuildRequest}
3338 objects of pending builds. The function should return one of the
3339 @code{BuildRequest} objects, or @code{None} if none of the pending
3340 builds should be started.
3342 @end table
3345 @node Defining Status Targets
3346 @section Defining Status Targets
3348 The Buildmaster has a variety of ways to present build status to
3349 various users. Each such delivery method is a ``Status Target'' object
3350 in the configuration's @code{status} list. To add status targets, you
3351 just append more objects to this list:
3353 @bcindex c['status']
3355 @example
3356 c['status'] = []
3358 from buildbot.status import html
3359 c['status'].append(html.Waterfall(http_port=8010))
3361 from buildbot.status import mail
3362 m = mail.MailNotifier(fromaddr="buildbot@@localhost",
3363                       extraRecipients=["builds@@lists.example.com"],
3364                       sendToInterestedUsers=False)
3365 c['status'].append(m)
3367 from buildbot.status import words
3368 c['status'].append(words.IRC(host="irc.example.com", nick="bb",
3369                              channels=["#example"]))
3370 @end example
3372 Status delivery has its own chapter, @xref{Status Delivery}, in which
3373 all the built-in status targets are documented.
3375 @node Limiting Memory and Disk Usage::
3376 @section Limiting Memory and Disk Usage::
3378 Buildbot stores historical information on disk in the form of "Pickle" files
3379 and compressed logfiles.  In a large installation, these can quickly consume
3380 disk space, yet in many cases developers never consult this historical
3381 information.  Four configuration parameters control the "pruning" of various
3382 data, shown here with their default values:
3384 @bcindex c['buildHorizon']
3385 @bcindex c['eventHorizon']
3386 @bcindex c['logHorizon']
3387 @bcindex c['buildCacheSize']
3388 @example
3389 c['buildHorizon'] = 100
3390 c['eventHorizon'] = 50
3391 c['logHorizon'] = 40
3393 c['buildCacheSize'] = 15
3394 @end example
3396 The @code{buildHorizon} specifies the minimum number of builds for each builder
3397 which should be kept on disk.  The @code{eventHorizon} specifies the minumum
3398 number of events to keep -- events mostly describe connections and
3399 disconnections of slaves, and are seldom helpful to developers.  The
3400 @code{logHorizon} gives the minimum number of builds for which logs should be
3401 maintained; this parameter must be less than @code{buildHorizon}. Builds older
3402 than @code{logHorizon} but not older than @code{buildHorizon} will maintain
3403 their overall status and the status of each step, but the logfiles will be
3404 deleted.
3406 Finally, the @code{buildCacheSize} gives the number of builds for each builder
3407 which are cached in memory.  This number should be larger than the number of
3408 builds required for commonly-used status displays (the waterfall or grid
3409 views), so that those displays do not miss the cache on a refresh.
3411 @node Debug options
3412 @section Debug options
3415 @bcindex c['debugPassword']
3416 If you set @code{c['debugPassword']}, then you can connect to the
3417 buildmaster with the diagnostic tool launched by @code{buildbot
3418 debugclient MASTER:PORT}. From this tool, you can reload the config
3419 file, manually force builds, and inject changes, which may be useful
3420 for testing your buildmaster without actually commiting changes to
3421 your repository (or before you have the Change Sources set up). The
3422 debug tool uses the same port number as the slaves do:
3423 @code{c['slavePortnum']}, and is authenticated with this password.
3425 @example
3426 c['debugPassword'] = "debugpassword"
3427 @end example
3429 @bcindex c['manhole']
3430 If you set @code{c['manhole']} to an instance of one of the classes in
3431 @code{buildbot.manhole}, you can telnet or ssh into the buildmaster
3432 and get an interactive Python shell, which may be useful for debugging
3433 buildbot internals. It is probably only useful for buildbot
3434 developers. It exposes full access to the buildmaster's account
3435 (including the ability to modify and delete files), so it should not
3436 be enabled with a weak or easily guessable password.
3438 There are three separate @code{Manhole} classes. Two of them use SSH,
3439 one uses unencrypted telnet. Two of them use a username+password
3440 combination to grant access, one of them uses an SSH-style
3441 @file{authorized_keys} file which contains a list of ssh public keys.
3443 @table @code
3444 @item manhole.AuthorizedKeysManhole
3445 You construct this with the name of a file that contains one SSH
3446 public key per line, just like @file{~/.ssh/authorized_keys}. If you
3447 provide a non-absolute filename, it will be interpreted relative to
3448 the buildmaster's base directory.
3450 @item manhole.PasswordManhole
3451 This one accepts SSH connections but asks for a username and password
3452 when authenticating. It accepts only one such pair.
3455 @item manhole.TelnetManhole
3456 This accepts regular unencrypted telnet connections, and asks for a
3457 username/password pair before providing access. Because this
3458 username/password is transmitted in the clear, and because Manhole
3459 access to the buildmaster is equivalent to granting full shell
3460 privileges to both the buildmaster and all the buildslaves (and to all
3461 accounts which then run code produced by the buildslaves), it is
3462 highly recommended that you use one of the SSH manholes instead.
3464 @end table
3466 @example
3467 # some examples:
3468 from buildbot import manhole
3469 c['manhole'] = manhole.AuthorizedKeysManhole(1234, "authorized_keys")
3470 c['manhole'] = manhole.PasswordManhole(1234, "alice", "mysecretpassword")
3471 c['manhole'] = manhole.TelnetManhole(1234, "bob", "snoop_my_password_please")
3472 @end example
3474 The @code{Manhole} instance can be configured to listen on a specific
3475 port. You may wish to have this listening port bind to the loopback
3476 interface (sometimes known as ``lo0'', ``localhost'', or 127.0.0.1) to
3477 restrict access to clients which are running on the same host.
3479 @example
3480 from buildbot.manhole import PasswordManhole
3481 c['manhole'] = PasswordManhole("tcp:9999:interface=127.0.0.1","admin","passwd")
3482 @end example
3484 To have the @code{Manhole} listen on all interfaces, use
3485 @code{"tcp:9999"} or simply 9999. This port specification uses
3486 @code{twisted.application.strports}, so you can make it listen on SSL
3487 or even UNIX-domain sockets if you want.
3489 Note that using any Manhole requires that the TwistedConch package be
3490 installed, and that you be using Twisted version 2.0 or later.
3492 The buildmaster's SSH server will use a different host key than the
3493 normal sshd running on a typical unix host. This will cause the ssh
3494 client to complain about a ``host key mismatch'', because it does not
3495 realize there are two separate servers running on the same host. To
3496 avoid this, use a clause like the following in your @file{.ssh/config}
3497 file:
3499 @example
3500 Host remotehost-buildbot
3501  HostName remotehost
3502  HostKeyAlias remotehost-buildbot
3503  Port 9999
3504  # use 'user' if you use PasswordManhole and your name is not 'admin'.
3505  # if you use AuthorizedKeysManhole, this probably doesn't matter.
3506  User admin
3507 @end example
3510 @node Getting Source Code Changes, Build Process, Configuration, Top
3511 @chapter Getting Source Code Changes
3513 The most common way to use the Buildbot is centered around the idea of
3514 @code{Source Trees}: a directory tree filled with source code of some form
3515 which can be compiled and/or tested. Some projects use languages that don't
3516 involve any compilation step: nevertheless there may be a @code{build} phase
3517 where files are copied or rearranged into a form that is suitable for
3518 installation. Some projects do not have unit tests, and the Buildbot is
3519 merely helping to make sure that the sources can compile correctly. But in
3520 all of these cases, the thing-being-tested is a single source tree.
3522 A Version Control System mantains a source tree, and tells the
3523 buildmaster when it changes. The first step of each Build is typically
3524 to acquire a copy of some version of this tree.
3526 This chapter describes how the Buildbot learns about what Changes have
3527 occurred. For more information on VC systems and Changes, see
3528 @ref{Version Control Systems}.
3531 @menu
3532 * Change Sources::
3533 * Choosing ChangeSources::
3534 * CVSToys - PBService::
3535 * Mail-parsing ChangeSources::
3536 * PBChangeSource::
3537 * P4Source::
3538 * BonsaiPoller::
3539 * SVNPoller::
3540 * MercurialHook::
3541 * Bzr Hook::
3542 * Bzr Poller::
3543 @end menu
3547 @node Change Sources, Choosing ChangeSources, Getting Source Code Changes, Getting Source Code Changes
3548 @section Change Sources
3550 @c TODO: rework this, the one-buildmaster-one-tree thing isn't quite
3551 @c so narrow-minded anymore
3553 Each Buildmaster watches a single source tree. Changes can be provided
3554 by a variety of ChangeSource types, however any given project will
3555 typically have only a single ChangeSource active. This section
3556 provides a description of all available ChangeSource types and
3557 explains how to set up each of them.
3559 There are a variety of ChangeSources available, some of which are
3560 meant to be used in conjunction with other tools to deliver Change
3561 events from the VC repository to the buildmaster.
3563 @itemize @bullet
3565 @item CVSToys
3566 This ChangeSource opens a TCP connection from the buildmaster to a
3567 waiting FreshCVS daemon that lives on the repository machine, and
3568 subscribes to hear about Changes.
3570 @item MaildirSource
3571 This one watches a local maildir-format inbox for email sent out by
3572 the repository when a change is made. When a message arrives, it is
3573 parsed to create the Change object. A variety of parsing functions are
3574 available to accomodate different email-sending tools.
3576 @item PBChangeSource
3577 This ChangeSource listens on a local TCP socket for inbound
3578 connections from a separate tool. Usually, this tool would be run on
3579 the VC repository machine in a commit hook. It is expected to connect
3580 to the TCP socket and send a Change message over the network
3581 connection. The @command{buildbot sendchange} command is one example
3582 of a tool that knows how to send these messages, so you can write a
3583 commit script for your VC system that calls it to deliver the Change.
3584 There are other tools in the contrib/ directory that use the same
3585 protocol.
3587 @end itemize
3589 As a quick guide, here is a list of VC systems and the ChangeSources
3590 that might be useful with them. All of these ChangeSources are in the
3591 @code{buildbot.changes} module.
3593 @table @code
3594 @item CVS
3596 @itemize @bullet
3597 @item freshcvs.FreshCVSSource (connected via TCP to the freshcvs daemon)
3598 @item mail.FCMaildirSource (watching for email sent by a freshcvs daemon)
3599 @item mail.BonsaiMaildirSource (watching for email sent by Bonsai)
3600 @item mail.SyncmailMaildirSource (watching for email sent by syncmail)
3601 @item pb.PBChangeSource (listening for connections from @code{buildbot
3602 sendchange} run in a loginfo script)
3603 @item pb.PBChangeSource (listening for connections from a long-running
3604 @code{contrib/viewcvspoll.py} polling process which examines the ViewCVS
3605 database directly
3606 @end itemize
3608 @item SVN
3609 @itemize @bullet
3610 @item pb.PBChangeSource (listening for connections from
3611 @code{contrib/svn_buildbot.py} run in a postcommit script)
3612 @item pb.PBChangeSource (listening for connections from a long-running
3613 @code{contrib/svn_watcher.py} or @code{contrib/svnpoller.py} polling
3614 process
3615 @item mail.SVNCommitEmailMaildirSource (watching for email sent by commit-email.pl)
3616 @item svnpoller.SVNPoller (polling the SVN repository)
3617 @end itemize
3619 @item Darcs
3620 @itemize @bullet
3621 @item pb.PBChangeSource (listening for connections from
3622 @code{contrib/darcs_buildbot.py} in a commit script
3623 @end itemize
3625 @item Mercurial
3626 @itemize @bullet
3627 @item pb.PBChangeSource (listening for connections from
3628 @code{contrib/hg_buildbot.py} run in an 'incoming' hook)
3629 @item pb.PBChangeSource (listening for connections from
3630 @code{buildbot/changes/hgbuildbot.py} run as an in-process 'changegroup'
3631 hook)
3632 @end itemize
3634 @item Arch/Bazaar
3635 @itemize @bullet
3636 @item pb.PBChangeSource (listening for connections from
3637 @code{contrib/arch_buildbot.py} run in a commit hook)
3638 @end itemize
3640 @item Bzr (the newer Bazaar)
3641 @itemize @bullet
3642 @item pb.PBChangeSource (listening for connections from
3643 @code{contrib/bzr_buildbot.py} run in a post-change-branch-tip or commit hook)
3644 @item @code{contrib/bzr_buildbot.py}'s BzrPoller (polling the Bzr repository)
3645 @end itemize
3647 @item Git
3648 @itemize @bullet
3649 @item pb.PBChangeSource (listening for connections from
3650 @code{contrib/git_buildbot.py} run in the post-receive hook)
3651 @end itemize
3653 @end table
3655 All VC systems can be driven by a PBChangeSource and the
3656 @code{buildbot sendchange} tool run from some form of commit script.
3657 If you write an email parsing function, they can also all be driven by
3658 a suitable @code{MaildirSource}.
3661 @node Choosing ChangeSources, CVSToys - PBService, Change Sources, Getting Source Code Changes
3662 @section Choosing ChangeSources
3664 The @code{master.cfg} configuration file has a dictionary key named
3665 @code{BuildmasterConfig['change_source']}, which holds the active
3666 @code{IChangeSource} object. The config file will typically create an
3667 object from one of the classes described below and stuff it into this
3668 key.
3670 Each buildmaster typically has just a single ChangeSource, since it is
3671 only watching a single source tree. But if, for some reason, you need
3672 multiple sources, just set @code{c['change_source']} to a list of
3673 ChangeSources.. it will accept that too.
3675 @example
3676 s = FreshCVSSourceNewcred(host="host", port=4519,
3677                           user="alice", passwd="secret",
3678                           prefix="Twisted")
3679 BuildmasterConfig['change_source'] = [s]
3680 @end example
3682 Each source tree has a nominal @code{top}. Each Change has a list of
3683 filenames, which are all relative to this top location. The
3684 ChangeSource is responsible for doing whatever is necessary to
3685 accomplish this. Most sources have a @code{prefix} argument: a partial
3686 pathname which is stripped from the front of all filenames provided to
3687 that @code{ChangeSource}. Files which are outside this sub-tree are
3688 ignored by the changesource: it does not generate Changes for those
3689 files.
3692 @node CVSToys - PBService, Mail-parsing ChangeSources, Choosing ChangeSources, Getting Source Code Changes
3693 @section CVSToys - PBService
3695 @csindex buildbot.changes.freshcvs.FreshCVSSource
3697 The @uref{http://purl.net/net/CVSToys, CVSToys} package provides a
3698 server which runs on the machine that hosts the CVS repository it
3699 watches. It has a variety of ways to distribute commit notifications,
3700 and offers a flexible regexp-based way to filter out uninteresting
3701 changes. One of the notification options is named @code{PBService} and
3702 works by listening on a TCP port for clients. These clients subscribe
3703 to hear about commit notifications.
3705 The buildmaster has a CVSToys-compatible @code{PBService} client built
3706 in. There are two versions of it, one for old versions of CVSToys
3707 (1.0.9 and earlier) which used the @code{oldcred} authentication
3708 framework, and one for newer versions (1.0.10 and later) which use
3709 @code{newcred}. Both are classes in the
3710 @code{buildbot.changes.freshcvs} package.
3712 @code{FreshCVSSourceNewcred} objects are created with the following
3713 parameters:
3715 @table @samp
3717 @item @code{host} and @code{port}
3718 these specify where the CVSToys server can be reached
3720 @item @code{user} and @code{passwd}
3721 these specify the login information for the CVSToys server
3722 (@code{freshcvs}). These must match the server's values, which are
3723 defined in the @code{freshCfg} configuration file (which lives in the
3724 CVSROOT directory of the repository).
3726 @item @code{prefix}
3727 this is the prefix to be found and stripped from filenames delivered
3728 by the CVSToys server. Most projects live in sub-directories of the
3729 main repository, as siblings of the CVSROOT sub-directory, so
3730 typically this prefix is set to that top sub-directory name.
3732 @end table
3734 @heading Example
3736 To set up the freshCVS server, add a statement like the following to
3737 your @file{freshCfg} file:
3739 @example
3740 pb = ConfigurationSet([
3741     (None, None, None, PBService(userpass=('foo', 'bar'), port=4519)),
3742     ])
3743 @end example
3745 This will announce all changes to a client which connects to port 4519
3746 using a username of 'foo' and a password of 'bar'.
3748 Then add a clause like this to your buildmaster's @file{master.cfg}:
3750 @example
3751 BuildmasterConfig['change_source'] = FreshCVSSource("cvs.example.com", 4519,
3752                                                     "foo", "bar",
3753                                                     prefix="glib/")
3754 @end example
3756 where "cvs.example.com" is the host that is running the FreshCVS daemon, and
3757 "glib" is the top-level directory (relative to the repository's root) where
3758 all your source code lives. Most projects keep one or more projects in the
3759 same repository (along with CVSROOT/ to hold admin files like loginfo and
3760 freshCfg); the prefix= argument tells the buildmaster to ignore everything
3761 outside that directory, and to strip that common prefix from all pathnames
3762 it handles.
3765 @node Mail-parsing ChangeSources, PBChangeSource, CVSToys - PBService, Getting Source Code Changes
3766 @section Mail-parsing ChangeSources
3768 Many projects publish information about changes to their source tree
3769 by sending an email message out to a mailing list, frequently named
3770 PROJECT-commits or PROJECT-changes. Each message usually contains a
3771 description of the change (who made the change, which files were
3772 affected) and sometimes a copy of the diff. Humans can subscribe to
3773 this list to stay informed about what's happening to the source tree.
3775 The Buildbot can also be subscribed to a -commits mailing list, and
3776 can trigger builds in response to Changes that it hears about. The
3777 buildmaster admin needs to arrange for these email messages to arrive
3778 in a place where the buildmaster can find them, and configure the
3779 buildmaster to parse the messages correctly. Once that is in place,
3780 the email parser will create Change objects and deliver them to the
3781 Schedulers (see @pxref{Change Sources and Schedulers}) just
3782 like any other ChangeSource.
3784 There are two components to setting up an email-based ChangeSource.
3785 The first is to route the email messages to the buildmaster, which is
3786 done by dropping them into a ``maildir''. The second is to actually
3787 parse the messages, which is highly dependent upon the tool that was
3788 used to create them. Each VC system has a collection of favorite
3789 change-emailing tools, and each has a slightly different format, so
3790 each has a different parsing function. There is a separate
3791 ChangeSource variant for each parsing function.
3793 Once you've chosen a maildir location and a parsing function, create
3794 the change source and put it in @code{c['change_source']}:
3796 @example
3797 from buildbot.changes.mail import SyncmailMaildirSource
3798 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot",
3799                                            prefix="/trunk/")
3800 @end example
3802 @menu
3803 * Subscribing the Buildmaster::
3804 * Using Maildirs::
3805 * Parsing Email Change Messages::
3806 @end menu
3808 @node Subscribing the Buildmaster, Using Maildirs, Mail-parsing ChangeSources, Mail-parsing ChangeSources
3809 @subsection Subscribing the Buildmaster
3811 The recommended way to install the buildbot is to create a dedicated
3812 account for the buildmaster. If you do this, the account will probably
3813 have a distinct email address (perhaps
3814 @email{buildmaster@@example.org}). Then just arrange for this
3815 account's email to be delivered to a suitable maildir (described in
3816 the next section).
3818 If the buildbot does not have its own account, ``extension addresses''
3819 can be used to distinguish between email intended for the buildmaster
3820 and email intended for the rest of the account. In most modern MTAs,
3821 the e.g. @code{foo@@example.org} account has control over every email
3822 address at example.org which begins with "foo", such that email
3823 addressed to @email{account-foo@@example.org} can be delivered to a
3824 different destination than @email{account-bar@@example.org}. qmail
3825 does this by using separate .qmail files for the two destinations
3826 (@file{.qmail-foo} and @file{.qmail-bar}, with @file{.qmail}
3827 controlling the base address and @file{.qmail-default} controlling all
3828 other extensions). Other MTAs have similar mechanisms.
3830 Thus you can assign an extension address like
3831 @email{foo-buildmaster@@example.org} to the buildmaster, and retain
3832 @email{foo@@example.org} for your own use.
3835 @node Using Maildirs, Parsing Email Change Messages, Subscribing the Buildmaster, Mail-parsing ChangeSources
3836 @subsection Using Maildirs
3838 A ``maildir'' is a simple directory structure originally developed for
3839 qmail that allows safe atomic update without locking. Create a base
3840 directory with three subdirectories: ``new'', ``tmp'', and ``cur''.
3841 When messages arrive, they are put into a uniquely-named file (using
3842 pids, timestamps, and random numbers) in ``tmp''. When the file is
3843 complete, it is atomically renamed into ``new''. Eventually the
3844 buildmaster notices the file in ``new'', reads and parses the
3845 contents, then moves it into ``cur''. A cronjob can be used to delete
3846 files in ``cur'' at leisure.
3848 Maildirs are frequently created with the @command{maildirmake} tool,
3849 but a simple @command{mkdir -p ~/MAILDIR/@{cur,new,tmp@}} is pretty much
3850 equivalent.
3852 Many modern MTAs can deliver directly to maildirs. The usual .forward
3853 or .procmailrc syntax is to name the base directory with a trailing
3854 slash, so something like @code{~/MAILDIR/} . qmail and postfix are
3855 maildir-capable MTAs, and procmail is a maildir-capable MDA (Mail
3856 Delivery Agent).
3858 For MTAs which cannot put files into maildirs directly, the
3859 ``safecat'' tool can be executed from a .forward file to accomplish
3860 the same thing.
3862 The Buildmaster uses the linux DNotify facility to receive immediate
3863 notification when the maildir's ``new'' directory has changed. When
3864 this facility is not available, it polls the directory for new
3865 messages, every 10 seconds by default.
3867 @node Parsing Email Change Messages,  , Using Maildirs, Mail-parsing ChangeSources
3868 @subsection Parsing Email Change Messages
3870 The second component to setting up an email-based ChangeSource is to
3871 parse the actual notices. This is highly dependent upon the VC system
3872 and commit script in use.
3874 A couple of common tools used to create these change emails are:
3876 @table @samp
3878 @item CVS
3879 @table @samp
3880 @item CVSToys MailNotifier
3881 @ref{FCMaildirSource}
3882 @item Bonsai notification
3883 @ref{BonsaiMaildirSource}
3884 @item syncmail
3885 @ref{SyncmailMaildirSource}
3886 @end table
3888 @item SVN
3889 @table @samp
3890 @item svnmailer
3891 http://opensource.perlig.de/en/svnmailer/
3892 @item commit-email.pl
3893 @ref{SVNCommitEmailMaildirSource}
3894 @end table
3896 @item Bzr
3897 @table @samp
3898 @item Launchpad
3899 @ref{BzrLaunchpadEmailMaildirSource}
3900 @end table
3902 @item Mercurial
3903 @table @samp
3904 @item NotifyExtension
3905 http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
3906 @end table
3908 @item Git
3909 @table @samp
3910 @item post-receive-email
3911 http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email;hb=HEAD
3912 @end table
3914 @end table
3917 The following sections describe the parsers available for each of
3918 these tools.
3920 Most of these parsers accept a @code{prefix=} argument, which is used
3921 to limit the set of files that the buildmaster pays attention to. This
3922 is most useful for systems like CVS and SVN which put multiple
3923 projects in a single repository (or use repository names to indicate
3924 branches). Each filename that appears in the email is tested against
3925 the prefix: if the filename does not start with the prefix, the file
3926 is ignored. If the filename @emph{does} start with the prefix, that
3927 prefix is stripped from the filename before any further processing is
3928 done. Thus the prefix usually ends with a slash.
3930 @menu
3931 * FCMaildirSource::
3932 * SyncmailMaildirSource::
3933 * BonsaiMaildirSource::
3934 * SVNCommitEmailMaildirSource::
3935 * BzrLaunchpadEmailMaildirSource::
3936 @end menu
3938 @node FCMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages, Parsing Email Change Messages
3939 @subsubsection FCMaildirSource
3942 @csindex buildbot.changes.mail.FCMaildirSource
3944 http://twistedmatrix.com/users/acapnotic/wares/code/CVSToys/
3946 This parser works with the CVSToys @code{MailNotification} action,
3947 which will send email to a list of recipients for each commit. This
3948 tends to work better than using @code{/bin/mail} from within the
3949 CVSROOT/loginfo file directly, as CVSToys will batch together all
3950 files changed during the same CVS invocation, and can provide more
3951 information (like creating a ViewCVS URL for each file changed).
3953 The Buildbot's @code{FCMaildirSource} knows for to parse these CVSToys
3954 messages and turn them into Change objects. It can be given two
3955 parameters: the directory name of the maildir root, and the prefix to
3956 strip.
3958 @example
3959 from buildbot.changes.mail import FCMaildirSource
3960 c['change_source'] = FCMaildirSource("~/maildir-buildbot")
3961 @end example
3963 @node SyncmailMaildirSource, BonsaiMaildirSource, FCMaildirSource, Parsing Email Change Messages
3964 @subsubsection SyncmailMaildirSource
3966 @csindex buildbot.changes.mail.SyncmailMaildirSource
3968 http://sourceforge.net/projects/cvs-syncmail
3970 @code{SyncmailMaildirSource} knows how to parse the message format used by
3971 the CVS ``syncmail'' script.
3973 @example
3974 from buildbot.changes.mail import SyncmailMaildirSource
3975 c['change_source'] = SyncmailMaildirSource("~/maildir-buildbot")
3976 @end example
3978 @node BonsaiMaildirSource, SVNCommitEmailMaildirSource, SyncmailMaildirSource, Parsing Email Change Messages
3979 @subsubsection BonsaiMaildirSource
3981 @csindex buildbot.changes.mail.BonsaiMaildirSource
3983 http://www.mozilla.org/bonsai.html
3985 @code{BonsaiMaildirSource} parses messages sent out by Bonsai, the CVS
3986 tree-management system built by Mozilla.
3988 @example
3989 from buildbot.changes.mail import BonsaiMaildirSource
3990 c['change_source'] = BonsaiMaildirSource("~/maildir-buildbot")
3991 @end example
3993 @node SVNCommitEmailMaildirSource, BzrLaunchpadEmailMaildirSource, BonsaiMaildirSource, Parsing Email Change Messages
3994 @subsubsection SVNCommitEmailMaildirSource
3996 @csindex buildbot.changes.mail.SVNCommitEmailMaildirSource
3998 @code{SVNCommitEmailMaildirSource} parses message sent out by the
3999 @code{commit-email.pl} script, which is included in the Subversion
4000 distribution.
4002 It does not currently handle branches: all of the Change objects that
4003 it creates will be associated with the default (i.e. trunk) branch.
4005 @example
4006 from buildbot.changes.mail import SVNCommitEmailMaildirSource
4007 c['change_source'] = SVNCommitEmailMaildirSource("~/maildir-buildbot")
4008 @end example
4010 @node BzrLaunchpadEmailMaildirSource, , SVNCommitEmailMaildirSource, Parsing Email Change Messages
4011 @subsubsection BzrLaunchpadEmailMaildirSource
4013 @csindex buildbot.changes.mail.BzrLaunchpadEmailMaildirSource
4015 @code{BzrLaunchpadEmailMaildirSource} parses the mails that are sent to
4016 addresses that subscribe to branch revision notifications for a bzr branch
4017 hosted on Launchpad.
4019 The branch name defaults to @code{lp:<Launchpad path>}. For example
4020 @code{lp:~maria-captains/maria/5.1}.
4022 If only a single branch is used, the default branch name can be changed by
4023 setting @code{defaultBranch}.
4025 For multiple branches, pass a dictionary as the value of the @code{branchMap}
4026 option to map specific repository paths to specific branch names (see example
4027 below). The leading @code{lp:} prefix of the path is optional.
4029 The @code{prefix} option is not supported (it is silently ignored). Use the
4030 @code{branchMap} and @code{defaultBranch} instead to assign changes to
4031 branches (and just do not subscribe the buildbot to branches that are not of
4032 interest).
4034 The revision number is obtained from the email text. The bzr revision id is
4035 not available in the mails sent by Launchpad. However, it is possible to set
4036 the bzr @code{append_revisions_only} option for public shared repositories to
4037 avoid new pushes of merges changing the meaning of old revision numbers.
4039 @verbatim
4040 from buildbot.changes.mail import BzrLaunchpadEmailMaildirSource
4041 bm = { 'lp:~maria-captains/maria/5.1' : '5.1', 'lp:~maria-captains/maria/6.0' : '6.0' }
4042 c['change_source'] = BzrLaunchpadEmailMaildirSource("~/maildir-buildbot", branchMap = bm)
4043 @end verbatim
4046 @node PBChangeSource, P4Source, Mail-parsing ChangeSources, Getting Source Code Changes
4047 @section PBChangeSource
4049 @csindex buildbot.changes.pb.PBChangeSource
4051 The last kind of ChangeSource actually listens on a TCP port for
4052 clients to connect and push change notices @emph{into} the
4053 Buildmaster. This is used by the built-in @code{buildbot sendchange}
4054 notification tool, as well as the VC-specific
4055 @file{contrib/svn_buildbot.py}, @file{contrib/arch_buildbot.py},
4056 @file{contrib/hg_buildbot.py} tools, and the
4057 @code{buildbot.changes.hgbuildbot} hook. These tools are run by the
4058 repository (in a commit hook script), and connect to the buildmaster
4059 directly each time a file is comitted. This is also useful for
4060 creating new kinds of change sources that work on a @code{push} model
4061 instead of some kind of subscription scheme, for example a script
4062 which is run out of an email .forward file.
4064 This ChangeSource can be configured to listen on its own TCP port, or
4065 it can share the port that the buildmaster is already using for the
4066 buildslaves to connect. (This is possible because the
4067 @code{PBChangeSource} uses the same protocol as the buildslaves, and
4068 they can be distinguished by the @code{username} attribute used when
4069 the initial connection is established). It might be useful to have it
4070 listen on a different port if, for example, you wanted to establish
4071 different firewall rules for that port. You could allow only the SVN
4072 repository machine access to the @code{PBChangeSource} port, while
4073 allowing only the buildslave machines access to the slave port. Or you
4074 could just expose one port and run everything over it. @emph{Note:
4075 this feature is not yet implemented, the PBChangeSource will always
4076 share the slave port and will always have a @code{user} name of
4077 @code{change}, and a passwd of @code{changepw}. These limitations will
4078 be removed in the future.}.
4081 The @code{PBChangeSource} is created with the following arguments. All
4082 are optional.
4084 @table @samp
4085 @item @code{port}
4086 which port to listen on. If @code{None} (which is the default), it
4087 shares the port used for buildslave connections. @emph{Not
4088 Implemented, always set to @code{None}}.
4090 @item @code{user} and @code{passwd}
4091 The user/passwd account information that the client program must use
4092 to connect. Defaults to @code{change} and @code{changepw}. @emph{Not
4093 Implemented, @code{user} is currently always set to @code{change},
4094 @code{passwd} is always set to @code{changepw}}.
4096 @item @code{prefix}
4097 The prefix to be found and stripped from filenames delivered over the
4098 connection. Any filenames which do not start with this prefix will be
4099 removed. If all the filenames in a given Change are removed, the that
4100 whole Change will be dropped. This string should probably end with a
4101 directory separator.
4103 This is useful for changes coming from version control systems that
4104 represent branches as parent directories within the repository (like
4105 SVN and Perforce). Use a prefix of 'trunk/' or
4106 'project/branches/foobranch/' to only follow one branch and to get
4107 correct tree-relative filenames. Without a prefix, the PBChangeSource
4108 will probably deliver Changes with filenames like @file{trunk/foo.c}
4109 instead of just @file{foo.c}. Of course this also depends upon the
4110 tool sending the Changes in (like @command{buildbot sendchange}) and
4111 what filenames it is delivering: that tool may be filtering and
4112 stripping prefixes at the sending end.
4114 @end table
4116 @node P4Source, BonsaiPoller, PBChangeSource, Getting Source Code Changes
4117 @section P4Source
4119 @csindex buildbot.changes.p4poller.P4Source
4121 The @code{P4Source} periodically polls a @uref{http://www.perforce.com/,
4122 Perforce} depot for changes. It accepts the following arguments:
4124 @table @samp
4125 @item @code{p4base}
4126 The base depot path to watch, without the trailing '/...'.
4128 @item @code{p4port}
4129 The Perforce server to connect to (as host:port).
4131 @item @code{p4user}
4132 The Perforce user.
4134 @item @code{p4passwd}
4135 The Perforce password.
4137 @item @code{p4bin}
4138 An optional string parameter. Specify the location of the perforce command
4139 line binary (p4).  You only need to do this if the perforce binary is not
4140 in the path of the buildbot user.  Defaults to ``p4''.
4142 @item @code{split_file}
4143 A function that maps a pathname, without the leading @code{p4base}, to a
4144 (branch, filename) tuple. The default just returns (None, branchfile),
4145 which effectively disables branch support. You should supply a function
4146 which understands your repository structure.
4148 @item @code{pollinterval}
4149 How often to poll, in seconds. Defaults to 600 (10 minutes).
4151 @item @code{histmax}
4152 The maximum number of changes to inspect at a time. If more than this
4153 number occur since the last poll, older changes will be silently
4154 ignored.
4155 @end table
4157 @heading Example
4159 This configuration uses the @code{P4PORT}, @code{P4USER}, and @code{P4PASSWD}
4160 specified in the buildmaster's environment. It watches a project in which the
4161 branch name is simply the next path component, and the file is all path
4162 components after.
4164 @example
4165 from buildbot.changes import p4poller
4166 s = p4poller.P4Source(p4base='//depot/project/',
4167                       split_file=lambda branchfile: branchfile.split('/',1),
4168                      )
4169 c['change_source'] = s
4170 @end example
4172 @node BonsaiPoller, SVNPoller, P4Source, Getting Source Code Changes
4173 @section BonsaiPoller
4175 @csindex buildbot.changes.bonsaipoller.BonsaiPoller
4177 The @code{BonsaiPoller} periodically polls a Bonsai server. This is a
4178 CGI script accessed through a web server that provides information
4179 about a CVS tree, for example the Mozilla bonsai server at
4180 @uref{http://bonsai.mozilla.org}. Bonsai servers are usable by both
4181 humans and machines. In this case, the buildbot's change source forms
4182 a query which asks about any files in the specified branch which have
4183 changed since the last query.
4185 Please take a look at the BonsaiPoller docstring for details about the
4186 arguments it accepts.
4189 @node SVNPoller, MercurialHook, BonsaiPoller, Getting Source Code Changes
4190 @section SVNPoller
4192 @csindex buildbot.changes.svnpoller.SVNPoller
4194 The @code{buildbot.changes.svnpoller.SVNPoller} is a ChangeSource
4195 which periodically polls a @uref{http://subversion.tigris.org/,
4196 Subversion} repository for new revisions, by running the @code{svn
4197 log} command in a subshell. It can watch a single branch or multiple
4198 branches.
4200 @code{SVNPoller} accepts the following arguments:
4202 @table @code
4203 @item svnurl
4204 The base URL path to watch, like
4205 @code{svn://svn.twistedmatrix.com/svn/Twisted/trunk}, or
4206 @code{http://divmod.org/svn/Divmod/}, or even
4207 @code{file:///home/svn/Repository/ProjectA/branches/1.5/}. This must
4208 include the access scheme, the location of the repository (both the
4209 hostname for remote ones, and any additional directory names necessary
4210 to get to the repository), and the sub-path within the repository's
4211 virtual filesystem for the project and branch of interest.
4213 The @code{SVNPoller} will only pay attention to files inside the
4214 subdirectory specified by the complete svnurl.
4216 @item split_file
4217 A function to convert pathnames into (branch, relative_pathname)
4218 tuples. Use this to explain your repository's branch-naming policy to
4219 @code{SVNPoller}. This function must accept a single string and return
4220 a two-entry tuple. There are a few utility functions in
4221 @code{buildbot.changes.svnpoller} that can be used as a
4222 @code{split_file} function, see below for details.
4224 The default value always returns (None, path), which indicates that
4225 all files are on the trunk.
4227 Subclasses of @code{SVNPoller} can override the @code{split_file}
4228 method instead of using the @code{split_file=} argument.
4230 @item svnuser
4231 An optional string parameter. If set, the @code{--user} argument will
4232 be added to all @code{svn} commands. Use this if you have to
4233 authenticate to the svn server before you can do @code{svn info} or
4234 @code{svn log} commands.
4236 @item svnpasswd
4237 Like @code{svnuser}, this will cause a @code{--password} argument to
4238 be passed to all svn commands.
4240 @item pollinterval
4241 How often to poll, in seconds. Defaults to 600 (checking once every 10
4242 minutes). Lower this if you want the buildbot to notice changes
4243 faster, raise it if you want to reduce the network and CPU load on
4244 your svn server. Please be considerate of public SVN repositories by
4245 using a large interval when polling them.
4247 @item histmax
4248 The maximum number of changes to inspect at a time. Every POLLINTERVAL
4249 seconds, the @code{SVNPoller} asks for the last HISTMAX changes and
4250 looks through them for any ones it does not already know about. If
4251 more than HISTMAX revisions have been committed since the last poll,
4252 older changes will be silently ignored. Larger values of histmax will
4253 cause more time and memory to be consumed on each poll attempt.
4254 @code{histmax} defaults to 100.
4256 @item svnbin
4257 This controls the @code{svn} executable to use. If subversion is
4258 installed in a weird place on your system (outside of the
4259 buildmaster's @code{$PATH}), use this to tell @code{SVNPoller} where
4260 to find it. The default value of ``svn'' will almost always be
4261 sufficient.
4263 @item revlinktmpl
4264 This parameter allows a link to be provided for each revision (for example,
4265 to websvn or viewvc).  These links appear anywhere changes are shown, such
4266 as on build or change pages.  The proper form for this parameter is an URL
4267 with the portion that will substitute for a revision number replaced by
4268 ''%s''.  For example, @code{'http://myserver/websvn/revision.php?rev=%s'}
4269 could be used to cause revision links to be created to a websvn repository
4270 viewer.
4272 @end table
4274 @heading Branches
4276 Each source file that is tracked by a Subversion repository has a
4277 fully-qualified SVN URL in the following form:
4278 (REPOURL)(PROJECT-plus-BRANCH)(FILEPATH). When you create the
4279 @code{SVNPoller}, you give it a @code{svnurl} value that includes all
4280 of the REPOURL and possibly some portion of the PROJECT-plus-BRANCH
4281 string. The @code{SVNPoller} is responsible for producing Changes that
4282 contain a branch name and a FILEPATH (which is relative to the top of
4283 a checked-out tree). The details of how these strings are split up
4284 depend upon how your repository names its branches.
4286 @subheading PROJECT/BRANCHNAME/FILEPATH repositories
4288 One common layout is to have all the various projects that share a
4289 repository get a single top-level directory each. Then under a given
4290 project's directory, you get two subdirectories, one named ``trunk''
4291 and another named ``branches''. Under ``branches'' you have a bunch of
4292 other directories, one per branch, with names like ``1.5.x'' and
4293 ``testing''. It is also common to see directories like ``tags'' and
4294 ``releases'' next to ``branches'' and ``trunk''.
4296 For example, the Twisted project has a subversion server on
4297 ``svn.twistedmatrix.com'' that hosts several sub-projects. The
4298 repository is available through a SCHEME of ``svn:''. The primary
4299 sub-project is Twisted, of course, with a repository root of
4300 ``svn://svn.twistedmatrix.com/svn/Twisted''. Another sub-project is
4301 Informant, with a root of
4302 ``svn://svn.twistedmatrix.com/svn/Informant'', etc. Inside any
4303 checked-out Twisted tree, there is a file named bin/trial (which is
4304 used to run unit test suites).
4306 The trunk for Twisted is in
4307 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk'', and the
4308 fully-qualified SVN URL for the trunk version of @code{trial} would be
4309 ``svn://svn.twistedmatrix.com/svn/Twisted/trunk/bin/trial''. The same
4310 SVNURL for that file on a branch named ``1.5.x'' would be
4311 ``svn://svn.twistedmatrix.com/svn/Twisted/branches/1.5.x/bin/trial''.
4313 To set up a @code{SVNPoller} that watches the Twisted trunk (and
4314 nothing else), we would use the following:
4316 @example
4317 from buildbot.changes.svnpoller import SVNPoller
4318 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted/trunk")
4319 @end example
4321 In this case, every Change that our @code{SVNPoller} produces will
4322 have @code{.branch=None}, to indicate that the Change is on the trunk.
4323 No other sub-projects or branches will be tracked.
4325 If we want our ChangeSource to follow multiple branches, we have to do
4326 two things. First we have to change our @code{svnurl=} argument to
4327 watch more than just ``.../Twisted/trunk''. We will set it to
4328 ``.../Twisted'' so that we'll see both the trunk and all the branches.
4329 Second, we have to tell @code{SVNPoller} how to split the
4330 (PROJECT-plus-BRANCH)(FILEPATH) strings it gets from the repository
4331 out into (BRANCH) and (FILEPATH) pairs.
4333 We do the latter by providing a ``split_file'' function. This function
4334 is responsible for splitting something like
4335 ``branches/1.5.x/bin/trial'' into @code{branch}=''branches/1.5.x'' and
4336 @code{filepath}=''bin/trial''. This function is always given a string
4337 that names a file relative to the subdirectory pointed to by the
4338 @code{SVNPoller}'s @code{svnurl=} argument. It is expected to return a
4339 (BRANCHNAME, FILEPATH) tuple (in which FILEPATH is relative to the
4340 branch indicated), or None to indicate that the file is outside any
4341 project of interest.
4343 (note that we want to see ``branches/1.5.x'' rather than just
4344 ``1.5.x'' because when we perform the SVN checkout, we will probably
4345 append the branch name to the baseURL, which requires that we keep the
4346 ``branches'' component in there. Other VC schemes use a different
4347 approach towards branches and may not require this artifact.)
4349 If your repository uses this same PROJECT/BRANCH/FILEPATH naming
4350 scheme, the following function will work:
4352 @example
4353 def split_file_branches(path):
4354     pieces = path.split('/')
4355     if pieces[0] == 'trunk':
4356         return (None, '/'.join(pieces[1:]))
4357     elif pieces[0] == 'branches':
4358         return ('/'.join(pieces[0:2]),
4359                 '/'.join(pieces[2:]))
4360     else:
4361         return None
4362 @end example
4364 This function is provided as
4365 @code{buildbot.changes.svnpoller.split_file_branches} for your
4366 convenience. So to have our Twisted-watching @code{SVNPoller} follow
4367 multiple branches, we would use this:
4369 @example
4370 from buildbot.changes.svnpoller import SVNPoller, split_file_branches
4371 c['change_source'] = SVNPoller("svn://svn.twistedmatrix.com/svn/Twisted",
4372                                split_file=split_file_branches)
4373 @end example
4375 Changes for all sorts of branches (with names like ``branches/1.5.x'',
4376 and None to indicate the trunk) will be delivered to the Schedulers.
4377 Each Scheduler is then free to use or ignore each branch as it sees
4378 fit.
4380 @subheading BRANCHNAME/PROJECT/FILEPATH repositories
4382 Another common way to organize a Subversion repository is to put the
4383 branch name at the top, and the projects underneath. This is
4384 especially frequent when there are a number of related sub-projects
4385 that all get released in a group.
4387 For example, Divmod.org hosts a project named ``Nevow'' as well as one
4388 named ``Quotient''. In a checked-out Nevow tree there is a directory
4389 named ``formless'' that contains a python source file named
4390 ``webform.py''. This repository is accessible via webdav (and thus
4391 uses an ``http:'' scheme) through the divmod.org hostname. There are
4392 many branches in this repository, and they use a
4393 (BRANCHNAME)/(PROJECT) naming policy.
4395 The fully-qualified SVN URL for the trunk version of webform.py is
4396 @code{http://divmod.org/svn/Divmod/trunk/Nevow/formless/webform.py}.
4397 You can do an @code{svn co} with that URL and get a copy of the latest
4398 version. The 1.5.x branch version of this file would have a URL of
4399 @code{http://divmod.org/svn/Divmod/branches/1.5.x/Nevow/formless/webform.py}.
4400 The whole Nevow trunk would be checked out with
4401 @code{http://divmod.org/svn/Divmod/trunk/Nevow}, while the Quotient
4402 trunk would be checked out using
4403 @code{http://divmod.org/svn/Divmod/trunk/Quotient}.
4405 Now suppose we want to have an @code{SVNPoller} that only cares about
4406 the Nevow trunk. This case looks just like the PROJECT/BRANCH layout
4407 described earlier:
4409 @example
4410 from buildbot.changes.svnpoller import SVNPoller
4411 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod/trunk/Nevow")
4412 @end example
4414 But what happens when we want to track multiple Nevow branches? We
4415 have to point our @code{svnurl=} high enough to see all those
4416 branches, but we also don't want to include Quotient changes (since
4417 we're only building Nevow). To accomplish this, we must rely upon the
4418 @code{split_file} function to help us tell the difference between
4419 files that belong to Nevow and those that belong to Quotient, as well
4420 as figuring out which branch each one is on.
4422 @example
4423 from buildbot.changes.svnpoller import SVNPoller
4424 c['change_source'] = SVNPoller("http://divmod.org/svn/Divmod",
4425                                split_file=my_file_splitter)
4426 @end example
4428 The @code{my_file_splitter} function will be called with
4429 repository-relative pathnames like:
4431 @table @code
4432 @item trunk/Nevow/formless/webform.py
4433 This is a Nevow file, on the trunk. We want the Change that includes this
4434 to see a filename of @code{formless/webform.py"}, and a branch of None
4436 @item branches/1.5.x/Nevow/formless/webform.py
4437 This is a Nevow file, on a branch. We want to get
4438 branch=''branches/1.5.x'' and filename=''formless/webform.py''.
4440 @item trunk/Quotient/setup.py
4441 This is a Quotient file, so we want to ignore it by having
4442 @code{my_file_splitter} return None.
4444 @item branches/1.5.x/Quotient/setup.py
4445 This is also a Quotient file, which should be ignored.
4446 @end table
4448 The following definition for @code{my_file_splitter} will do the job:
4450 @example
4451 def my_file_splitter(path):
4452     pieces = path.split('/')
4453     if pieces[0] == 'trunk':
4454         branch = None
4455         pieces.pop(0) # remove 'trunk'
4456     elif pieces[0] == 'branches':
4457         pieces.pop(0) # remove 'branches'
4458         # grab branch name
4459         branch = 'branches/' + pieces.pop(0)
4460     else:
4461         return None # something weird
4462     projectname = pieces.pop(0)
4463     if projectname != 'Nevow':
4464         return None # wrong project
4465     return (branch, '/'.join(pieces))
4466 @end example
4468 @node MercurialHook,  Bzr Hook, SVNPoller, Getting Source Code Changes
4469 @section MercurialHook
4471 Since Mercurial is written in python, the hook script can invoke
4472 Buildbot's @code{sendchange} function directly, rather than having to
4473 spawn an external process. This function delivers the same sort of
4474 changes as @code{buildbot sendchange} and the various hook scripts in
4475 contrib/, so you'll need to add a @code{pb.PBChangeSource} to your
4476 buildmaster to receive these changes.
4478 To set this up, first choose a Mercurial repository that represents
4479 your central ``official'' source tree. This will be the same
4480 repository that your buildslaves will eventually pull from. Install
4481 Buildbot on the machine that hosts this repository, using the same
4482 version of python as Mercurial is using (so that the Mercurial hook
4483 can import code from buildbot). Then add the following to the
4484 @code{.hg/hgrc} file in that repository, replacing the buildmaster
4485 hostname/portnumber as appropriate for your buildbot:
4487 @example
4488 [hooks]
4489 changegroup.buildbot = python:buildbot.changes.hgbuildbot.hook
4491 [hgbuildbot]
4492 master = buildmaster.example.org:9987
4493 @end example
4495 (Note that Mercurial lets you define multiple @code{changegroup} hooks
4496 by giving them distinct names, like @code{changegroup.foo} and
4497 @code{changegroup.bar}, which is why we use
4498 @code{changegroup.buildbot} in this example. There is nothing magical
4499 about the ``buildbot'' suffix in the hook name. The
4500 @code{[hgbuildbot]} section @emph{is} special, however, as it is the
4501 only section that the buildbot hook pays attention to.)
4503 Also note that this runs as a @code{changegroup} hook, rather than as
4504 an @code{incoming} hook. The @code{changegroup} hook is run with
4505 multiple revisions at a time (say, if multiple revisions are being
4506 pushed to this repository in a single @command{hg push} command),
4507 whereas the @code{incoming} hook is run with just one revision at a
4508 time. The @code{hgbuildbot.hook} function will only work with the
4509 @code{changegroup} hook.
4511 The @code{[hgbuildbot]} section has two other parameters that you
4512 might specify, both of which control the name of the branch that is
4513 attached to the changes coming from this hook.
4515 One common branch naming policy for Mercurial repositories is to use
4516 it just like Darcs: each branch goes into a separate repository, and
4517 all the branches for a single project share a common parent directory.
4518 For example, you might have @file{/var/repos/PROJECT/trunk/} and
4519 @file{/var/repos/PROJECT/release}. To use this style, use the
4520 @code{branchtype = dirname} setting, which simply uses the last
4521 component of the repository's enclosing directory as the branch name:
4523 @example
4524 [hgbuildbot]
4525 master = buildmaster.example.org:9987
4526 branchtype = dirname
4527 @end example
4529 Another approach is to use Mercurial's built-in branches (the kind
4530 created with @command{hg branch} and listed with @command{hg
4531 branches}). This feature associates persistent names with particular
4532 lines of descent within a single repository. (note that the buildbot
4533 @code{source.Mercurial} checkout step does not yet support this kind
4534 of branch). To have the commit hook deliver this sort of branch name
4535 with the Change object, use @code{branchtype = inrepo}:
4537 @example
4538 [hgbuildbot]
4539 master = buildmaster.example.org:9987
4540 branchtype = inrepo
4541 @end example
4543 Finally, if you want to simply specify the branchname directly, for
4544 all changes, use @code{branch = BRANCHNAME}. This overrides
4545 @code{branchtype}:
4547 @example
4548 [hgbuildbot]
4549 master = buildmaster.example.org:9987
4550 branch = trunk
4551 @end example
4553 If you use @code{branch=} like this, you'll need to put a separate
4554 .hgrc in each repository. If you use @code{branchtype=}, you may be
4555 able to use the same .hgrc for all your repositories, stored in
4556 @file{~/.hgrc} or @file{/etc/mercurial/hgrc}.
4559 @node Bzr Hook, Bzr Poller, MercurialHook, Getting Source Code Changes
4560 @section Bzr Hook
4562 Bzr is also written in Python, and the Bzr hook depends on Twisted to send the
4563 changes.
4565 To install, put @code{contrib/bzr_buildbot.py} in one of your plugins
4566 locations a bzr plugins directory (e.g.,
4567 @code{~/.bazaar/plugins}). Then, in one of your bazaar conf files (e.g.,
4568 @code{~/.bazaar/locations.conf}), set the location you want to connect with buildbot
4569 with these keys:
4571 @table @code
4572 @item buildbot_on
4573 one of 'commit', 'push, or 'change'. Turns the plugin on to report changes via
4574 commit, changes via push, or any changes to the trunk. 'change' is
4575 recommended.
4577 @item buildbot_server
4578 (required to send to a buildbot master) the URL of the buildbot master to
4579 which you will connect (as of this writing, the same server and port to which
4580 slaves connect).
4582 @item buildbot_port
4583 (optional, defaults to 9989) the port of the buildbot master to which you will
4584 connect (as of this writing, the same server and port to which slaves connect)
4586 @item buildbot_pqm
4587 (optional, defaults to not pqm) Normally, the user that commits the revision
4588 is the user that is responsible for the change. When run in a pqm (Patch Queue
4589 Manager, see https://launchpad.net/pqm) environment, the user that commits is
4590 the Patch Queue Manager, and the user that committed the *parent* revision is
4591 responsible for the change. To turn on the pqm mode, set this value to any of
4592 (case-insensitive) "Yes", "Y", "True", or "T".
4594 @item buildbot_dry_run
4595 (optional, defaults to not a dry run) Normally, the post-commit hook will
4596 attempt to communicate with the configured buildbot server and port. If this
4597 parameter is included and any of (case-insensitive) "Yes", "Y", "True", or
4598 "T", then the hook will simply print what it would have sent, but not attempt
4599 to contact the buildbot master.
4601 @item buildbot_send_branch_name
4602 (optional, defaults to not sending the branch name) If your buildbot's bzr
4603 source build step uses a repourl, do *not* turn this on. If your buildbot's
4604 bzr build step uses a baseURL, then you may set this value to any of
4605 (case-insensitive) "Yes", "Y", "True", or "T" to have the buildbot master
4606 append the branch name to the baseURL.
4608 @end table
4610 When buildbot no longer has a hardcoded password, it will be a configuration
4611 option here as well.
4613 Here's a simple example that you might have in your
4614 @code{~/.bazaar/locations.conf}.
4616 @example
4617 [chroot-*:///var/local/myrepo/mybranch]
4618 buildbot_on = change
4619 buildbot_server = localhost
4620 @end example
4622 @node Bzr Poller, , Bzr Hook, Getting Source Code Changes
4623 @section Bzr Poller
4625 If you cannot insert a Bzr hook in the server, you can use the Bzr Poller. To
4626 use, put @code{contrib/bzr_buildbot.py} somewhere that your buildbot
4627 configuration can import it. Even putting it in the same directory as the master.cfg
4628 should work. Install the poller in the buildbot configuration as with any
4629 other change source. Minimally, provide a URL that you want to poll (bzr://,
4630 bzr+ssh://, or lp:), though make sure the buildbot user has necessary
4631 privileges. You may also want to specify these optional values.
4633 @table @code
4634 @item poll_interval
4635 The number of seconds to wait between polls.  Defaults to 10 minutes.
4637 @item branch_name
4638 Any value to be used as the branch name. Defaults to None, or specify a
4639 string, or specify the constants from @code{bzr_buildbot.py} SHORT or FULL to
4640 get the short branch name or full branch address.
4642 @item blame_merge_author
4643 normally, the user that commits the revision is the user that is responsible
4644 for the change. When run in a pqm (Patch Queue Manager, see
4645 https://launchpad.net/pqm) environment, the user that commits is the Patch
4646 Queue Manager, and the user that committed the merged, *parent* revision is
4647 responsible for the change. set this value to True if this is pointed against
4648 a PQM-managed branch.
4649 @end table
4651 @node Build Process, Status Delivery, Getting Source Code Changes, Top
4652 @chapter Build Process
4654 A @code{Build} object is responsible for actually performing a build.
4655 It gets access to a remote @code{SlaveBuilder} where it may run
4656 commands, and a @code{BuildStatus} object where it must emit status
4657 events. The @code{Build} is created by the Builder's
4658 @code{BuildFactory}.
4660 The default @code{Build} class is made up of a fixed sequence of
4661 @code{BuildSteps}, executed one after another until all are complete
4662 (or one of them indicates that the build should be halted early). The
4663 default @code{BuildFactory} creates instances of this @code{Build}
4664 class with a list of @code{BuildSteps}, so the basic way to configure
4665 the build is to provide a list of @code{BuildSteps} to your
4666 @code{BuildFactory}.
4668 More complicated @code{Build} subclasses can make other decisions:
4669 execute some steps only if certain files were changed, or if certain
4670 previous steps passed or failed. The base class has been written to
4671 allow users to express basic control flow without writing code, but
4672 you can always subclass and customize to achieve more specialized
4673 behavior.
4675 @menu
4676 * Build Steps::
4677 * Interlocks::
4678 * Build Factories::
4679 @end menu
4681 @node Build Steps, Interlocks, Build Process, Build Process
4682 @section Build Steps
4684 @code{BuildStep}s are usually specified in the buildmaster's
4685 configuration file, in a list that goes into the @code{BuildFactory}.
4686 The @code{BuildStep} instances in this list are used as templates to
4687 construct new independent copies for each build (so that state can be
4688 kept on the @code{BuildStep} in one build without affecting a later
4689 build). Each @code{BuildFactory} can be created with a list of steps,
4690 or the factory can be created empty and then steps added to it using
4691 the @code{addStep} method:
4693 @example
4694 from buildbot.steps import source, shell
4695 from buildbot.process import factory
4697 f = factory.BuildFactory()
4698 f.addStep(source.SVN(svnurl="http://svn.example.org/Trunk/"))
4699 f.addStep(shell.ShellCommand(command=["make", "all"]))
4700 f.addStep(shell.ShellCommand(command=["make", "test"]))
4701 @end example
4703 In earlier versions (0.7.5 and older), these steps were specified with
4704 a tuple of (step_class, keyword_arguments). Steps can still be
4705 specified this way, but the preferred form is to pass actual
4706 @code{BuildStep} instances to @code{addStep}, because that gives the
4707 @code{BuildStep} class a chance to do some validation on the
4708 arguments.
4710 If you have a common set of steps which are used in several factories, the
4711 @code{addSteps} method may be handy.  It takes an iterable of @code{BuildStep}
4712 instances.
4714 @example
4715 setup_steps = [
4716     source.SVN(svnurl="http://svn.example.org/Trunk/")
4717     shell.ShellCommand(command="./setup")
4719 quick = factory.BuildFactory()
4720 quick.addSteps(setup_steps)
4721 quick.addStep(shell.shellCommand(command="make quick"))
4722 @end example
4724 The rest of this section lists all the standard BuildStep objects
4725 available for use in a Build, and the parameters which can be used to
4726 control each.
4728 @menu
4729 * Common Parameters::
4730 * Using Build Properties::
4731 * Source Checkout::
4732 * ShellCommand::
4733 * Simple ShellCommand Subclasses::
4734 * Python BuildSteps::
4735 * Transferring Files::
4736 * Steps That Run on the Master::
4737 * Triggering Schedulers::
4738 * Writing New BuildSteps::
4739 @end menu
4741 @node Common Parameters, Using Build Properties, Build Steps, Build Steps
4742 @subsection Common Parameters
4744 The standard @code{Build} runs a series of @code{BuildStep}s in order,
4745 only stopping when it runs out of steps or if one of them requests
4746 that the build be halted. It collects status information from each one
4747 to create an overall build status (of SUCCESS, WARNINGS, or FAILURE).
4749 All BuildSteps accept some common parameters. Some of these control
4750 how their individual status affects the overall build. Others are used
4751 to specify which @code{Locks} (see @pxref{Interlocks}) should be
4752 acquired before allowing the step to run.
4754 Arguments common to all @code{BuildStep} subclasses:
4757 @table @code
4758 @item name
4759 the name used to describe the step on the status display. It is also
4760 used to give a name to any LogFiles created by this step.
4762 @item haltOnFailure
4763 if True, a FAILURE of this build step will cause the build to halt
4764 immediately. Steps with @code{alwaysRun=True} are still run. Generally
4765 speaking, haltOnFailure implies flunkOnFailure (the default for most
4766 BuildSteps). In some cases, particularly series of tests, it makes sense
4767 to haltOnFailure if something fails early on but not flunkOnFailure.
4768 This can be achieved with haltOnFailure=True, flunkOnFailure=False.
4770 @item flunkOnWarnings
4771 when True, a WARNINGS or FAILURE of this build step will mark the
4772 overall build as FAILURE. The remaining steps will still be executed.
4774 @item flunkOnFailure
4775 when True, a FAILURE of this build step will mark the overall build as
4776 a FAILURE. The remaining steps will still be executed.
4778 @item warnOnWarnings
4779 when True, a WARNINGS or FAILURE of this build step will mark the
4780 overall build as having WARNINGS. The remaining steps will still be
4781 executed.
4783 @item warnOnFailure
4784 when True, a FAILURE of this build step will mark the overall build as
4785 having WARNINGS. The remaining steps will still be executed.
4787 @item alwaysRun
4788 if True, this build step will always be run, even if a previous buildstep
4789 with @code{haltOnFailure=True} has failed.
4791 @item locks
4792 a list of Locks (instances of @code{buildbot.locks.SlaveLock} or
4793 @code{buildbot.locks.MasterLock}) that should be acquired before
4794 starting this Step. The Locks will be released when the step is
4795 complete. Note that this is a list of actual Lock instances, not
4796 names. Also note that all Locks must have unique names.
4798 @end table
4800 @node Using Build Properties, Source Checkout, Common Parameters, Build Steps
4801 @subsection Using Build Properties
4802 @cindex Properties
4804 Build properties are a generalized way to provide configuration
4805 information to build steps; see @ref{Build Properties}.
4807 Some build properties are inherited from external sources -- global
4808 properties, schedulers, or buildslaves.  Some build properties are
4809 set when the build starts, such as the SourceStamp information. Other
4810 properties can be set by BuildSteps as they run, for example the
4811 various Source steps will set the @code{got_revision} property to the
4812 source revision that was actually checked out (which can be useful
4813 when the SourceStamp in use merely requested the ``latest revision'':
4814 @code{got_revision} will tell you what was actually built).
4816 In custom BuildSteps, you can get and set the build properties with
4817 the @code{getProperty}/@code{setProperty} methods. Each takes a string
4818 for the name of the property, and returns or accepts an
4819 arbitrary@footnote{Build properties are serialized along with the
4820 build results, so they must be serializable. For this reason, the
4821 value of any build property should be simple inert data: strings,
4822 numbers, lists, tuples, and dictionaries. They should not contain
4823 class instances.} object. For example:
4825 @example
4826 class MakeTarball(ShellCommand):
4827     def start(self):
4828         if self.getProperty("os") == "win":
4829             self.setCommand([ ... ]) # windows-only command
4830         else:
4831             self.setCommand([ ... ]) # equivalent for other systems
4832         ShellCommand.start(self)
4833 @end example
4835 @heading WithProperties
4836 @cindex WithProperties
4838 You can use build properties in ShellCommands by using the
4839 @code{WithProperties} wrapper when setting the arguments of
4840 the ShellCommand. This interpolates the named build properties
4841 into the generated shell command.  Most step parameters accept
4842 @code{WithProperties}.  Please file bugs for any parameters which
4843 do not.
4845 @example
4846 from buildbot.steps.shell import ShellCommand
4847 from buildbot.process.properties import WithProperties
4849 f.addStep(ShellCommand(
4850           command=["tar", "czf",
4851                    WithProperties("build-%s.tar.gz", "revision"),
4852                    "source"]))
4853 @end example
4855 If this BuildStep were used in a tree obtained from Subversion, it
4856 would create a tarball with a name like @file{build-1234.tar.gz}.
4858 The @code{WithProperties} function does @code{printf}-style string
4859 interpolation, using strings obtained by calling
4860 @code{build.getProperty(propname)}. Note that for every @code{%s} (or
4861 @code{%d}, etc), you must have exactly one additional argument to
4862 indicate which build property you want to insert.
4864 You can also use python dictionary-style string interpolation by using
4865 the @code{%(propname)s} syntax. In this form, the property name goes
4866 in the parentheses, and WithProperties takes @emph{no} additional
4867 arguments:
4869 @example
4870 f.addStep(ShellCommand(
4871           command=["tar", "czf",
4872                    WithProperties("build-%(revision)s.tar.gz"),
4873                    "source"]))
4874 @end example
4876 Don't forget the extra ``s'' after the closing parenthesis! This is
4877 the cause of many confusing errors.
4879 The dictionary-style interpolation supports a number of more advanced
4880 syntaxes, too.
4882 @table @code
4884 @item propname:-replacement
4885 If @code{propname} exists, substitute its value; otherwise,
4886 substitute @code{replacement}.  @code{replacement} may be empty
4887 (@code{%(propname:-)s})
4889 @item propname:+replacement
4890 If @code{propname} exists, substitute @code{replacement}; otherwise,
4891 substitute an empty string.
4893 @end table
4895 Although these are similar to shell substitutions, no other
4896 substitutions are currently supported, and @code{replacement} in the
4897 above cannot contain more substitutions.
4899 Note: like python, you can either do positional-argument interpolation
4900 @emph{or} keyword-argument interpolation, not both. Thus you cannot use
4901 a string like @code{WithProperties("foo-%(revision)s-%s", "branch")}.
4903 @heading Common Build Properties
4905 The following build properties are set when the build is started, and
4906 are available to all steps.
4908 @table @code
4909 @item branch
4911 This comes from the build's SourceStamp, and describes which branch is
4912 being checked out. This will be @code{None} (which interpolates into
4913 @code{WithProperties} as an empty string) if the build is on the
4914 default branch, which is generally the trunk. Otherwise it will be a
4915 string like ``branches/beta1.4''. The exact syntax depends upon the VC
4916 system being used.
4918 @item revision
4920 This also comes from the SourceStamp, and is the revision of the source code
4921 tree that was requested from the VC system. When a build is requested of a
4922 specific revision (as is generally the case when the build is triggered by
4923 Changes), this will contain the revision specification. This is always a
4924 string, although the syntax depends upon the VC system in use: for SVN it is an
4925 integer, for Mercurial it is a short string, for Darcs it is a rather large
4926 string, etc.
4928 If the ``force build'' button was pressed, the revision will be @code{None},
4929 which means to use the most recent revision available.  This is a ``trunk
4930 build''. This will be interpolated as an empty string.
4932 @item got_revision
4934 This is set when a Source step checks out the source tree, and
4935 provides the revision that was actually obtained from the VC system.
4936 In general this should be the same as @code{revision}, except for
4937 trunk builds, where @code{got_revision} indicates what revision was
4938 current when the checkout was performed. This can be used to rebuild
4939 the same source code later.
4941 Note that for some VC systems (Darcs in particular), the revision is a
4942 large string containing newlines, and is not suitable for interpolation
4943 into a filename.
4945 @item buildername
4947 This is a string that indicates which Builder the build was a part of.
4948 The combination of buildername and buildnumber uniquely identify a
4949 build.
4951 @item buildnumber
4953 Each build gets a number, scoped to the Builder (so the first build
4954 performed on any given Builder will have a build number of 0). This
4955 integer property contains the build's number.
4957 @item slavename
4959 This is a string which identifies which buildslave the build is
4960 running on.
4962 @item scheduler
4964 If the build was started from a scheduler, then this property will
4965 contain the name of that scheduler.
4967 @end table
4970 @node Source Checkout, ShellCommand, Using Build Properties, Build Steps
4971 @subsection Source Checkout
4973 The first step of any build is typically to acquire the source code
4974 from which the build will be performed. There are several classes to
4975 handle this, one for each of the different source control system that
4976 Buildbot knows about. For a description of how Buildbot treats source
4977 control in general, see @ref{Version Control Systems}.
4979 All source checkout steps accept some common parameters to control how
4980 they get the sources and where they should be placed. The remaining
4981 per-VC-system parameters are mostly to specify where exactly the
4982 sources are coming from.
4984 @table @code
4985 @item mode
4987 a string describing the kind of VC operation that is desired. Defaults
4988 to @code{update}.
4990 @table @code
4991 @item update
4992 specifies that the CVS checkout/update should be performed directly
4993 into the workdir. Each build is performed in the same directory,
4994 allowing for incremental builds. This minimizes disk space, bandwidth,
4995 and CPU time. However, it may encounter problems if the build process
4996 does not handle dependencies properly (sometimes you must do a ``clean
4997 build'' to make sure everything gets compiled), or if source files are
4998 deleted but generated files can influence test behavior (e.g. python's
4999 .pyc files), or when source directories are deleted but generated
5000 files prevent CVS from removing them. Builds ought to be correct
5001 regardless of whether they are done ``from scratch'' or incrementally,
5002 but it is useful to test both kinds: this mode exercises the
5003 incremental-build style.
5005 @item copy
5006 specifies that the CVS workspace should be maintained in a separate
5007 directory (called the 'copydir'), using checkout or update as
5008 necessary. For each build, a new workdir is created with a copy of the
5009 source tree (rm -rf workdir; cp -r copydir workdir). This doubles the
5010 disk space required, but keeps the bandwidth low (update instead of a
5011 full checkout). A full 'clean' build is performed each time. This
5012 avoids any generated-file build problems, but is still occasionally
5013 vulnerable to CVS problems such as a repository being manually
5014 rearranged, causing CVS errors on update which are not an issue with a
5015 full checkout.
5017 @c TODO: something is screwy about this, revisit. Is it the source
5018 @c directory or the working directory that is deleted each time?
5020 @item clobber
5021 specifes that the working directory should be deleted each time,
5022 necessitating a full checkout for each build. This insures a clean
5023 build off a complete checkout, avoiding any of the problems described
5024 above. This mode exercises the ``from-scratch'' build style.
5026 @item export
5027 this is like @code{clobber}, except that the 'cvs export' command is
5028 used to create the working directory. This command removes all CVS
5029 metadata files (the CVS/ directories) from the tree, which is
5030 sometimes useful for creating source tarballs (to avoid including the
5031 metadata in the tar file).
5032 @end table
5034 @item workdir
5035 like all Steps, this indicates the directory where the build will take
5036 place. Source Steps are special in that they perform some operations
5037 outside of the workdir (like creating the workdir itself).
5039 @item alwaysUseLatest
5040 if True, bypass the usual ``update to the last Change'' behavior, and
5041 always update to the latest changes instead.
5043 @item retry
5044 If set, this specifies a tuple of @code{(delay, repeats)} which means
5045 that when a full VC checkout fails, it should be retried up to
5046 @var{repeats} times, waiting @var{delay} seconds between attempts. If
5047 you don't provide this, it defaults to @code{None}, which means VC
5048 operations should not be retried. This is provided to make life easier
5049 for buildslaves which are stuck behind poor network connections.
5051 @end table
5054 My habit as a developer is to do a @code{cvs update} and @code{make} each
5055 morning. Problems can occur, either because of bad code being checked in, or
5056 by incomplete dependencies causing a partial rebuild to fail where a
5057 complete from-scratch build might succeed. A quick Builder which emulates
5058 this incremental-build behavior would use the @code{mode='update'}
5059 setting.
5061 On the other hand, other kinds of dependency problems can cause a clean
5062 build to fail where a partial build might succeed. This frequently results
5063 from a link step that depends upon an object file that was removed from a
5064 later version of the tree: in the partial tree, the object file is still
5065 around (even though the Makefiles no longer know how to create it).
5067 ``official'' builds (traceable builds performed from a known set of
5068 source revisions) are always done as clean builds, to make sure it is
5069 not influenced by any uncontrolled factors (like leftover files from a
5070 previous build). A ``full'' Builder which behaves this way would want
5071 to use the @code{mode='clobber'} setting.
5073 Each VC system has a corresponding source checkout class: their
5074 arguments are described on the following pages.
5077 @menu
5078 * CVS::
5079 * SVN::
5080 * Darcs::
5081 * Mercurial::
5082 * Arch::
5083 * Bazaar::
5084 * Bzr::
5085 * P4::
5086 * Git::
5087 @end menu
5089 @node CVS, SVN, Source Checkout, Source Checkout
5090 @subsubsection CVS
5091 @cindex CVS Checkout
5092 @bsindex buildbot.steps.source.CVS
5095 The @code{CVS} build step performs a @uref{http://www.nongnu.org/cvs/,
5096 CVS} checkout or update. It takes the following arguments:
5098 @table @code
5099 @item cvsroot
5100 (required): specify the CVSROOT value, which points to a CVS
5101 repository, probably on a remote machine. For example, the cvsroot
5102 value you would use to get a copy of the Buildbot source code is
5103 @code{:pserver:anonymous@@cvs.sourceforge.net:/cvsroot/buildbot}
5105 @item cvsmodule
5106 (required): specify the cvs @code{module}, which is generally a
5107 subdirectory of the CVSROOT. The cvsmodule for the Buildbot source
5108 code is @code{buildbot}.
5110 @item branch
5111 a string which will be used in a @code{-r} argument. This is most
5112 useful for specifying a branch to work on. Defaults to @code{HEAD}.
5114 @item global_options
5115 a list of flags to be put before the verb in the CVS command.
5117 @item checkoutDelay
5118 if set, the number of seconds to put between the timestamp of the last
5119 known Change and the value used for the @code{-D} option. Defaults to
5120 half of the parent Build's treeStableTimer.
5122 @end table
5125 @node SVN, Darcs, CVS, Source Checkout
5126 @subsubsection SVN
5128 @cindex SVN Checkout
5129 @bsindex buildbot.steps.source.SVN
5132 The @code{SVN} build step performs a
5133 @uref{http://subversion.tigris.org, Subversion} checkout or update.
5134 There are two basic ways of setting up the checkout step, depending
5135 upon whether you are using multiple branches or not.
5137 If all of your builds use the same branch, then you should create the
5138 @code{SVN} step with the @code{svnurl} argument:
5140 @table @code
5141 @item svnurl
5142 (required): this specifies the @code{URL} argument that will be given
5143 to the @code{svn checkout} command. It dictates both where the
5144 repository is located and which sub-tree should be extracted. In this
5145 respect, it is like a combination of the CVS @code{cvsroot} and
5146 @code{cvsmodule} arguments. For example, if you are using a remote
5147 Subversion repository which is accessible through HTTP at a URL of
5148 @code{http://svn.example.com/repos}, and you wanted to check out the
5149 @code{trunk/calc} sub-tree, you would use
5150 @code{svnurl="http://svn.example.com/repos/trunk/calc"} as an argument
5151 to your @code{SVN} step.
5152 @end table
5154 If, on the other hand, you are building from multiple branches, then
5155 you should create the @code{SVN} step with the @code{baseURL} and
5156 @code{defaultBranch} arguments instead:
5158 @table @code
5159 @item baseURL
5160 (required): this specifies the base repository URL, to which a branch
5161 name will be appended. It should probably end in a slash.
5163 @item defaultBranch
5164 this specifies the name of the branch to use when a Build does not
5165 provide one of its own. This will be appended to @code{baseURL} to
5166 create the string that will be passed to the @code{svn checkout}
5167 command.
5169 @item username
5170 if specified, this will be passed to the @code{svn} binary with a
5171 @code{--username} option.
5173 @item password
5174 if specified, this will be passed to the @code{svn} binary with a
5175 @code{--password} option.  The password itself will be suitably obfuscated in
5176 the logs.
5178 @item extra_args
5179 if specified, an array of strings that will be passed as extra
5180 arguments to the @code{svn} binary.
5182 @end table
5184 If you are using branches, you must also make sure your
5185 @code{ChangeSource} will report the correct branch names.
5187 @heading branch example
5189 Let's suppose that the ``MyProject'' repository uses branches for the
5190 trunk, for various users' individual development efforts, and for
5191 several new features that will require some amount of work (involving
5192 multiple developers) before they are ready to merge onto the trunk.
5193 Such a repository might be organized as follows:
5195 @example
5196 svn://svn.example.org/MyProject/trunk
5197 svn://svn.example.org/MyProject/branches/User1/foo
5198 svn://svn.example.org/MyProject/branches/User1/bar
5199 svn://svn.example.org/MyProject/branches/User2/baz
5200 svn://svn.example.org/MyProject/features/newthing
5201 svn://svn.example.org/MyProject/features/otherthing
5202 @end example
5204 Further assume that we want the Buildbot to run tests against the
5205 trunk and against all the feature branches (i.e., do a
5206 checkout/compile/build of branch X when a file has been changed on
5207 branch X, when X is in the set [trunk, features/newthing,
5208 features/otherthing]). We do not want the Buildbot to automatically
5209 build any of the user branches, but it should be willing to build a
5210 user branch when explicitly requested (most likely by the user who
5211 owns that branch).
5213 There are three things that need to be set up to accomodate this
5214 system. The first is a ChangeSource that is capable of identifying the
5215 branch which owns any given file. This depends upon a user-supplied
5216 function, in an external program that runs in the SVN commit hook and
5217 connects to the buildmaster's @code{PBChangeSource} over a TCP
5218 connection. (you can use the ``@code{buildbot sendchange}'' utility
5219 for this purpose, but you will still need an external program to
5220 decide what value should be passed to the @code{--branch=} argument).
5221 For example, a change to a file with the SVN url of
5222 ``svn://svn.example.org/MyProject/features/newthing/src/foo.c'' should
5223 be broken down into a Change instance with
5224 @code{branch='features/newthing'} and @code{file='src/foo.c'}.
5226 The second piece is an @code{AnyBranchScheduler} which will pay
5227 attention to the desired branches. It will not pay attention to the
5228 user branches, so it will not automatically start builds in response
5229 to changes there. The AnyBranchScheduler class requires you to
5230 explicitly list all the branches you want it to use, but it would not
5231 be difficult to write a subclass which used
5232 @code{branch.startswith('features/'} to remove the need for this
5233 explicit list. Or, if you want to build user branches too, you can use
5234 AnyBranchScheduler with @code{branches=None} to indicate that you want
5235 it to pay attention to all branches.
5237 The third piece is an @code{SVN} checkout step that is configured to
5238 handle the branches correctly, with a @code{baseURL} value that
5239 matches the way the ChangeSource splits each file's URL into base,
5240 branch, and file.
5242 @example
5243 from buildbot.changes.pb import PBChangeSource
5244 from buildbot.scheduler import AnyBranchScheduler
5245 from buildbot.process import source, factory
5246 from buildbot.steps import source, shell
5248 c['change_source'] = PBChangeSource()
5249 s1 = AnyBranchScheduler('main',
5250                         ['trunk', 'features/newthing', 'features/otherthing'],
5251                         10*60, ['test-i386', 'test-ppc'])
5252 c['schedulers'] = [s1]
5254 f = factory.BuildFactory()
5255 f.addStep(source.SVN(mode='update',
5256                      baseURL='svn://svn.example.org/MyProject/',
5257                      defaultBranch='trunk'))
5258 f.addStep(shell.Compile(command="make all"))
5259 f.addStep(shell.Test(command="make test"))
5261 c['builders'] = [
5262   @{'name':'test-i386', 'slavename':'bot-i386', 'builddir':'test-i386',
5263                        'factory':f @},
5264   @{'name':'test-ppc', 'slavename':'bot-ppc', 'builddir':'test-ppc',
5265                       'factory':f @},
5267 @end example
5269 In this example, when a change arrives with a @code{branch} attribute
5270 of ``trunk'', the resulting build will have an SVN step that
5271 concatenates ``svn://svn.example.org/MyProject/'' (the baseURL) with
5272 ``trunk'' (the branch name) to get the correct svn command. If the
5273 ``newthing'' branch has a change to ``src/foo.c'', then the SVN step
5274 will concatenate ``svn://svn.example.org/MyProject/'' with
5275 ``features/newthing'' to get the svnurl for checkout.
5277 @node Darcs, Mercurial, SVN, Source Checkout
5278 @subsubsection Darcs
5280 @cindex Darcs Checkout
5281 @bsindex buildbot.steps.source.Darcs
5284 The @code{Darcs} build step performs a
5285 @uref{http://darcs.net/, Darcs} checkout or update.
5287 Like @xref{SVN}, this step can either be configured to always check
5288 out a specific tree, or set up to pull from a particular branch that
5289 gets specified separately for each build. Also like SVN, the
5290 repository URL given to Darcs is created by concatenating a
5291 @code{baseURL} with the branch name, and if no particular branch is
5292 requested, it uses a @code{defaultBranch}. The only difference in
5293 usage is that each potential Darcs repository URL must point to a
5294 fully-fledged repository, whereas SVN URLs usually point to sub-trees
5295 of the main Subversion repository. In other words, doing an SVN
5296 checkout of @code{baseURL} is legal, but silly, since you'd probably
5297 wind up with a copy of every single branch in the whole repository.
5298 Doing a Darcs checkout of @code{baseURL} is just plain wrong, since
5299 the parent directory of a collection of Darcs repositories is not
5300 itself a valid repository.
5302 The Darcs step takes the following arguments:
5304 @table @code
5305 @item repourl
5306 (required unless @code{baseURL} is provided): the URL at which the
5307 Darcs source repository is available.
5309 @item baseURL
5310 (required unless @code{repourl} is provided): the base repository URL,
5311 to which a branch name will be appended. It should probably end in a
5312 slash.
5314 @item defaultBranch
5315 (allowed if and only if @code{baseURL} is provided): this specifies
5316 the name of the branch to use when a Build does not provide one of its
5317 own. This will be appended to @code{baseURL} to create the string that
5318 will be passed to the @code{darcs get} command.
5319 @end table
5321 @node Mercurial, Arch, Darcs, Source Checkout
5322 @subsubsection Mercurial
5324 @cindex Mercurial Checkout
5325 @bsindex buildbot.steps.source.Mercurial
5328 The @code{Mercurial} build step performs a
5329 @uref{http://selenic.com/mercurial, Mercurial} (aka ``hg'') checkout
5330 or update.
5332 Branches are available in two modes: ''dirname'' like @xref{Darcs}, or
5333 ''inrepo'', which uses the repository internal branches. Make sure this
5334 setting matches your changehook, if you have that installed.
5336 The Mercurial step takes the following arguments:
5338 @table @code
5339 @item repourl
5340 (required unless @code{baseURL} is provided): the URL at which the
5341 Mercurial source repository is available.
5343 @item baseURL
5344 (required unless @code{repourl} is provided): the base repository URL,
5345 to which a branch name will be appended. It should probably end in a
5346 slash.
5348 @item defaultBranch
5349 (allowed if and only if @code{baseURL} is provided): this specifies
5350 the name of the branch to use when a Build does not provide one of its
5351 own. This will be appended to @code{baseURL} to create the string that
5352 will be passed to the @code{hg clone} command.
5354 @item branchType
5355 either 'dirname' (default) or 'inrepo' depending on whether
5356 the branch name should be appended to the @code{baseURL}
5357 or the branch is a mercurial named branch and can be
5358 found within the @code{repourl}.
5360 @item clobberOnBranchChange
5361 boolean, defaults to True. If set and
5362 using inrepos branches, clobber the tree
5363 at each branch change. Otherwise, just
5364 update to the branch.
5366 @end table
5369 @node Arch, Bazaar, Mercurial, Source Checkout
5370 @subsubsection Arch
5372 @cindex Arch Checkout
5373 @bsindex buildbot.steps.source.Arch
5376 The @code{Arch} build step performs an @uref{http://gnuarch.org/,
5377 Arch} checkout or update using the @code{tla} client. It takes the
5378 following arguments:
5380 @table @code
5381 @item url
5382 (required): this specifies the URL at which the Arch source archive is
5383 available.
5385 @item version
5386 (required): this specifies which ``development line'' (like a branch)
5387 should be used. This provides the default branch name, but individual
5388 builds may specify a different one.
5390 @item archive
5391 (optional): Each repository knows its own archive name. If this
5392 parameter is provided, it must match the repository's archive name.
5393 The parameter is accepted for compatibility with the @code{Bazaar}
5394 step, below.
5396 @end table
5398 @node Bazaar, Bzr, Arch, Source Checkout
5399 @subsubsection Bazaar
5401 @cindex Bazaar Checkout
5402 @bsindex buildbot.steps.source.Bazaar
5405 @code{Bazaar} is an alternate implementation of the Arch VC system,
5406 which uses a client named @code{baz}. The checkout semantics are just
5407 different enough from @code{tla} that there is a separate BuildStep for
5410 It takes exactly the same arguments as @code{Arch}, except that the
5411 @code{archive=} parameter is required. (baz does not emit the archive
5412 name when you do @code{baz register-archive}, so we must provide it
5413 ourselves).
5416 @node Bzr, P4, Bazaar, Source Checkout
5417 @subsubsection Bzr
5419 @cindex Bzr Checkout
5420 @bsindex buildbot.steps.source.Bzr
5422 @code{bzr} is a descendant of Arch/Baz, and is frequently referred to
5423 as simply ``Bazaar''. The repository-vs-workspace model is similar to
5424 Darcs, but it uses a strictly linear sequence of revisions (one
5425 history per branch) like Arch. Branches are put in subdirectories.
5426 This makes it look very much like Mercurial. It takes the following
5427 arguments:
5429 @table @code
5431 @item repourl
5432 (required unless @code{baseURL} is provided): the URL at which the
5433 Bzr source repository is available.
5435 @item baseURL
5436 (required unless @code{repourl} is provided): the base repository URL,
5437 to which a branch name will be appended. It should probably end in a
5438 slash.
5440 @item defaultBranch
5441 (allowed if and only if @code{baseURL} is provided): this specifies
5442 the name of the branch to use when a Build does not provide one of its
5443 own. This will be appended to @code{baseURL} to create the string that
5444 will be passed to the @code{bzr checkout} command.
5446 @item forceSharedRepo
5447 (boolean, optional, defaults to False): If set to True, the working directory
5448 will be made into a bzr shared repository if it is not already. Shared
5449 repository greatly reduces the amount of history data that needs to be
5450 downloaded if not using update/copy mode, or if using update/copy mode with
5451 multiple branches.
5452 @end table
5456 @node P4, Git, Bzr, Source Checkout
5457 @subsubsection P4
5459 @cindex Perforce Update
5460 @bsindex buildbot.steps.source.P4
5461 @c TODO @bsindex buildbot.steps.source.P4Sync
5464 The @code{P4} build step creates a @uref{http://www.perforce.com/,
5465 Perforce} client specification and performs an update.
5467 @table @code
5468 @item p4base
5469 A view into the Perforce depot without branch name or trailing "...".
5470 Typically "//depot/proj/".
5471 @item defaultBranch
5472 A branch name to append on build requests if none is specified.
5473 Typically "trunk".
5474 @item p4port
5475 (optional): the host:port string describing how to get to the P4 Depot
5476 (repository), used as the -p argument for all p4 commands.
5477 @item p4user
5478 (optional): the Perforce user, used as the -u argument to all p4
5479 commands.
5480 @item p4passwd
5481 (optional): the Perforce password, used as the -p argument to all p4
5482 commands.
5483 @item p4extra_views
5484 (optional): a list of (depotpath, clientpath) tuples containing extra
5485 views to be mapped into the client specification. Both will have
5486 "/..." appended automatically. The client name and source directory
5487 will be prepended to the client path.
5488 @item p4client
5489 (optional): The name of the client to use. In mode='copy' and
5490 mode='update', it's particularly important that a unique name is used
5491 for each checkout directory to avoid incorrect synchronization. For
5492 this reason, Python percent substitution will be performed on this value
5493 to replace %(slave)s with the slave name and %(builder)s with the
5494 builder name. The default is "buildbot_%(slave)s_%(build)s".
5495 @end table
5498 @node Git,  , P4, Source Checkout
5499 @subsubsection Git
5501 @cindex Git Checkout
5502 @bsindex buildbot.steps.source.Git
5504 The @code{Git} build step clones or updates a @uref{http://git.or.cz/,
5505 Git} repository and checks out the specified branch or revision. Note
5506 that the buildbot supports Git version 1.2.0 and later: earlier
5507 versions (such as the one shipped in Ubuntu 'Dapper') do not support
5508 the @command{git init} command that the buildbot uses.
5510 The Git step takes the following arguments:
5512 @table @code
5513 @item repourl
5514 (required): the URL of the upstream Git repository.
5516 @item branch
5517 (optional): this specifies the name of the branch to use when a Build
5518 does not provide one of its own. If this this parameter is not
5519 specified, and the Build does not provide a branch, the ``master''
5520 branch will be used.
5521 @end table
5524 @node ShellCommand, Simple ShellCommand Subclasses, Source Checkout, Build Steps
5525 @subsection ShellCommand
5527 @bsindex buildbot.steps.shell.ShellCommand
5528 @c TODO @bsindex buildbot.steps.shell.TreeSize
5530 This is a useful base class for just about everything you might want
5531 to do during a build (except for the initial source checkout). It runs
5532 a single command in a child shell on the buildslave. All stdout/stderr
5533 is recorded into a LogFile. The step finishes with a status of FAILURE
5534 if the command's exit code is non-zero, otherwise it has a status of
5535 SUCCESS.
5537 The preferred way to specify the command is with a list of argv strings,
5538 since this allows for spaces in filenames and avoids doing any fragile
5539 shell-escaping. You can also specify the command with a single string, in
5540 which case the string is given to '/bin/sh -c COMMAND' for parsing.
5542 On Windows, commands are run via @code{cmd.exe /c} which works well. However,
5543 if you're running a batch file, the error level does not get propagated
5544 correctly unless you add 'call' before your batch file's name:
5545 @code{cmd=['call', 'myfile.bat', ...]}.
5547 All ShellCommands are run by default in the ``workdir'', which
5548 defaults to the ``@file{build}'' subdirectory of the slave builder's
5549 base directory. The absolute path of the workdir will thus be the
5550 slave's basedir (set as an option to @code{buildbot create-slave},
5551 @pxref{Creating a buildslave}) plus the builder's basedir (set in the
5552 builder's @code{c['builddir']} key in master.cfg) plus the workdir
5553 itself (a class-level attribute of the BuildFactory, defaults to
5554 ``@file{build}'').
5556 @code{ShellCommand} arguments:
5558 @table @code
5559 @item command
5560 a list of strings (preferred) or single string (discouraged) which
5561 specifies the command to be run. A list of strings is preferred
5562 because it can be used directly as an argv array. Using a single
5563 string (with embedded spaces) requires the buildslave to pass the
5564 string to /bin/sh for interpretation, which raises all sorts of
5565 difficult questions about how to escape or interpret shell
5566 metacharacters.
5568 @item env
5569 a dictionary of environment strings which will be added to the child
5570 command's environment. For example, to run tests with a different i18n
5571 language setting, you might use
5573 @example
5574 f.addStep(ShellCommand(command=["make", "test"],
5575                        env=@{'LANG': 'fr_FR'@}))
5576 @end example
5578 These variable settings will override any existing ones in the
5579 buildslave's environment or the environment specified in the
5580 Builder. The exception is PYTHONPATH, which is merged
5581 with (actually prepended to) any existing $PYTHONPATH setting. The
5582 value is treated as a list of directories to prepend, and a single
5583 string is treated like a one-item list. For example, to prepend both
5584 @file{/usr/local/lib/python2.3} and @file{/home/buildbot/lib/python}
5585 to any existing $PYTHONPATH setting, you would do something like the
5586 following:
5588 @example
5589 f.addStep(ShellCommand(
5590               command=["make", "test"],
5591               env=@{'PYTHONPATH': ["/usr/local/lib/python2.3",
5592                                    "/home/buildbot/lib/python"] @}))
5593 @end example
5595 @item want_stdout
5596 if False, stdout from the child process is discarded rather than being
5597 sent to the buildmaster for inclusion in the step's LogFile.
5599 @item want_stderr
5600 like @code{want_stdout} but for stderr. Note that commands run through
5601 a PTY do not have separate stdout/stderr streams: both are merged into
5602 stdout.
5604 @item usePTY
5605 Should this command be run in a @code{pty}?  The default is to observe the
5606 configuration of the client (@pxref{Buildslave Options}), but specifying
5607 @code{True} or @code{False} here will override the default.
5609 The advantage of using a PTY is that ``grandchild'' processes are more likely
5610 to be cleaned up if the build is interrupted or times out (since it enables the
5611 use of a ``process group'' in which all child processes will be placed). The
5612 disadvantages: some forms of Unix have problems with PTYs, some of your unit
5613 tests may behave differently when run under a PTY (generally those which check
5614 to see if they are being run interactively), and PTYs will merge the stdout and
5615 stderr streams into a single output stream (which means the red-vs-black
5616 coloring in the logfiles will be lost).
5618 @item logfiles
5619 Sometimes commands will log interesting data to a local file, rather
5620 than emitting everything to stdout or stderr. For example, Twisted's
5621 ``trial'' command (which runs unit tests) only presents summary
5622 information to stdout, and puts the rest into a file named
5623 @file{_trial_temp/test.log}. It is often useful to watch these files
5624 as the command runs, rather than using @command{/bin/cat} to dump
5625 their contents afterwards.
5627 The @code{logfiles=} argument allows you to collect data from these
5628 secondary logfiles in near-real-time, as the step is running. It
5629 accepts a dictionary which maps from a local Log name (which is how
5630 the log data is presented in the build results) to either a remote filename
5631 (interpreted relative to the build's working directory), or a dictionary
5632 of options. Each named file will be polled on a regular basis (every couple
5633 of seconds) as the build runs, and any new text will be sent over to the
5634 buildmaster.
5636 If you provide a dictionary of options instead of a string, you must specify
5637 the @code{filename} key. You can optionally provide a @code{follow} key which
5638 is a boolean controlling whether a logfile is followed or concatenated in its
5639 entirety.  Following is appropriate for logfiles to which the build step will
5640 append, where the pre-existing contents are not interesting.  The default value
5641 for @code{follow} is @code{False}, which gives the same behavior as just
5642 providing a string filename.
5644 @example
5645 f.addStep(ShellCommand(
5646               command=["make", "test"],
5647               logfiles=@{"triallog": "_trial_temp/test.log"@}))
5648 @end example
5650 @example
5651 f.addStep(ShellCommand(
5652               command=["make", "test"],
5653               logfiles=@{"triallog": @{"filename": "_trial_temp/test.log",
5654                                "follow": True,@}@}))
5655 @end example
5658 @item timeout
5659 if the command fails to produce any output for this many seconds, it
5660 is assumed to be locked up and will be killed.
5662 @item description
5663 This will be used to describe the command (on the Waterfall display)
5664 while the command is still running. It should be a single
5665 imperfect-tense verb, like ``compiling'' or ``testing''. The preferred
5666 form is a list of short strings, which allows the HTML Waterfall
5667 display to create narrower columns by emitting a <br> tag between each
5668 word. You may also provide a single string.
5670 @item descriptionDone
5671 This will be used to describe the command once it has finished. A
5672 simple noun like ``compile'' or ``tests'' should be used. Like
5673 @code{description}, this may either be a list of short strings or a
5674 single string.
5676 If neither @code{description} nor @code{descriptionDone} are set, the
5677 actual command arguments will be used to construct the description.
5678 This may be a bit too wide to fit comfortably on the Waterfall
5679 display.
5681 @example
5682 f.addStep(ShellCommand(command=["make", "test"],
5683                        description=["testing"],
5684                        descriptionDone=["tests"]))
5685 @end example
5687 @item logEnviron
5688 If this option is true (the default), then the step's logfile will describe the
5689 environment variables on the slave.  In situations where the environment is not
5690 relevant and is long, it may be easier to set @code{logEnviron=False}.
5692 @end table
5694 @node Simple ShellCommand Subclasses, Python BuildSteps, ShellCommand, Build Steps
5695 @subsection Simple ShellCommand Subclasses
5697 Several subclasses of ShellCommand are provided as starting points for
5698 common build steps. These are all very simple: they just override a few
5699 parameters so you don't have to specify them yourself, making the master.cfg
5700 file less verbose.
5702 @menu
5703 * Configure::
5704 * Compile::
5705 * Test::
5706 * TreeSize::
5707 * PerlModuleTest::
5708 * SetProperty::
5709 @end menu
5711 @node Configure, Compile, Simple ShellCommand Subclasses, Simple ShellCommand Subclasses
5712 @subsubsection Configure
5714 @bsindex buildbot.steps.shell.Configure
5716 This is intended to handle the @code{./configure} step from
5717 autoconf-style projects, or the @code{perl Makefile.PL} step from perl
5718 MakeMaker.pm-style modules. The default command is @code{./configure}
5719 but you can change this by providing a @code{command=} parameter.
5721 @node Compile, Test, Configure, Simple ShellCommand Subclasses
5722 @subsubsection Compile
5724 @bsindex buildbot.steps.shell.Compile
5726 This is meant to handle compiling or building a project written in C.
5727 The default command is @code{make all}. When the compile is finished,
5728 the log file is scanned for GCC warning messages, a summary log is
5729 created with any problems that were seen, and the step is marked as
5730 WARNINGS if any were discovered. The number of warnings is stored in a
5731 Build Property named ``warnings-count'', which is accumulated over all
5732 Compile steps (so if two warnings are found in one step, and three are
5733 found in another step, the overall build will have a
5734 ``warnings-count'' property of 5.
5736 The default regular expression used to detect a warning is
5737 @code{'.*warning[: ].*'} , which is fairly liberal and may cause
5738 false-positives. To use a different regexp, provide a
5739 @code{warningPattern=} argument, or use a subclass which sets the
5740 @code{warningPattern} attribute:
5742 @example
5743 f.addStep(Compile(command=["make", "test"],
5744                   warningPattern="^Warning: "))
5745 @end example
5747 The @code{warningPattern=} can also be a pre-compiled python regexp
5748 object: this makes it possible to add flags like @code{re.I} (to use
5749 case-insensitive matching).
5751 (TODO: this step needs to be extended to look for GCC error messages
5752 as well, and collect them into a separate logfile, along with the
5753 source code filenames involved).
5756 @node Test, TreeSize, Compile, Simple ShellCommand Subclasses
5757 @subsubsection Test
5759 @bsindex buildbot.steps.shell.Test
5761 This is meant to handle unit tests. The default command is @code{make
5762 test}, and the @code{warnOnFailure} flag is set.
5764 @node TreeSize, PerlModuleTest, Test, Simple ShellCommand Subclasses
5765 @subsubsection TreeSize
5767 @bsindex buildbot.steps.shell.TreeSize
5769 This is a simple command that uses the 'du' tool to measure the size
5770 of the code tree. It puts the size (as a count of 1024-byte blocks,
5771 aka 'KiB' or 'kibibytes') on the step's status text, and sets a build
5772 property named 'tree-size-KiB' with the same value.
5774 @node PerlModuleTest, SetProperty, TreeSize, Simple ShellCommand Subclasses
5775 @subsubsection PerlModuleTest
5777 @bsindex buildbot.steps.shell.PerlModuleTest
5779 This is a simple command that knows how to run tests of perl modules.
5780 It parses the output to determine the number of tests passed and
5781 failed and total number executed, saving the results for later query.
5783 @node SetProperty,  , PerlModuleTest, Simple ShellCommand Subclasses
5784 @subsubsection SetProperty
5786 @bsindex buildbot.steps.shell.SetProperty
5788 This buildstep is similar to ShellCommand, except that it captures the
5789 output of the command into a property.  It is usually used like this:
5791 @example
5792 f.addStep(SetProperty(command="uname -a", property="uname"))
5793 @end example
5795 This runs @code{uname -a} and captures its stdout, stripped of leading
5796 and trailing whitespace, in the property "uname".  To avoid stripping,
5797 add @code{strip=False}.  The @code{property} argument can be specified
5798 as a @code{WithProperties} object.
5800 The more advanced usage allows you to specify a function to extract
5801 properties from the command output.  Here you can use regular
5802 expressions, string interpolation, or whatever you would like.
5803 The function is called with three arguments: the exit status of the
5804 command, its standard output as a string, and its standard error as
5805 a string.  It should return a dictionary containing all new properties.
5807 @example
5808 def glob2list(rc, stdout, stderr):
5809     jpgs = [ l.strip() for l in stdout.split('\n') ]
5810     return @{ 'jpgs' : jpgs @}
5811 f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
5812 @end example
5814 Note that any ordering relationship of the contents of stdout and
5815 stderr is lost.  For example, given
5817 @example
5818 f.addStep(SetProperty(
5819     command="echo output1; echo error >&2; echo output2",
5820     extract_fn=my_extract))
5821 @end example
5823 Then @code{my_extract} will see @code{stdout="output1\noutput2\n"}
5824 and @code{stderr="error\n"}.
5826 @node Python BuildSteps, Transferring Files, Simple ShellCommand Subclasses, Build Steps
5827 @subsection Python BuildSteps
5829 Here are some BuildSteps that are specifcally useful for projects
5830 implemented in Python.
5832 @menu
5833 * BuildEPYDoc::
5834 * PyFlakes::
5835 * PyLint::
5836 @end menu
5838 @node BuildEPYDoc
5839 @subsubsection BuildEPYDoc
5841 @bsindex buildbot.steps.python.BuildEPYDoc
5843 @url{http://epydoc.sourceforge.net/, epydoc} is a tool for generating
5844 API documentation for Python modules from their docstrings. It reads
5845 all the .py files from your source tree, processes the docstrings
5846 therein, and creates a large tree of .html files (or a single .pdf
5847 file).
5849 The @code{buildbot.steps.python.BuildEPYDoc} step will run
5850 @command{epydoc} to produce this API documentation, and will count the
5851 errors and warnings from its output.
5853 You must supply the command line to be used. The default is
5854 @command{make epydocs}, which assumes that your project has a Makefile
5855 with an ``epydocs'' target. You might wish to use something like
5856 @command{epydoc -o apiref source/PKGNAME} instead. You might also want
5857 to add @command{--pdf} to generate a PDF file instead of a large tree
5858 of HTML files.
5860 The API docs are generated in-place in the build tree (under the
5861 workdir, in the subdirectory controlled by the ``-o'' argument). To
5862 make them useful, you will probably have to copy them to somewhere
5863 they can be read. A command like @command{rsync -ad apiref/
5864 dev.example.com:~public_html/current-apiref/} might be useful. You
5865 might instead want to bundle them into a tarball and publish it in the
5866 same place where the generated install tarball is placed.
5868 @example
5869 from buildbot.steps.python import BuildEPYDoc
5872 f.addStep(BuildEPYDoc(command=["epydoc", "-o", "apiref", "source/mypkg"]))
5873 @end example
5876 @node PyFlakes
5877 @subsubsection PyFlakes
5879 @bsindex buildbot.steps.python.PyFlakes
5881 @url{http://divmod.org/trac/wiki/DivmodPyflakes, PyFlakes} is a tool
5882 to perform basic static analysis of Python code to look for simple
5883 errors, like missing imports and references of undefined names. It is
5884 like a fast and simple form of the C ``lint'' program. Other tools
5885 (like pychecker) provide more detailed results but take longer to run.
5887 The @code{buildbot.steps.python.PyFlakes} step will run pyflakes and
5888 count the various kinds of errors and warnings it detects.
5890 You must supply the command line to be used. The default is
5891 @command{make pyflakes}, which assumes you have a top-level Makefile
5892 with a ``pyflakes'' target. You might want to use something like
5893 @command{pyflakes .} or @command{pyflakes src}.
5895 @example
5896 from buildbot.steps.python import PyFlakes
5899 f.addStep(PyFlakes(command=["pyflakes", "src"]))
5900 @end example
5902 @node PyLint
5903 @subsubsection PyLint
5905 @bsindex buildbot.steps.python.PyLint
5907 Similarly, the @code{buildbot.steps.python.PyLint} step will run pylint and
5908 analyze the results.
5910 You must supply the command line to be used. There is no default.
5912 @example
5913 from buildbot.steps.python import PyLint
5916 f.addStep(PyLint(command=["pylint", "src"]))
5917 @end example
5920 @node Transferring Files
5921 @subsection Transferring Files
5923 @cindex File Transfer
5924 @bsindex buildbot.steps.transfer.FileUpload
5925 @bsindex buildbot.steps.transfer.FileDownload
5926 @bsindex buildbot.steps.transfer.DirectoryUpload
5928 Most of the work involved in a build will take place on the
5929 buildslave. But occasionally it is useful to do some work on the
5930 buildmaster side. The most basic way to involve the buildmaster is
5931 simply to move a file from the slave to the master, or vice versa.
5932 There are a pair of BuildSteps named @code{FileUpload} and
5933 @code{FileDownload} to provide this functionality. @code{FileUpload}
5934 moves a file @emph{up to} the master, while @code{FileDownload} moves
5935 a file @emph{down from} the master.
5937 As an example, let's assume that there is a step which produces an
5938 HTML file within the source tree that contains some sort of generated
5939 project documentation. We want to move this file to the buildmaster,
5940 into a @file{~/public_html} directory, so it can be visible to
5941 developers. This file will wind up in the slave-side working directory
5942 under the name @file{docs/reference.html}. We want to put it into the
5943 master-side @file{~/public_html/ref.html}.
5945 @example
5946 from buildbot.steps.shell import ShellCommand
5947 from buildbot.steps.transfer import FileUpload
5949 f.addStep(ShellCommand(command=["make", "docs"]))
5950 f.addStep(FileUpload(slavesrc="docs/reference.html",
5951                      masterdest="~/public_html/ref.html"))
5952 @end example
5954 The @code{masterdest=} argument will be passed to os.path.expanduser,
5955 so things like ``~'' will be expanded properly. Non-absolute paths
5956 will be interpreted relative to the buildmaster's base directory.
5957 Likewise, the @code{slavesrc=} argument will be expanded and
5958 interpreted relative to the builder's working directory.
5961 To move a file from the master to the slave, use the
5962 @code{FileDownload} command. For example, let's assume that some step
5963 requires a configuration file that, for whatever reason, could not be
5964 recorded in the source code repository or generated on the buildslave
5965 side:
5967 @example
5968 from buildbot.steps.shell import ShellCommand
5969 from buildbot.steps.transfer import FileDownload
5971 f.addStep(FileDownload(mastersrc="~/todays_build_config.txt",
5972                        slavedest="build_config.txt"))
5973 f.addStep(ShellCommand(command=["make", "config"]))
5974 @end example
5976 Like @code{FileUpload}, the @code{mastersrc=} argument is interpreted
5977 relative to the buildmaster's base directory, and the
5978 @code{slavedest=} argument is relative to the builder's working
5979 directory. If the buildslave is running in @file{~buildslave}, and the
5980 builder's ``builddir'' is something like @file{tests-i386}, then the
5981 workdir is going to be @file{~buildslave/tests-i386/build}, and a
5982 @code{slavedest=} of @file{foo/bar.html} will get put in
5983 @file{~buildslave/tests-i386/build/foo/bar.html}. Both of these commands
5984 will create any missing intervening directories.
5986 @subheading Other Parameters
5988 The @code{maxsize=} argument lets you set a maximum size for the file
5989 to be transferred. This may help to avoid surprises: transferring a
5990 100MB coredump when you were expecting to move a 10kB status file
5991 might take an awfully long time. The @code{blocksize=} argument
5992 controls how the file is sent over the network: larger blocksizes are
5993 slightly more efficient but also consume more memory on each end, and
5994 there is a hard-coded limit of about 640kB.
5996 The @code{mode=} argument allows you to control the access permissions
5997 of the target file, traditionally expressed as an octal integer. The
5998 most common value is probably 0755, which sets the ``x'' executable
5999 bit on the file (useful for shell scripts and the like). The default
6000 value for @code{mode=} is None, which means the permission bits will
6001 default to whatever the umask of the writing process is. The default
6002 umask tends to be fairly restrictive, but at least on the buildslave
6003 you can make it less restrictive with a --umask command-line option at
6004 creation time (@pxref{Buildslave Options}).
6006 @subheading Transfering Directories
6008 To transfer complete directories from the buildslave to the master, there
6009 is a BuildStep named @code{DirectoryUpload}. It works like @code{FileUpload},
6010 just for directories. However it does not support the @code{maxsize},
6011 @code{blocksize} and @code{mode} arguments. As an example, let's assume an
6012 generated project documentation, which consists of many files (like the output
6013 of doxygen or epydoc). We want to move the entire documentation to the
6014 buildmaster, into a @code{~/public_html/docs} directory. On the slave-side
6015 the directory can be found under @code{docs}:
6017 @example
6018 from buildbot.steps.shell import ShellCommand
6019 from buildbot.steps.transfer import DirectoryUpload
6021 f.addStep(ShellCommand(command=["make", "docs"]))
6022 f.addStep(DirectoryUpload(slavesrc="docs",
6023                                 masterdest="~/public_html/docs"))
6024 @end example
6026 The DirectoryUpload step will create all necessary directories and
6027 transfers empty directories, too.
6029 @node Steps That Run on the Master
6030 @subsection Steps That Run on the Master
6032 Occasionally, it is useful to execute some task on the master, for example to
6033 create a directory, deploy a build result, or trigger some other centralized
6034 processing.  This is possible, in a limited fashion, with the
6035 @code{MasterShellCommand} step.
6037 This step operates similarly to a regular @code{ShellCommand}, but executes on
6038 the master, instead of the slave.  To be clear, the enclosing @code{Build}
6039 object must still have a slave object, just as for any other step -- only, in
6040 this step, the slave does not do anything.
6042 In this example, the step renames a tarball based on the day of the week.
6044 @example
6045 from buildbot.steps.transfer import FileUpload
6046 from buildbot.steps.master import MasterShellCommand
6048 f.addStep(FileUpload(slavesrc="widgetsoft.tar.gz",
6049                      masterdest="/var/buildoutputs/widgetsoft-new.tar.gz"))
6050 f.addStep(MasterShellCommand(command="""
6051     cd /var/buildoutputs;
6052     mv widgetsoft-new.tar.gz widgetsoft-`date +%a`.tar.gz"""))
6053 @end example
6055 @node Triggering Schedulers
6056 @subsection Triggering Schedulers
6058 The counterpart to the Triggerable described in section
6059 @pxref{Triggerable Scheduler} is the Trigger BuildStep.
6061 @example
6062 from buildbot.steps.trigger import Trigger
6063 f.addStep(Trigger(schedulerNames=['build-prep'],
6064                   waitForFinish=True,
6065                   updateSourceStamp=True,
6066                   set_properties=@{ 'quick' : False @},
6067                   copy_properties=[ 'release_code_name' ]))
6068 @end example
6070 The @code{schedulerNames=} argument lists the Triggerables
6071 that should be triggered when this step is executed.  Note that
6072 it is possible, but not advisable, to create a cycle where a build
6073 continually triggers itself, because the schedulers are specified
6074 by name.
6076 If @code{waitForFinish} is True, then the step will not finish until
6077 all of the builds from the triggered schedulers have finished. If this
6078 argument is False (the default) or not given, then the buildstep
6079 succeeds immediately after triggering the schedulers.
6081 If @code{updateSourceStamp} is True (the default), then step updates
6082 the SourceStamp given to the Triggerables to include
6083 @code{got_revision} (the revision actually used in this build) as
6084 @code{revision} (the revision to use in the triggered builds). This is
6085 useful to ensure that all of the builds use exactly the same
6086 SourceStamp, even if other Changes have occurred while the build was
6087 running.
6089 Two parameters allow control of the properties that are passed to the triggered
6090 scheduler.  To simply copy properties verbatim, list them in the
6091 @code{copy_properties} parameter.  To set properties explicitly, use the more
6092 sophisticated @code{set_properties}, which takes a dictionary mapping property
6093 names to values.  You may use @code{WithProperties} here to dynamically
6094 construct new property values.
6096 @node Writing New BuildSteps
6097 @subsection Writing New BuildSteps
6099 While it is a good idea to keep your build process self-contained in
6100 the source code tree, sometimes it is convenient to put more
6101 intelligence into your Buildbot configuration. One way to do this is
6102 to write a custom BuildStep. Once written, this Step can be used in
6103 the @file{master.cfg} file.
6105 The best reason for writing a custom BuildStep is to better parse the
6106 results of the command being run. For example, a BuildStep that knows
6107 about JUnit could look at the logfiles to determine which tests had
6108 been run, how many passed and how many failed, and then report more
6109 detailed information than a simple @code{rc==0} -based ``good/bad''
6110 decision.
6112 @menu
6113 * Writing BuildStep Constructors::
6114 * BuildStep LogFiles::
6115 * Reading Logfiles::
6116 * Adding LogObservers::
6117 * BuildStep URLs::
6118 @end menu
6120 @node Writing BuildStep Constructors
6121 @subsubsection Writing BuildStep Constructors
6123 BuildStep classes have some extra equipment, because they are their own
6124 factories.  Consider the use of a BuildStep in @file{master.cfg}:
6126 @example
6127 f.addStep(MyStep(someopt="stuff", anotheropt=1))
6128 @end example
6130 This creates a single instance of class @code{MyStep}.  However, Buildbot needs
6131 a new object each time the step is executed.  this is accomplished by storing
6132 the information required to instantiate a new object in the @code{factory}
6133 attribute.  When the time comes to construct a new Build, BuildFactory consults
6134 this attribute (via @code{getStepFactory}) and instantiates a new step object.
6136 When writing a new step class, then, keep in mind are that you cannot do
6137 anything "interesting" in the constructor -- limit yourself to checking and
6138 storing arguments.  To ensure that these arguments are provided to any new
6139 objects, call @code{self.addFactoryArguments} with any keyword arguments your
6140 constructor needs.
6142 Keep a @code{**kwargs} argument on the end of your options, and pass that up to
6143 the parent class's constructor.
6145 The whole thing looks like this:
6147 @example
6148 class Frobinfy(LoggingBuildStep):
6149     def __init__(self,
6150             frob_what="frobee",
6151             frob_how_many=None,
6152             frob_how=None,
6153             **kwargs)
6155         # check
6156         if frob_how_many is None:
6157             raise TypeError("Frobinfy argument how_many is required")
6159         # call parent
6160         LoggingBuildStep.__init__(self, **kwargs)
6162         # and record arguments for later
6163         self.addFactoryArguments(
6164             frob_what=frob_what,
6165             frob_how_many=frob_how_many,
6166             frob_how=frob_how)
6168 class FastFrobnify(Frobnify):
6169     def __init__(self,
6170             speed=5,
6171             **kwargs)
6172         Frobnify.__init__(self, **kwargs)
6173         self.addFactoryArguments(
6174             speed=speed)
6175 @end example
6177 @node BuildStep LogFiles
6178 @subsubsection BuildStep LogFiles
6180 Each BuildStep has a collection of ``logfiles''. Each one has a short
6181 name, like ``stdio'' or ``warnings''. Each LogFile contains an
6182 arbitrary amount of text, usually the contents of some output file
6183 generated during a build or test step, or a record of everything that
6184 was printed to stdout/stderr during the execution of some command.
6186 These LogFiles are stored to disk, so they can be retrieved later.
6188 Each can contain multiple ``channels'', generally limited to three
6189 basic ones: stdout, stderr, and ``headers''. For example, when a
6190 ShellCommand runs, it writes a few lines to the ``headers'' channel to
6191 indicate the exact argv strings being run, which directory the command
6192 is being executed in, and the contents of the current environment
6193 variables. Then, as the command runs, it adds a lot of ``stdout'' and
6194 ``stderr'' messages. When the command finishes, a final ``header''
6195 line is added with the exit code of the process.
6197 Status display plugins can format these different channels in
6198 different ways. For example, the web page shows LogFiles as text/html,
6199 with header lines in blue text, stdout in black, and stderr in red. A
6200 different URL is available which provides a text/plain format, in
6201 which stdout and stderr are collapsed together, and header lines are
6202 stripped completely. This latter option makes it easy to save the
6203 results to a file and run @command{grep} or whatever against the
6204 output.
6206 Each BuildStep contains a mapping (implemented in a python dictionary)
6207 from LogFile name to the actual LogFile objects. Status plugins can
6208 get a list of LogFiles to display, for example, a list of HREF links
6209 that, when clicked, provide the full contents of the LogFile.
6211 @heading Using LogFiles in custom BuildSteps
6213 The most common way for a custom BuildStep to use a LogFile is to
6214 summarize the results of a ShellCommand (after the command has
6215 finished running). For example, a compile step with thousands of lines
6216 of output might want to create a summary of just the warning messages.
6217 If you were doing this from a shell, you would use something like:
6219 @example
6220 grep "warning:" output.log >warnings.log
6221 @end example
6223 In a custom BuildStep, you could instead create a ``warnings'' LogFile
6224 that contained the same text. To do this, you would add code to your
6225 @code{createSummary} method that pulls lines from the main output log
6226 and creates a new LogFile with the results:
6228 @example
6229     def createSummary(self, log):
6230         warnings = []
6231         for line in log.readlines():
6232             if "warning:" in line:
6233                 warnings.append()
6234         self.addCompleteLog('warnings', "".join(warnings))
6235 @end example
6237 This example uses the @code{addCompleteLog} method, which creates a
6238 new LogFile, puts some text in it, and then ``closes'' it, meaning
6239 that no further contents will be added. This LogFile will appear in
6240 the HTML display under an HREF with the name ``warnings'', since that
6241 is the name of the LogFile.
6243 You can also use @code{addHTMLLog} to create a complete (closed)
6244 LogFile that contains HTML instead of plain text. The normal LogFile
6245 will be HTML-escaped if presented through a web page, but the HTML
6246 LogFile will not. At the moment this is only used to present a pretty
6247 HTML representation of an otherwise ugly exception traceback when
6248 something goes badly wrong during the BuildStep.
6250 In contrast, you might want to create a new LogFile at the beginning
6251 of the step, and add text to it as the command runs. You can create
6252 the LogFile and attach it to the build by calling @code{addLog}, which
6253 returns the LogFile object. You then add text to this LogFile by
6254 calling methods like @code{addStdout} and @code{addHeader}. When you
6255 are done, you must call the @code{finish} method so the LogFile can be
6256 closed. It may be useful to create and populate a LogFile like this
6257 from a LogObserver method @xref{Adding LogObservers}.
6259 The @code{logfiles=} argument to @code{ShellCommand} (see
6260 @pxref{ShellCommand}) creates new LogFiles and fills them in realtime
6261 by asking the buildslave to watch a actual file on disk. The
6262 buildslave will look for additions in the target file and report them
6263 back to the BuildStep. These additions will be added to the LogFile by
6264 calling @code{addStdout}. These secondary LogFiles can be used as the
6265 source of a LogObserver just like the normal ``stdio'' LogFile.
6267 @node Reading Logfiles
6268 @subsubsection Reading Logfiles
6270 Once a LogFile has been added to a BuildStep with @code{addLog()},
6271 @code{addCompleteLog()}, @code{addHTMLLog()}, or @code{logfiles=},
6272 your BuildStep can retrieve it by using @code{getLog()}:
6274 @example
6275 class MyBuildStep(ShellCommand):
6276     logfiles = @{ "nodelog": "_test/node.log" @}
6278     def evaluateCommand(self, cmd):
6279         nodelog = self.getLog("nodelog")
6280         if "STARTED" in nodelog.getText():
6281             return SUCCESS
6282         else:
6283             return FAILURE
6284 @end example
6286 For a complete list of the methods you can call on a LogFile, please
6287 see the docstrings on the @code{IStatusLog} class in
6288 @file{buildbot/interfaces.py}.
6291 @node Adding LogObservers, BuildStep URLs, Reading Logfiles, Writing New BuildSteps
6292 @subsubsection Adding LogObservers
6294 @cindex LogObserver
6295 @cindex LogLineObserver
6297 Most shell commands emit messages to stdout or stderr as they operate,
6298 especially if you ask them nicely with a @code{--verbose} flag of some
6299 sort. They may also write text to a log file while they run. Your
6300 BuildStep can watch this output as it arrives, to keep track of how
6301 much progress the command has made. You can get a better measure of
6302 progress by counting the number of source files compiled or test cases
6303 run than by merely tracking the number of bytes that have been written
6304 to stdout. This improves the accuracy and the smoothness of the ETA
6305 display.
6307 To accomplish this, you will need to attach a @code{LogObserver} to
6308 one of the log channels, most commonly to the ``stdio'' channel but
6309 perhaps to another one which tracks a log file. This observer is given
6310 all text as it is emitted from the command, and has the opportunity to
6311 parse that output incrementally. Once the observer has decided that
6312 some event has occurred (like a source file being compiled), it can
6313 use the @code{setProgress} method to tell the BuildStep about the
6314 progress that this event represents.
6316 There are a number of pre-built @code{LogObserver} classes that you
6317 can choose from (defined in @code{buildbot.process.buildstep}, and of
6318 course you can subclass them to add further customization. The
6319 @code{LogLineObserver} class handles the grunt work of buffering and
6320 scanning for end-of-line delimiters, allowing your parser to operate
6321 on complete stdout/stderr lines. (Lines longer than a set maximum
6322 length are dropped; the maximum defaults to 16384 bytes, but you can
6323 change it by calling @code{setMaxLineLength()} on your
6324 @code{LogLineObserver} instance.  Use @code{sys.maxint} for effective
6325 infinity.)
6327 For example, let's take a look at the @code{TrialTestCaseCounter},
6328 which is used by the Trial step to count test cases as they are run.
6329 As Trial executes, it emits lines like the following:
6331 @example
6332 buildbot.test.test_config.ConfigTest.testDebugPassword ... [OK]
6333 buildbot.test.test_config.ConfigTest.testEmpty ... [OK]
6334 buildbot.test.test_config.ConfigTest.testIRC ... [FAIL]
6335 buildbot.test.test_config.ConfigTest.testLocks ... [OK]
6336 @end example
6338 When the tests are finished, trial emits a long line of ``======'' and
6339 then some lines which summarize the tests that failed. We want to
6340 avoid parsing these trailing lines, because their format is less
6341 well-defined than the ``[OK]'' lines.
6343 The parser class looks like this:
6345 @example
6346 from buildbot.process.buildstep import LogLineObserver
6348 class TrialTestCaseCounter(LogLineObserver):
6349     _line_re = re.compile(r'^([\w\.]+) \.\.\. \[([^\]]+)\]$')
6350     numTests = 0
6351     finished = False
6353     def outLineReceived(self, line):
6354         if self.finished:
6355             return
6356         if line.startswith("=" * 40):
6357             self.finished = True
6358             return
6360         m = self._line_re.search(line.strip())
6361         if m:
6362             testname, result = m.groups()
6363             self.numTests += 1
6364             self.step.setProgress('tests', self.numTests)
6365 @end example
6367 This parser only pays attention to stdout, since that's where trial
6368 writes the progress lines. It has a mode flag named @code{finished} to
6369 ignore everything after the ``===='' marker, and a scary-looking
6370 regular expression to match each line while hopefully ignoring other
6371 messages that might get displayed as the test runs.
6373 Each time it identifies a test has been completed, it increments its
6374 counter and delivers the new progress value to the step with
6375 @code{self.step.setProgress}. This class is specifically measuring
6376 progress along the ``tests'' metric, in units of test cases (as
6377 opposed to other kinds of progress like the ``output'' metric, which
6378 measures in units of bytes). The Progress-tracking code uses each
6379 progress metric separately to come up with an overall completion
6380 percentage and an ETA value.
6382 To connect this parser into the @code{Trial} BuildStep,
6383 @code{Trial.__init__} ends with the following clause:
6385 @example
6386         # this counter will feed Progress along the 'test cases' metric
6387         counter = TrialTestCaseCounter()
6388         self.addLogObserver('stdio', counter)
6389         self.progressMetrics += ('tests',)
6390 @end example
6392 This creates a TrialTestCaseCounter and tells the step that the
6393 counter wants to watch the ``stdio'' log. The observer is
6394 automatically given a reference to the step in its @code{.step}
6395 attribute.
6397 @subheading A Somewhat Whimsical Example
6399 Let's say that we've got some snazzy new unit-test framework called
6400 Framboozle. It's the hottest thing since sliced bread. It slices, it
6401 dices, it runs unit tests like there's no tomorrow. Plus if your unit
6402 tests fail, you can use its name for a Web 2.1 startup company, make
6403 millions of dollars, and hire engineers to fix the bugs for you, while
6404 you spend your afternoons lazily hang-gliding along a scenic pacific
6405 beach, blissfully unconcerned about the state of your
6406 tests.@footnote{framboozle.com is still available. Remember, I get 10%
6407 :).}
6409 To run a Framboozle-enabled test suite, you just run the 'framboozler'
6410 command from the top of your source code tree. The 'framboozler'
6411 command emits a bunch of stuff to stdout, but the most interesting bit
6412 is that it emits the line "FNURRRGH!" every time it finishes running a
6413 test case@footnote{Framboozle gets very excited about running unit
6414 tests.}. You'd like to have a test-case counting LogObserver that
6415 watches for these lines and counts them, because counting them will
6416 help the buildbot more accurately calculate how long the build will
6417 take, and this will let you know exactly how long you can sneak out of
6418 the office for your hang-gliding lessons without anyone noticing that
6419 you're gone.
6421 This will involve writing a new BuildStep (probably named
6422 "Framboozle") which inherits from ShellCommand. The BuildStep class
6423 definition itself will look something like this:
6425 @example
6426 # START
6427 from buildbot.steps.shell import ShellCommand
6428 from buildbot.process.buildstep import LogLineObserver
6430 class FNURRRGHCounter(LogLineObserver):
6431     numTests = 0
6432     def outLineReceived(self, line):
6433         if "FNURRRGH!" in line:
6434             self.numTests += 1
6435             self.step.setProgress('tests', self.numTests)
6437 class Framboozle(ShellCommand):
6438     command = ["framboozler"]
6440     def __init__(self, **kwargs):
6441         ShellCommand.__init__(self, **kwargs)   # always upcall!
6442         counter = FNURRRGHCounter())
6443         self.addLogObserver('stdio', counter)
6444         self.progressMetrics += ('tests',)
6445 # FINISH
6446 @end example
6448 So that's the code that we want to wind up using. How do we actually
6449 deploy it?
6451 You have a couple of different options.
6453 Option 1: The simplest technique is to simply put this text
6454 (everything from START to FINISH) in your master.cfg file, somewhere
6455 before the BuildFactory definition where you actually use it in a
6456 clause like:
6458 @example
6459 f = BuildFactory()
6460 f.addStep(SVN(svnurl="stuff"))
6461 f.addStep(Framboozle())
6462 @end example
6464 Remember that master.cfg is secretly just a python program with one
6465 job: populating the BuildmasterConfig dictionary. And python programs
6466 are allowed to define as many classes as they like. So you can define
6467 classes and use them in the same file, just as long as the class is
6468 defined before some other code tries to use it.
6470 This is easy, and it keeps the point of definition very close to the
6471 point of use, and whoever replaces you after that unfortunate
6472 hang-gliding accident will appreciate being able to easily figure out
6473 what the heck this stupid "Framboozle" step is doing anyways. The
6474 downside is that every time you reload the config file, the Framboozle
6475 class will get redefined, which means that the buildmaster will think
6476 that you've reconfigured all the Builders that use it, even though
6477 nothing changed. Bleh.
6479 Option 2: Instead, we can put this code in a separate file, and import
6480 it into the master.cfg file just like we would the normal buildsteps
6481 like ShellCommand and SVN.
6483 Create a directory named ~/lib/python, put everything from START to
6484 FINISH in ~/lib/python/framboozle.py, and run your buildmaster using:
6486 @example
6487  PYTHONPATH=~/lib/python buildbot start MASTERDIR
6488 @end example
6490 or use the @file{Makefile.buildbot} to control the way
6491 @command{buildbot start} works. Or add something like this to
6492 something like your ~/.bashrc or ~/.bash_profile or ~/.cshrc:
6494 @example
6495  export PYTHONPATH=~/lib/python
6496 @end example
6498 Once we've done this, our master.cfg can look like:
6500 @example
6501 from framboozle import Framboozle
6502 f = BuildFactory()
6503 f.addStep(SVN(svnurl="stuff"))
6504 f.addStep(Framboozle())
6505 @end example
6509 @example
6510 import framboozle
6511 f = BuildFactory()
6512 f.addStep(SVN(svnurl="stuff"))
6513 f.addStep(framboozle.Framboozle())
6514 @end example
6516 (check out the python docs for details about how "import" and "from A
6517 import B" work).
6519 What we've done here is to tell python that every time it handles an
6520 "import" statement for some named module, it should look in our
6521 ~/lib/python/ for that module before it looks anywhere else. After our
6522 directories, it will try in a bunch of standard directories too
6523 (including the one where buildbot is installed). By setting the
6524 PYTHONPATH environment variable, you can add directories to the front
6525 of this search list.
6527 Python knows that once it "import"s a file, it doesn't need to
6528 re-import it again. This means that reconfiguring the buildmaster
6529 (with "buildbot reconfig", for example) won't make it think the
6530 Framboozle class has changed every time, so the Builders that use it
6531 will not be spuriously restarted. On the other hand, you either have
6532 to start your buildmaster in a slightly weird way, or you have to
6533 modify your environment to set the PYTHONPATH variable.
6536 Option 3: Install this code into a standard python library directory
6538 Find out what your python's standard include path is by asking it:
6540 @example
6541 80:warner@@luther% python
6542 Python 2.4.4c0 (#2, Oct  2 2006, 00:57:46)
6543 [GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
6544 Type "help", "copyright", "credits" or "license" for more information.
6545 >>> import sys
6546 >>> import pprint
6547 >>> pprint.pprint(sys.path)
6548 ['',
6549  '/usr/lib/python24.zip',
6550  '/usr/lib/python2.4',
6551  '/usr/lib/python2.4/plat-linux2',
6552  '/usr/lib/python2.4/lib-tk',
6553  '/usr/lib/python2.4/lib-dynload',
6554  '/usr/local/lib/python2.4/site-packages',
6555  '/usr/lib/python2.4/site-packages',
6556  '/usr/lib/python2.4/site-packages/Numeric',
6557  '/var/lib/python-support/python2.4',
6558  '/usr/lib/site-python']
6559 @end example
6561 In this case, putting the code into
6562 /usr/local/lib/python2.4/site-packages/framboozle.py would work just
6563 fine. We can use the same master.cfg "import framboozle" statement as
6564 in Option 2. By putting it in a standard include directory (instead of
6565 the decidedly non-standard ~/lib/python), we don't even have to set
6566 PYTHONPATH to anything special. The downside is that you probably have
6567 to be root to write to one of those standard include directories.
6570 Option 4: Submit the code for inclusion in the Buildbot distribution
6572 Make a fork of buildbot on http://github.com/djmitche/buildbot or post a patch
6573 in a bug at http://buildbot.net.  In either case, post a note about your patch
6574 to the mailing list, so others can provide feedback and, eventually, commit it.
6576 @example
6577 from buildbot.steps import framboozle
6578 f = BuildFactory()
6579 f.addStep(SVN(svnurl="stuff"))
6580 f.addStep(framboozle.Framboozle())
6581 @end example
6583 And then you don't even have to install framboozle.py anywhere on your
6584 system, since it will ship with Buildbot. You don't have to be root,
6585 you don't have to set PYTHONPATH. But you do have to make a good case
6586 for Framboozle being worth going into the main distribution, you'll
6587 probably have to provide docs and some unit test cases, you'll need to
6588 figure out what kind of beer the author likes, and then you'll have to
6589 wait until the next release. But in some environments, all this is
6590 easier than getting root on your buildmaster box, so the tradeoffs may
6591 actually be worth it.
6595 Putting the code in master.cfg (1) makes it available to that
6596 buildmaster instance. Putting it in a file in a personal library
6597 directory (2) makes it available for any buildmasters you might be
6598 running. Putting it in a file in a system-wide shared library
6599 directory (3) makes it available for any buildmasters that anyone on
6600 that system might be running. Getting it into the buildbot's upstream
6601 repository (4) makes it available for any buildmasters that anyone in
6602 the world might be running. It's all a matter of how widely you want
6603 to deploy that new class.
6607 @node BuildStep URLs,  , Adding LogObservers, Writing New BuildSteps
6608 @subsubsection BuildStep URLs
6610 @cindex links
6611 @cindex BuildStep URLs
6612 @cindex addURL
6614 Each BuildStep has a collection of ``links''. Like its collection of
6615 LogFiles, each link has a name and a target URL. The web status page
6616 creates HREFs for each link in the same box as it does for LogFiles,
6617 except that the target of the link is the external URL instead of an
6618 internal link to a page that shows the contents of the LogFile.
6620 These external links can be used to point at build information hosted
6621 on other servers. For example, the test process might produce an
6622 intricate description of which tests passed and failed, or some sort
6623 of code coverage data in HTML form, or a PNG or GIF image with a graph
6624 of memory usage over time. The external link can provide an easy way
6625 for users to navigate from the buildbot's status page to these
6626 external web sites or file servers. Note that the step itself is
6627 responsible for insuring that there will be a document available at
6628 the given URL (perhaps by using @command{scp} to copy the HTML output
6629 to a @file{~/public_html/} directory on a remote web server). Calling
6630 @code{addURL} does not magically populate a web server.
6632 To set one of these links, the BuildStep should call the @code{addURL}
6633 method with the name of the link and the target URL. Multiple URLs can
6634 be set.
6636 In this example, we assume that the @command{make test} command causes
6637 a collection of HTML files to be created and put somewhere on the
6638 coverage.example.org web server, in a filename that incorporates the
6639 build number.
6641 @example
6642 class TestWithCodeCoverage(BuildStep):
6643     command = ["make", "test",
6644                WithProperties("buildnum=%s" % "buildnumber")]
6646     def createSummary(self, log):
6647         buildnumber = self.getProperty("buildnumber")
6648         url = "http://coverage.example.org/builds/%s.html" % buildnumber
6649         self.addURL("coverage", url)
6650 @end example
6652 You might also want to extract the URL from some special message
6653 output by the build process itself:
6655 @example
6656 class TestWithCodeCoverage(BuildStep):
6657     command = ["make", "test",
6658                WithProperties("buildnum=%s" % "buildnumber")]
6660     def createSummary(self, log):
6661         output = StringIO(log.getText())
6662         for line in output.readlines():
6663             if line.startswith("coverage-url:"):
6664                 url = line[len("coverage-url:"):].strip()
6665                 self.addURL("coverage", url)
6666                 return
6667 @end example
6669 Note that a build process which emits both stdout and stderr might
6670 cause this line to be split or interleaved between other lines. It
6671 might be necessary to restrict the getText() call to only stdout with
6672 something like this:
6674 @example
6675         output = StringIO("".join([c[1]
6676                                    for c in log.getChunks()
6677                                    if c[0] == LOG_CHANNEL_STDOUT]))
6678 @end example
6680 Of course if the build is run under a PTY, then stdout and stderr will
6681 be merged before the buildbot ever sees them, so such interleaving
6682 will be unavoidable.
6685 @node Interlocks, Build Factories, Build Steps, Build Process
6686 @section Interlocks
6688 @cindex locks
6689 @slindex buildbot.locks.MasterLock
6690 @slindex buildbot.locks.SlaveLock
6691 @slindex buildbot.locks.LockAccess
6693 Until now, we assumed that a master can run builds at any slave whenever
6694 needed or desired.  Some times, you want to enforce additional constraints on
6695 builds. For reasons like limited network bandwidth, old slave machines, or a
6696 self-willed data base server, you may want to limit the number of builds (or
6697 build steps) that can access a resource.
6699 The mechanism used by Buildbot is known as the read/write lock.@footnote{See
6700 http://en.wikipedia.org/wiki/Read/write_lock_pattern for more information.} It
6701 allows either many readers or a single writer but not a combination of readers
6702 and writers. The general lock has been modified and extended for use in
6703 Buildbot. Firstly, the general lock allows an infinite number of readers. In
6704 Buildbot, we often want to put an upper limit on the number of readers, for
6705 example allowing two out of five possible builds at the same time. To do this,
6706 the lock counts the number of active readers. Secondly, the terms @emph{read
6707 mode} and @emph{write mode} are confusing in Buildbot context. They have been
6708 replaced by @emph{counting mode} (since the lock counts them) and @emph{exclusive
6709 mode}.  As a result of these changes, locks in Buildbot allow a number of
6710 builds (upto some fixed number) in counting mode, or they allow one build in
6711 exclusive mode.
6713 Often, not all slaves are equal. To allow for this situation, Buildbot allows
6714 to have a separate upper limit on the count for each slave. In this way, you
6715 can have at most 3 concurrent builds at a fast slave, 2 at a slightly older
6716 slave, and 1 at all other slaves.
6718 The final thing you can specify when you introduce a new lock is its scope.
6719 Some constraints are global -- they must be enforced over all slaves. Other
6720 constraints are local to each slave.  A @emph{master lock} is used for the
6721 global constraints. You can ensure for example that at most one build (of all
6722 builds running at all slaves) accesses the data base server. With a
6723 @emph{slave lock} you can add a limit local to each slave. With such a lock,
6724 you can for example enforce an upper limit to the number of active builds at a
6725 slave, like above.
6727 Time for a few examples. Below a master lock is defined to protect a data base,
6728 and a slave lock is created to limit the number of builds at each slave.
6730 @example
6731 from buildbot import locks
6733 db_lock = locks.MasterLock("database")
6734 build_lock = locks.SlaveLock("slave_builds",
6735                              maxCount = 1,
6736                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6737 @end example
6739 After importing locks from buildbot, @code{db_lock} is defined to be a master
6740 lock. The @code{"database"} string is used for uniquely identifying the lock.
6741 At the next line, a slave lock called @code{build_lock} is created. It is
6742 identified by the @code{"slave_builds"} string. Since the requirements of the
6743 lock are a bit more complicated, two optional arguments are also specified. The
6744 @code{maxCount} parameter sets the default limit for builds in counting mode to
6745 @code{1}. For the slave called @code{'fast'} however, we want to have at most
6746 three builds, and for the slave called @code{'new'} the upper limit is two
6747 builds running at the same time.
6749 The next step is using the locks in builds.  Buildbot allows a lock to be used
6750 during an entire build (from beginning to end), or only during a single build
6751 step. In the latter case, the lock is claimed for use just before the step
6752 starts, and released again when the step ends. To prevent
6753 deadlocks,@footnote{Deadlock is the situation where two or more slaves each
6754 hold a lock in exclusive mode, and in addition want to claim the lock held by
6755 the other slave exclusively as well. Since locks allow at most one exclusive
6756 user, both slaves will wait forever.} it is not possible to claim or release
6757 locks at other times.
6759 To use locks, you should add them with a @code{locks} argument.
6760 Each use of a lock is either in counting mode (that is, possibly shared with
6761 other builds) or in exclusive mode. A build or build step proceeds only when it
6762 has acquired all locks. If a build or step needs a lot of locks, it may be
6763 starved@footnote{Starving is the situation that only a few locks are available,
6764 and they are immediately grabbed by another build. As a result, it may take a
6765 long time before all locks needed by the starved build are free at the same
6766 time.} by other builds that need fewer locks.
6768 To illustrate use of locks, a few examples.
6770 @example
6771 from buildbot import locks
6772 from buildbot.steps import source, shell
6773 from buildbot.process import factory
6775 db_lock = locks.MasterLock("database")
6776 build_lock = locks.SlaveLock("slave_builds",
6777                              maxCount = 1,
6778                              maxCountForSlave = @{ 'fast': 3, 'new': 2 @})
6780 f = factory.BuildFactory()
6781 f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk"))
6782 f.addStep(shell.ShellCommand(command="make all"))
6783 f.addStep(shell.ShellCommand(command="make test",
6784                              locks=[db_lock.access('exclusive')]))
6786 b1 = @{'name': 'full1', 'slavename': 'fast',  'builddir': 'f1', 'factory': f,
6787        'locks': [build_lock.access('counting')] @}
6789 b2 = @{'name': 'full2', 'slavename': 'new',   'builddir': 'f2', 'factory': f.
6790        'locks': [build_lock.access('counting')] @}
6792 b3 = @{'name': 'full3', 'slavename': 'old',   'builddir': 'f3', 'factory': f.
6793        'locks': [build_lock.access('counting')] @}
6795 b4 = @{'name': 'full4', 'slavename': 'other', 'builddir': 'f4', 'factory': f.
6796        'locks': [build_lock.access('counting')] @}
6798 c['builders'] = [b1, b2, b3, b4]
6799 @end example
6801 Here we have four slaves @code{b1}, @code{b2}, @code{b3}, and @code{b4}. Each
6802 slave performs the same checkout, make, and test build step sequence.
6803 We want to enforce that at most one test step is executed between all slaves due
6804 to restrictions with the data base server. This is done by adding the
6805 @code{locks=} parameter with the third step. It takes a list of locks with their
6806 access mode. In this case only the @code{db_lock} is needed. The exclusive
6807 access mode is used to ensure there is at most one slave that executes the test
6808 step.
6810 In addition to exclusive accessing the data base, we also want slaves to stay
6811 responsive even under the load of a large number of builds being triggered.
6812 For this purpose, the slave lock called @code{build_lock} is defined. Since
6813 the restraint holds for entire builds, the lock is specified in the builder
6814 with @code{'locks': [build_lock.access('counting')]}.
6815 @node Build Factories,  , Interlocks, Build Process
6816 @section Build Factories
6819 Each Builder is equipped with a ``build factory'', which is
6820 responsible for producing the actual @code{Build} objects that perform
6821 each build. This factory is created in the configuration file, and
6822 attached to a Builder through the @code{factory} element of its
6823 dictionary.
6825 The standard @code{BuildFactory} object creates @code{Build} objects
6826 by default. These Builds will each execute a collection of BuildSteps
6827 in a fixed sequence. Each step can affect the results of the build,
6828 but in general there is little intelligence to tie the different steps
6829 together. You can create subclasses of @code{Build} to implement more
6830 sophisticated build processes, and then use a subclass of
6831 @code{BuildFactory} (or simply set the @code{buildClass} attribute) to
6832 create instances of your new Build subclass.
6835 @menu
6836 * BuildStep Objects::
6837 * BuildFactory::
6838 * Process-Specific build factories::
6839 @end menu
6841 @node BuildStep Objects, BuildFactory, Build Factories, Build Factories
6842 @subsection BuildStep Objects
6844 The steps used by these builds are all subclasses of @code{BuildStep}.
6845 The standard ones provided with Buildbot are documented later,
6846 @xref{Build Steps}. You can also write your own subclasses to use in
6847 builds.
6849 The basic behavior for a @code{BuildStep} is to:
6851 @itemize @bullet
6852 @item
6853 run for a while, then stop
6854 @item
6855 possibly invoke some RemoteCommands on the attached build slave
6856 @item
6857 possibly produce a set of log files
6858 @item
6859 finish with a status described by one of four values defined in
6860 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, SKIPPED
6861 @item
6862 provide a list of short strings to describe the step
6863 @item
6864 define a color (generally green, orange, or red) with which the
6865 step should be displayed
6866 @end itemize
6869 More sophisticated steps may produce additional information and
6870 provide it to later build steps, or store it in the factory to provide
6871 to later builds.
6874 @menu
6875 * BuildFactory Attributes::
6876 * Quick builds::
6877 @end menu
6879 @node BuildFactory, Process-Specific build factories, BuildStep Objects, Build Factories
6880 @subsection BuildFactory
6882 @bfindex buildbot.process.factory.BuildFactory
6883 @bfindex buildbot.process.factory.BasicBuildFactory
6884 @c TODO: what is BasicSVN anyway?
6885 @bfindex buildbot.process.factory.BasicSVN
6887 The default @code{BuildFactory}, provided in the
6888 @code{buildbot.process.factory} module, contains an internal list of
6889 ``BuildStep specifications'': a list of @code{(step_class, kwargs)}
6890 tuples for each. These specification tuples are constructed when the
6891 config file is read, by asking the instances passed to @code{addStep}
6892 for their subclass and arguments.
6894 When asked to create a Build, the @code{BuildFactory} puts a copy of
6895 the list of step specifications into the new Build object. When the
6896 Build is actually started, these step specifications are used to
6897 create the actual set of BuildSteps, which are then executed one at a
6898 time. This serves to give each Build an independent copy of each step.
6899 For example, a build which consists of a CVS checkout followed by a
6900 @code{make build} would be constructed as follows:
6902 @example
6903 from buildbot.steps import source, shell
6904 from buildbot.process import factory
6906 f = factory.BuildFactory()
6907 f.addStep(source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"))
6908 f.addStep(shell.Compile(command=["make", "build"]))
6909 @end example
6911 (To support config files from buildbot-0.7.5 and earlier,
6912 @code{addStep} also accepts the @code{f.addStep(shell.Compile,
6913 command=["make","build"])} form, although its use is discouraged
6914 because then the @code{Compile} step doesn't get to validate or
6915 complain about its arguments until build time. The modern
6916 pass-by-instance approach allows this validation to occur while the
6917 config file is being loaded, where the admin has a better chance of
6918 noticing problems).
6920 It is also possible to pass a list of steps into the
6921 @code{BuildFactory} when it is created. Using @code{addStep} is
6922 usually simpler, but there are cases where is is more convenient to
6923 create the list of steps ahead of time.:
6925 @example
6926 from buildbot.steps import source, shell
6927 from buildbot.process import factory
6929 all_steps = [source.CVS(cvsroot=CVSROOT, cvsmodule="project", mode="update"),
6930              shell.Compile(command=["make", "build"]),
6931             ]
6932 f = factory.BuildFactory(all_steps)
6933 @end example
6936 Each step can affect the build process in the following ways:
6938 @itemize @bullet
6939 @item
6940 If the step's @code{haltOnFailure} attribute is True, then a failure
6941 in the step (i.e. if it completes with a result of FAILURE) will cause
6942 the whole build to be terminated immediately: no further steps will be
6943 executed, with the exception of steps with @code{alwaysRun} set to
6944 True. @code{haltOnFailure} is useful for setup steps upon which the
6945 rest of the build depends: if the CVS checkout or @code{./configure}
6946 process fails, there is no point in trying to compile or test the
6947 resulting tree.
6949 @item
6950 If the step's @code{alwaysRun} attribute is True, then it will always
6951 be run, regardless of if previous steps have failed. This is useful
6952 for cleanup steps that should always be run to return the build
6953 directory or build slave into a good state.
6955 @item
6956 If the @code{flunkOnFailure} or @code{flunkOnWarnings} flag is set,
6957 then a result of FAILURE or WARNINGS will mark the build as a whole as
6958 FAILED. However, the remaining steps will still be executed. This is
6959 appropriate for things like multiple testing steps: a failure in any
6960 one of them will indicate that the build has failed, however it is
6961 still useful to run them all to completion.
6963 @item
6964 Similarly, if the @code{warnOnFailure} or @code{warnOnWarnings} flag
6965 is set, then a result of FAILURE or WARNINGS will mark the build as
6966 having WARNINGS, and the remaining steps will still be executed. This
6967 may be appropriate for certain kinds of optional build or test steps.
6968 For example, a failure experienced while building documentation files
6969 should be made visible with a WARNINGS result but not be serious
6970 enough to warrant marking the whole build with a FAILURE.
6972 @end itemize
6974 In addition, each Step produces its own results, may create logfiles,
6975 etc. However only the flags described above have any effect on the
6976 build as a whole.
6978 The pre-defined BuildSteps like @code{CVS} and @code{Compile} have
6979 reasonably appropriate flags set on them already. For example, without
6980 a source tree there is no point in continuing the build, so the
6981 @code{CVS} class has the @code{haltOnFailure} flag set to True. Look
6982 in @file{buildbot/steps/*.py} to see how the other Steps are
6983 marked.
6985 Each Step is created with an additional @code{workdir} argument that
6986 indicates where its actions should take place. This is specified as a
6987 subdirectory of the slave builder's base directory, with a default
6988 value of @code{build}. This is only implemented as a step argument (as
6989 opposed to simply being a part of the base directory) because the
6990 CVS/SVN steps need to perform their checkouts from the parent
6991 directory.
6993 @menu
6994 * BuildFactory Attributes::
6995 * Quick builds::
6996 @end menu
6998 @node BuildFactory Attributes, Quick builds, BuildFactory, BuildFactory
6999 @subsubsection BuildFactory Attributes
7001 Some attributes from the BuildFactory are copied into each Build.
7003 @cindex treeStableTimer
7005 @table @code
7006 @item useProgress
7007 (defaults to True): if True, the buildmaster keeps track of how long
7008 each step takes, so it can provide estimates of how long future builds
7009 will take. If builds are not expected to take a consistent amount of
7010 time (such as incremental builds in which a random set of files are
7011 recompiled or tested each time), this should be set to False to
7012 inhibit progress-tracking.
7014 @end table
7017 @node Quick builds,  , BuildFactory Attributes, BuildFactory
7018 @subsubsection Quick builds
7020 @bfindex buildbot.process.factory.QuickBuildFactory
7022 The difference between a ``full build'' and a ``quick build'' is that
7023 quick builds are generally done incrementally, starting with the tree
7024 where the previous build was performed. That simply means that the
7025 source-checkout step should be given a @code{mode='update'} flag, to
7026 do the source update in-place.
7028 In addition to that, the @code{useProgress} flag should be set to
7029 False. Incremental builds will (or at least the ought to) compile as
7030 few files as necessary, so they will take an unpredictable amount of
7031 time to run. Therefore it would be misleading to claim to predict how
7032 long the build will take.
7035 @node Process-Specific build factories,  , BuildFactory, Build Factories
7036 @subsection Process-Specific build factories
7038 Many projects use one of a few popular build frameworks to simplify
7039 the creation and maintenance of Makefiles or other compilation
7040 structures. Buildbot provides several pre-configured BuildFactory
7041 subclasses which let you build these projects with a minimum of fuss.
7043 @menu
7044 * GNUAutoconf::
7045 * CPAN::
7046 * Python distutils::
7047 * Python/Twisted/trial projects::
7048 @end menu
7050 @node GNUAutoconf, CPAN, Process-Specific build factories, Process-Specific build factories
7051 @subsubsection GNUAutoconf
7053 @bfindex buildbot.process.factory.GNUAutoconf
7055 @uref{http://www.gnu.org/software/autoconf/, GNU Autoconf} is a
7056 software portability tool, intended to make it possible to write
7057 programs in C (and other languages) which will run on a variety of
7058 UNIX-like systems. Most GNU software is built using autoconf. It is
7059 frequently used in combination with GNU automake. These tools both
7060 encourage a build process which usually looks like this:
7062 @example
7063 % CONFIG_ENV=foo ./configure --with-flags
7064 % make all
7065 % make check
7066 # make install
7067 @end example
7069 (except of course the Buildbot always skips the @code{make install}
7070 part).
7072 The Buildbot's @code{buildbot.process.factory.GNUAutoconf} factory is
7073 designed to build projects which use GNU autoconf and/or automake. The
7074 configuration environment variables, the configure flags, and command
7075 lines used for the compile and test are all configurable, in general
7076 the default values will be suitable.
7078 Example:
7080 @example
7081 # use the s() convenience function defined earlier
7082 f = factory.GNUAutoconf(source=s(step.SVN, svnurl=URL, mode="copy"),
7083                         flags=["--disable-nls"])
7084 @end example
7086 Required Arguments:
7088 @table @code
7089 @item source
7090 This argument must be a step specification tuple that provides a
7091 BuildStep to generate the source tree.
7092 @end table
7094 Optional Arguments:
7096 @table @code
7097 @item configure
7098 The command used to configure the tree. Defaults to
7099 @code{./configure}. Accepts either a string or a list of shell argv
7100 elements.
7102 @item configureEnv
7103 The environment used for the initial configuration step. This accepts
7104 a dictionary which will be merged into the buildslave's normal
7105 environment. This is commonly used to provide things like
7106 @code{CFLAGS="-O2 -g"} (to turn off debug symbols during the compile).
7107 Defaults to an empty dictionary.
7109 @item configureFlags
7110 A list of flags to be appended to the argument list of the configure
7111 command. This is commonly used to enable or disable specific features
7112 of the autoconf-controlled package, like @code{["--without-x"]} to
7113 disable windowing support. Defaults to an empty list.
7115 @item compile
7116 this is a shell command or list of argv values which is used to
7117 actually compile the tree. It defaults to @code{make all}. If set to
7118 None, the compile step is skipped.
7120 @item test
7121 this is a shell command or list of argv values which is used to run
7122 the tree's self-tests. It defaults to @code{make check}. If set to
7123 None, the test step is skipped.
7125 @end table
7128 @node CPAN, Python distutils, GNUAutoconf, Process-Specific build factories
7129 @subsubsection CPAN
7131 @bfindex buildbot.process.factory.CPAN
7133 Most Perl modules available from the @uref{http://www.cpan.org/, CPAN}
7134 archive use the @code{MakeMaker} module to provide configuration,
7135 build, and test services. The standard build routine for these modules
7136 looks like:
7138 @example
7139 % perl Makefile.PL
7140 % make
7141 % make test
7142 # make install
7143 @end example
7145 (except again Buildbot skips the install step)
7147 Buildbot provides a @code{CPAN} factory to compile and test these
7148 projects.
7151 Arguments:
7152 @table @code
7153 @item source
7154 (required): A step specification tuple, like that used by GNUAutoconf.
7156 @item perl
7157 A string which specifies the @code{perl} executable to use. Defaults
7158 to just @code{perl}.
7160 @end table
7163 @node Python distutils, Python/Twisted/trial projects, CPAN, Process-Specific build factories
7164 @subsubsection Python distutils
7166 @bfindex buildbot.process.factory.Distutils
7168 Most Python modules use the @code{distutils} package to provide
7169 configuration and build services. The standard build process looks
7170 like:
7172 @example
7173 % python ./setup.py build
7174 % python ./setup.py install
7175 @end example
7177 Unfortunately, although Python provides a standard unit-test framework
7178 named @code{unittest}, to the best of my knowledge @code{distutils}
7179 does not provide a standardized target to run such unit tests. (Please
7180 let me know if I'm wrong, and I will update this factory.)
7182 The @code{Distutils} factory provides support for running the build
7183 part of this process. It accepts the same @code{source=} parameter as
7184 the other build factories.
7187 Arguments:
7188 @table @code
7189 @item source
7190 (required): A step specification tuple, like that used by GNUAutoconf.
7192 @item python
7193 A string which specifies the @code{python} executable to use. Defaults
7194 to just @code{python}.
7196 @item test
7197 Provides a shell command which runs unit tests. This accepts either a
7198 string or a list. The default value is None, which disables the test
7199 step (since there is no common default command to run unit tests in
7200 distutils modules).
7202 @end table
7205 @node Python/Twisted/trial projects,  , Python distutils, Process-Specific build factories
7206 @subsubsection Python/Twisted/trial projects
7208 @bfindex buildbot.process.factory.Trial
7209 @c TODO: document these steps better
7210 @bsindex buildbot.steps.python_twisted.HLint
7211 @bsindex buildbot.steps.python_twisted.Trial
7212 @bsindex buildbot.steps.python_twisted.ProcessDocs
7213 @bsindex buildbot.steps.python_twisted.BuildDebs
7214 @bsindex buildbot.steps.python_twisted.RemovePYCs
7216 Twisted provides a unit test tool named @code{trial} which provides a
7217 few improvements over Python's built-in @code{unittest} module. Many
7218 python projects which use Twisted for their networking or application
7219 services also use trial for their unit tests. These modules are
7220 usually built and tested with something like the following:
7222 @example
7223 % python ./setup.py build
7224 % PYTHONPATH=build/lib.linux-i686-2.3 trial -v PROJECTNAME.test
7225 % python ./setup.py install
7226 @end example
7228 Unfortunately, the @file{build/lib} directory into which the
7229 built/copied .py files are placed is actually architecture-dependent,
7230 and I do not yet know of a simple way to calculate its value. For many
7231 projects it is sufficient to import their libraries ``in place'' from
7232 the tree's base directory (@code{PYTHONPATH=.}).
7234 In addition, the @var{PROJECTNAME} value where the test files are
7235 located is project-dependent: it is usually just the project's
7236 top-level library directory, as common practice suggests the unit test
7237 files are put in the @code{test} sub-module. This value cannot be
7238 guessed, the @code{Trial} class must be told where to find the test
7239 files.
7241 The @code{Trial} class provides support for building and testing
7242 projects which use distutils and trial. If the test module name is
7243 specified, trial will be invoked. The library path used for testing
7244 can also be set.
7246 One advantage of trial is that the Buildbot happens to know how to
7247 parse trial output, letting it identify which tests passed and which
7248 ones failed. The Buildbot can then provide fine-grained reports about
7249 how many tests have failed, when individual tests fail when they had
7250 been passing previously, etc.
7252 Another feature of trial is that you can give it a series of source
7253 .py files, and it will search them for special @code{test-case-name}
7254 tags that indicate which test cases provide coverage for that file.
7255 Trial can then run just the appropriate tests. This is useful for
7256 quick builds, where you want to only run the test cases that cover the
7257 changed functionality.
7259 Arguments:
7260 @table @code
7261 @item testpath
7262 Provides a directory to add to @code{PYTHONPATH} when running the unit
7263 tests, if tests are being run. Defaults to @code{.} to include the
7264 project files in-place. The generated build library is frequently
7265 architecture-dependent, but may simply be @file{build/lib} for
7266 pure-python modules.
7268 @item python
7269 which python executable to use. This list will form the start of
7270 the argv array that will launch trial. If you use this,
7271 you should set @code{trial} to an explicit path (like
7272 @code{/usr/bin/trial} or @code{./bin/trial}). The parameter defaults to @code{None}, which
7273 leaves it out entirely (running @code{trial args} instead of
7274 @code{python ./bin/trial args}). Likely values are @code{['python']},
7275 @code{['python2.2']}, or @code{['python', '-Wall']}.
7277 @item trial
7278 provides the name of the @code{trial} command. It is occasionally
7279 useful to use an alternate executable, such as @code{trial2.2} which
7280 might run the tests under an older version of Python. Defaults to
7281 @code{trial}.
7283 @item trialMode
7284 a list of arguments to pass to trial, specifically to set the reporting mode.
7285 This defaults to @code{['--reporter=bwverbose']}, which only works for
7286 Twisted-2.1.0 and later.
7288 @item trialArgs
7289 a list of arguments to pass to trial, available to turn on any extra flags you
7290 like. Defaults to @code{[]}.
7292 @item tests
7293 Provides a module name or names which contain the unit tests for this
7294 project. Accepts a string, typically @code{PROJECTNAME.test}, or a
7295 list of strings. Defaults to None, indicating that no tests should be
7296 run. You must either set this or @code{testChanges}.
7298 @item testChanges
7299 if True, ignore the @code{tests} parameter and instead ask the Build for all
7300 the files that make up the Changes going into this build. Pass these filenames
7301 to trial and ask it to look for test-case-name tags, running just the tests
7302 necessary to cover the changes.
7304 @item recurse
7305 If @code{True}, tells Trial (with the @code{--recurse} argument) to look in all
7306 subdirectories for additional test cases. 
7308 @item reactor
7309 which reactor to use, like 'gtk' or 'java'. If not provided, the Twisted's
7310 usual platform-dependent default is used.
7312 @item randomly
7313 If @code{True}, tells Trial (with the @code{--random=0} argument) to
7314 run the test cases in random order, which sometimes catches subtle
7315 inter-test dependency bugs. Defaults to @code{False}.
7316 @end table
7318 The step can also take any of the @code{ShellCommand} arguments, e.g.,
7319 @code{haltOnFailure}.
7321 Unless one of @code{tests} or @code{testChanges} are set, the step will
7322 generate an exception.
7324 @node Status Delivery, Command-line tool, Build Process, Top
7325 @chapter Status Delivery
7327 More details are available in the docstrings for each class, use a
7328 command like @code{pydoc buildbot.status.html.WebStatus} to see them.
7329 Most status delivery objects take a @code{categories=} argument, which
7330 can contain a list of ``category'' names: in this case, it will only
7331 show status for Builders that are in one of the named categories.
7333 (implementor's note: each of these objects should be a
7334 service.MultiService which will be attached to the BuildMaster object
7335 when the configuration is processed. They should use
7336 @code{self.parent.getStatus()} to get access to the top-level IStatus
7337 object, either inside @code{startService} or later. They may call
7338 @code{status.subscribe()} in @code{startService} to receive
7339 notifications of builder events, in which case they must define
7340 @code{builderAdded} and related methods. See the docstrings in
7341 @file{buildbot/interfaces.py} for full details.)
7343 @menu
7344 * WebStatus::
7345 * MailNotifier::
7346 * IRC Bot::
7347 * PBListener::
7348 * Writing New Status Plugins::
7349 @end menu
7351 @c @node Email Delivery,  , Status Delivery, Status Delivery
7352 @c @subsection Email Delivery
7354 @c DOCUMENT THIS
7357 @node WebStatus, MailNotifier, Status Delivery, Status Delivery
7358 @section WebStatus
7360 @cindex WebStatus
7361 @stindex buildbot.status.web.baseweb.WebStatus
7363 The @code{buildbot.status.html.WebStatus} status target runs a small
7364 web server inside the buildmaster. You can point a browser at this web
7365 server and retrieve information about every build the buildbot knows
7366 about, as well as find out what the buildbot is currently working on.
7368 The first page you will see is the ``Welcome Page'', which contains
7369 links to all the other useful pages. This page is simply served from
7370 the @file{public_html/index.html} file in the buildmaster's base
7371 directory, where it is created by the @command{buildbot create-master}
7372 command along with the rest of the buildmaster.
7374 The most complex resource provided by @code{WebStatus} is the
7375 ``Waterfall Display'', which shows a time-based chart of events. This
7376 somewhat-busy display provides detailed information about all steps of
7377 all recent builds, and provides hyperlinks to look at individual build
7378 logs and source changes. By simply reloading this page on a regular
7379 basis, you will see a complete description of everything the buildbot
7380 is currently working on.
7382 A similar, but more developer-oriented display is the "Grid" display.  This
7383 arranges builds by SourceStamp (horizontal axis) and builder (vertical axis),
7384 and can provide quick information as to which revisions are passing or failing
7385 on which builders.
7387 There are also pages with more specialized information. For example,
7388 there is a page which shows the last 20 builds performed by the
7389 buildbot, one line each. Each line is a link to detailed information
7390 about that build. By adding query arguments to the URL used to reach
7391 this page, you can narrow the display to builds that involved certain
7392 branches, or which ran on certain Builders. These pages are described
7393 in great detail below.
7396 When the buildmaster is created, a subdirectory named
7397 @file{public_html/} is created in its base directory. By default, @code{WebStatus}
7398 will serve files from this directory: for example, when a user points
7399 their browser at the buildbot's @code{WebStatus} URL, they will see
7400 the contents of the @file{public_html/index.html} file. Likewise,
7401 @file{public_html/robots.txt}, @file{public_html/buildbot.css}, and
7402 @file{public_html/favicon.ico} are all useful things to have in there.
7403 The first time a buildmaster is created, the @file{public_html}
7404 directory is populated with some sample files, which you will probably
7405 want to customize for your own project. These files are all static:
7406 the buildbot does not modify them in any way as it serves them to HTTP
7407 clients.
7409 @example
7410 from buildbot.status.html import WebStatus
7411 c['status'].append(WebStatus(8080))
7412 @end example
7414 Note that the initial robots.txt file has Disallow lines for all of
7415 the dynamically-generated buildbot pages, to discourage web spiders
7416 and search engines from consuming a lot of CPU time as they crawl
7417 through the entire history of your buildbot. If you are running the
7418 buildbot behind a reverse proxy, you'll probably need to put the
7419 robots.txt file somewhere else (at the top level of the parent web
7420 server), and replace the URL prefixes in it with more suitable values.
7422 If you would like to use an alternative root directory, add the
7423 @code{public_html=..} option to the @code{WebStatus} creation:
7425 @example
7426 c['status'].append(WebStatus(8080, public_html="/var/www/buildbot"))
7427 @end example
7429 In addition, if you are familiar with twisted.web @emph{Resource
7430 Trees}, you can write code to add additional pages at places inside
7431 this web space. Just use @code{webstatus.putChild} to place these
7432 resources.
7434 The following section describes the special URLs and the status views
7435 they provide.
7438 @menu
7439 * WebStatus Configuration Parameters::
7440 * Enabling the "Force Build" Button::
7441 * Buildbot Web Resources::
7442 * XMLRPC server::
7443 * HTML Waterfall::
7444 @end menu
7446 @node WebStatus Configuration Parameters
7447 @subsection WebStatus Configuration Parameters
7449 The most common way to run a @code{WebStatus} is on a regular TCP
7450 port. To do this, just pass in the TCP port number when you create the
7451 @code{WebStatus} instance; this is called the @code{http_port} argument:
7453 @example
7454 from buildbot.status.html import WebStatus
7455 c['status'].append(WebStatus(8080))
7456 @end example
7458 The @code{http_port} argument is actually a ``strports specification''
7459 for the port that the web server should listen on. This can be a
7460 simple port number, or a string like
7461 @code{tcp:8080:interface=127.0.0.1} (to limit connections to the
7462 loopback interface, and therefore to clients running on the same
7463 host)@footnote{It may even be possible to provide SSL access by using
7464 a specification like
7465 @code{"ssl:12345:privateKey=mykey.pen:certKey=cert.pem"}, but this is
7466 completely untested}.
7468 If instead (or in addition) you provide the @code{distrib_port}
7469 argument, a twisted.web distributed server will be started either on a
7470 TCP port (if @code{distrib_port} is like @code{"tcp:12345"}) or more
7471 likely on a UNIX socket (if @code{distrib_port} is like
7472 @code{"unix:/path/to/socket"}).
7474 The @code{distrib_port} option means that, on a host with a
7475 suitably-configured twisted-web server, you do not need to consume a
7476 separate TCP port for the buildmaster's status web page. When the web
7477 server is constructed with @code{mktap web --user}, URLs that point to
7478 @code{http://host/~username/} are dispatched to a sub-server that is
7479 listening on a UNIX socket at @code{~username/.twisted-web-pb}. On
7480 such a system, it is convenient to create a dedicated @code{buildbot}
7481 user, then set @code{distrib_port} to
7482 @code{"unix:"+os.path.expanduser("~/.twistd-web-pb")}. This
7483 configuration will make the HTML status page available at
7484 @code{http://host/~buildbot/} . Suitable URL remapping can make it
7485 appear at @code{http://host/buildbot/}, and the right virtual host
7486 setup can even place it at @code{http://buildbot.host/} .
7488 @node Enabling the "Force Build" Button
7489 @subsection Enabling the "Force Build" Button
7491 An important @code{WebStatus} argument is @code{allowForce}. If set to True,
7492 then the web page will provide a ``Force Build'' button that allows visitors to
7493 manually trigger builds. This is useful for developers to re-run builds that
7494 have failed because of intermittent problems in the test suite, or because of
7495 libraries that were not installed at the time of the previous build. The
7496 default value is False, since it also allows anyone with a web browser to waste
7497 computing resources forcing unnecessary builds.
7499 If you do not wish to allow strangers to cause a build to run or to stop
7500 current builds, pass an instance of @code{status.web.authentication.IAuth} as a
7501 @code{auth} keyword argument to @code{WebStatus}.  The class @code{BasicAuth}
7502 implements a basic authentication mechanism using a list of user/password
7503 tuples provided from the configuration file.  The class @code{HTPasswdAuth}
7504 implements an authentication against an @file{.htpasswd} file.
7506 @example
7507 from buildbot.status.html import WebStatus
7508 from buildbot.status.web.authentication import BasicAuth
7509 users = [('bob', 'secret-pass'), ('jill', 'super-pass')]
7510 c['status'].append(WebStatus(http_port=8080, auth=BasicAuth(users)))
7512 from buildbot.status.web.authentication import HTPasswdAuth
7513 file = '/path/to/file'
7514 c['status'].append(WebStatus(http_port=8080, auth=(HTPasswdAuth(file))))
7515 @end example
7517 @node Buildbot Web Resources
7518 @subsection Buildbot Web Resources
7520 Certain URLs are ``magic'', and the pages they serve are created by
7521 code in various classes in the @file{buildbot.status.web} package
7522 instead of being read from disk. The most common way to access these
7523 pages is for the buildmaster admin to write or modify the
7524 @file{index.html} page to contain links to them. Of course other
7525 project web pages can contain links to these buildbot pages as well.
7527 Many pages can be modified by adding query arguments to the URL. For
7528 example, a page which shows the results of the most recent build
7529 normally does this for all builders at once. But by appending
7530 ``?builder=i386'' to the end of the URL, the page will show only the
7531 results for the ``i386'' builder. When used in this way, you can add
7532 multiple ``builder='' arguments to see multiple builders. Remembering
7533 that URL query arguments are separated @emph{from each other} with
7534 ampersands, a URL that ends in ``?builder=i386&builder=ppc'' would
7535 show builds for just those two Builders.
7537 The @code{branch=} query argument can be used on some pages. This
7538 filters the information displayed by that page down to only the builds
7539 or changes which involved the given branch. Use @code{branch=trunk} to
7540 reference the trunk: if you aren't intentionally using branches,
7541 you're probably using trunk. Multiple @code{branch=} arguments can be
7542 used to examine multiple branches at once (so appending
7543 @code{?branch=foo&branch=bar} to the URL will show builds involving
7544 either branch). No @code{branch=} arguments means to show builds and
7545 changes for all branches.
7547 Some pages may include the Builder name or the build number in the
7548 main part of the URL itself. For example, a page that describes Build
7549 #7 of the ``i386'' builder would live at @file{/builders/i386/builds/7}.
7551 The table below lists all of the internal pages and the URLs that can
7552 be used to access them.
7554 NOTE: of the pages described here, @code{/slave_status_timeline} and
7555 @code{/last_build} have not yet been implemented, and @code{/xmlrpc}
7556 has only a few methods so far. Future releases will improve this.
7558 @table @code
7560 @item /waterfall
7562 This provides a chronologically-oriented display of the activity of
7563 all builders. It is the same display used by the Waterfall display.
7565 By adding one or more ``builder='' query arguments, the Waterfall is
7566 restricted to only showing information about the given Builders. By
7567 adding one or more ``branch='' query arguments, the display is
7568 restricted to showing information about the given branches. In
7569 addition, adding one or more ``category='' query arguments to the URL
7570 will limit the display to Builders that were defined with one of the
7571 given categories.
7573 A 'show_events=true' query argument causes the display to include
7574 non-Build events, like slaves attaching and detaching, as well as
7575 reconfiguration events. 'show_events=false' hides these events. The
7576 default is to show them.
7578 By adding the 'failures_only=true' query argument, the Waterfall is
7579 restricted to only showing information about the builders that
7580 are currently failing. A builder is considered failing if the
7581 last finished build was not successful, a step in the current
7582 build(s) is failing, or if the builder is offline.
7584 The @code{last_time=}, @code{first_time=}, and @code{show_time=}
7585 arguments will control what interval of time is displayed. The default
7586 is to show the latest events, but these can be used to look at earlier
7587 periods in history. The @code{num_events=} argument also provides a
7588 limit on the size of the displayed page.
7590 The Waterfall has references to resources many of the other portions
7591 of the URL space: @file{/builders} for access to individual builds,
7592 @file{/changes} for access to information about source code changes,
7593 etc.
7595 @item /grid
7597 This provides a chronologically oriented display of builders, by
7598 revision.  The builders are listed down the left side of the page,
7599 and the revisions are listed across the top.
7601 By adding one ore more ``category='' arguments the grid will be
7602 restricted to revisions in those categories.
7604 A ``width=N'' argument will limit the number of revisions shown to N,
7605 defaulting to 5.
7607 A ``branch=BRANCHNAME'' argument will limit the grid to revisions on
7608 branch BRANCHNAME.
7610 @item /tgrid
7612 The Transposed Grid is similar to the standard grid, but, as the name
7613 implies, transposes the grid: the revisions are listed down the left side
7614 of the page, and the build hosts are listed across the top.  It accepts
7615 the same query arguments. The exception being that instead of ``width''
7616 the argument is named ``length.''
7618 @item /rss
7620 This provides a rss feed summarizing all failed builds. The same
7621 query-arguments used by 'waterfall' can be added to filter the
7622 feed output.
7624 @item /atom
7626 This provides an atom feed summarizing all failed builds. The same
7627 query-arguments used by 'waterfall' can be added to filter the feed
7628 output.
7630 @item /buildstatus?builder=$BUILDERNAME&number=$BUILDNUM
7632 This displays a waterfall-like chronologically-oriented view of all the
7633 steps for a given build number on a given builder.
7635 @item /builders/$BUILDERNAME
7637 This describes the given Builder, and provides buttons to force a
7638 build.  A @code{numbuilds=} argument will control how many build lines
7639 are displayed (5 by default).
7641 @item /builders/$BUILDERNAME/builds/$BUILDNUM
7643 This describes a specific Build.
7645 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME
7647 This describes a specific BuildStep.
7649 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME
7651 This provides an HTML representation of a specific logfile.
7653 @item /builders/$BUILDERNAME/builds/$BUILDNUM/steps/$STEPNAME/logs/$LOGNAME/text
7655 This returns the logfile as plain text, without any HTML coloring
7656 markup. It also removes the ``headers'', which are the lines that
7657 describe what command was run and what the environment variable
7658 settings were like. This maybe be useful for saving to disk and
7659 feeding to tools like 'grep'.
7661 @item /changes
7663 This provides a brief description of the ChangeSource in use
7664 (@pxref{Change Sources}).
7666 @item /changes/NN
7668 This shows detailed information about the numbered Change: who was the
7669 author, what files were changed, what revision number was represented,
7670 etc.
7672 @item /buildslaves
7674 This summarizes each BuildSlave, including which Builders are
7675 configured to use it, whether the buildslave is currently connected or
7676 not, and host information retrieved from the buildslave itself.
7678 @item /one_line_per_build
7680 This page shows one line of text for each build, merging information
7681 from all Builders@footnote{Apparently this is the same way
7682 http://buildd.debian.org displays build status}. Each line specifies
7683 the name of the Builder, the number of the Build, what revision it
7684 used, and a summary of the results. Successful builds are in green,
7685 while failing builds are in red. The date and time of the build are
7686 added to the right-hand edge of the line. The lines are ordered by
7687 build finish timestamp.
7689 One or more @code{builder=} or @code{branch=} arguments can be used to
7690 restrict the list. In addition, a @code{numbuilds=} argument will
7691 control how many lines are displayed (20 by default).
7693 @item /one_box_per_builder
7695 This page shows a small table, with one box for each Builder,
7696 containing the results of the most recent Build. It does not show the
7697 individual steps, or the current status. This is a simple summary of
7698 buildbot status: if this page is green, then all tests are passing.
7700 As with @code{/one_line_per_build}, this page will also honor
7701 @code{builder=} and @code{branch=} arguments.
7703 @item /about
7705 This page gives a brief summary of the Buildbot itself: software
7706 version, versions of some libraries that the Buildbot depends upon,
7707 etc. It also contains a link to the buildbot.net home page.
7709 @item /slave_status_timeline
7711 (note: this page has not yet been implemented)
7713 This provides a chronological display of configuration and operational
7714 events: master startup/shutdown, slave connect/disconnect, and
7715 config-file changes. When a config-file reload is abandoned because of
7716 an error in the config file, the error is displayed on this page.
7718 This page does not show any builds.
7720 @item /last_build/$BUILDERNAME/status.png
7722 This returns a PNG image that describes the results of the most recent
7723 build, which can be referenced in an IMG tag by other pages, perhaps
7724 from a completely different site. Use it as you would a webcounter.
7726 @end table
7728 There are also a set of web-status resources that are intended for use
7729 by other programs, rather than humans.
7731 @table @code
7733 @item /xmlrpc
7735 This runs an XML-RPC server which can be used to query status
7736 information about various builds. See @ref{XMLRPC server} for more
7737 details.
7739 @end table
7741 @node XMLRPC server, HTML Waterfall, Buildbot Web Resources, WebStatus
7742 @subsection XMLRPC server
7744 When using WebStatus, the buildbot runs an XML-RPC server at
7745 @file{/xmlrpc} that can be used by other programs to query build
7746 status. The following table lists the methods that can be invoked
7747 using this interface.
7749 @table @code
7750 @item getAllBuildsInInterval(start, stop)
7752 Return a list of builds that have completed after the 'start'
7753 timestamp and before the 'stop' timestamp. This looks at all Builders.
7755 The timestamps are integers, interpreted as standard unix timestamps
7756 (seconds since epoch).
7758 Each Build is returned as a tuple in the form: @code{(buildername,
7759 buildnumber, build_end, branchname, revision, results, text)}
7761 The buildnumber is an integer. 'build_end' is an integer (seconds
7762 since epoch) specifying when the build finished.
7764 The branchname is a string, which may be an empty string to indicate
7765 None (i.e. the default branch). The revision is a string whose meaning
7766 is specific to the VC system in use, and comes from the 'got_revision'
7767 build property. The results are expressed as a string, one of
7768 ('success', 'warnings', 'failure', 'exception'). The text is a list of
7769 short strings that ought to be joined by spaces and include slightly
7770 more data about the results of the build.
7772 @item getBuild(builder_name, build_number)
7774 Return information about a specific build.
7776 This returns a dictionary (aka ``struct'' in XMLRPC terms) with
7777 complete information about the build. It does not include the contents
7778 of the log files, but it has just about everything else.
7780 @end table
7782 @node HTML Waterfall,  , XMLRPC server, WebStatus
7783 @subsection HTML Waterfall
7785 @cindex Waterfall
7786 @stindex buildbot.status.html.Waterfall
7788 The @code{Waterfall} status target, deprecated as of 0.7.6, is a
7789 subset of the regular @code{WebStatus} resource (@pxref{WebStatus}).
7790 This section (and the @code{Waterfall} class itself) will be removed
7791 from a future release.
7793 @example
7794 from buildbot.status import html
7795 w = html.WebStatus(http_port=8080)
7796 c['status'].append(w)
7797 @end example
7801 @node MailNotifier, IRC Bot, WebStatus, Status Delivery
7802 @section MailNotifier
7804 @cindex email
7805 @cindex mail
7806 @stindex buildbot.status.mail.MailNotifier
7808 The buildbot can also send email when builds finish. The most common
7809 use of this is to tell developers when their change has caused the
7810 build to fail. It is also quite common to send a message to a mailing
7811 list (usually named ``builds'' or similar) about every build.
7813 The @code{MailNotifier} status target is used to accomplish this. You
7814 configure it by specifying who mail should be sent to, under what
7815 circumstances mail should be sent, and how to deliver the mail. It can
7816 be configured to only send out mail for certain builders, and only
7817 send messages when the build fails, or when the builder transitions
7818 from success to failure. It can also be configured to include various
7819 build logs in each message.
7822 By default, the message will be sent to the Interested Users list
7823 (@pxref{Doing Things With Users}), which includes all developers who
7824 made changes in the build. You can add additional recipients with the
7825 extraRecipients argument.
7827 Each MailNotifier sends mail to a single set of recipients. To send
7828 different kinds of mail to different recipients, use multiple
7829 MailNotifiers.
7831 The following simple example will send an email upon the completion of
7832 each build, to just those developers whose Changes were included in
7833 the build. The email contains a description of the Build, its results,
7834 and URLs where more information can be obtained.
7836 @example
7837 from buildbot.status.mail import MailNotifier
7838 mn = MailNotifier(fromaddr="buildbot@@example.org", lookup="example.org")
7839 c['status'].append(mn)
7840 @end example
7842 To get a simple one-message-per-build (say, for a mailing list), use
7843 the following form instead. This form does not send mail to individual
7844 developers (and thus does not need the @code{lookup=} argument,
7845 explained below), instead it only ever sends mail to the ``extra
7846 recipients'' named in the arguments:
7848 @example
7849 mn = MailNotifier(fromaddr="buildbot@@example.org",
7850                   sendToInterestedUsers=False,
7851                   extraRecipients=['listaddr@@example.org'])
7852 @end example
7854 In some cases it is desirable to have different information then what
7855 is provided in a standard MailNotifier message. For this purpose
7856 MailNotifier provides the argument customMesg (a function) which allows
7857 for the creation of messages with unique content.
7859 For example it can be useful to display the last few lines of a log file
7860 and recent changes when a builder fails:
7862 @example
7863 def message(attrs):
7864     logLines = 10
7865     text = list()
7866     text.append("STATUS: %s" % attrs['result'].title())
7867     text.append("")
7868     text.extend([c.asText() for c in attrs['changes']])
7869     text.append("")
7870     name, url, lines, logstatus = attrs['logs'][-1]
7871     text.append("Last %d lines of '%s':" % (logLines, name))
7872     text.extend(["\t%s\n" % line for line in lines[len(lines)-logLines:]])
7873     text.append("")
7874     text.append("-buildbot")
7875     return ("\n".join(text), 'plain')
7877 mn = MailNotifier(fromaddr="buildbot@@example.org",
7878                   sendToInterestedUsers=False,
7879                   mode='problem',
7880                   extraRecipients=['listaddr@@example.org'],
7881                   customMesg=message)
7882 @end example
7884 A customMesg function takes a single dict argument (see below) and returns a
7885 tuple of strings. The first string is the complete text of the message and the
7886 second is the message type ('plain' or 'html'). The 'html' type should be used
7887 when generating an HTML message:
7889 @example
7890 def message(attrs):
7891     logLines = 10
7892     text = list()
7893     text.append('<h4>Build status %s.</h4>' % (attrs['result'].title()))
7894     if attrs['changes']:
7895         text.append('<h4>Recent Changes:</h4>')
7896         text.extend([c.asHTML() for c in attrs['changes']])
7897     name, url, lines, logstatus = attrs['logs'][-1]
7898     text.append('<h4>Last %d lines of "%s":</h4>' % (logLines, name))
7899     text.append('<p>')
7900     text.append('<br>'.join([line for line in lines[len(lines)-logLines:]]))
7901     text.append('</p>')
7902     text.append('<br><br>')
7903     text.append('Full log at: %s' % url)
7904     text.append('<br><br>')
7905     text.append('<b>-buildbot</b>')
7906     return ('\n'.join(text), 'html')
7907 @end example
7909 @heading MailNotifier arguments
7911 @table @code
7912 @item fromaddr
7913 The email address to be used in the 'From' header.
7915 @item sendToInterestedUsers
7916 (boolean). If True (the default), send mail to all of the Interested
7917 Users. If False, only send mail to the extraRecipients list.
7919 @item extraRecipients
7920 (tuple of strings). A list of email addresses to which messages should
7921 be sent (in addition to the InterestedUsers list, which includes any
7922 developers who made Changes that went into this build). It is a good
7923 idea to create a small mailing list and deliver to that, then let
7924 subscribers come and go as they please.
7926 @item subject
7927 (string). A string to be used as the subject line of the message.
7928 @code{%(builder)s} will be replaced with the name of the builder which
7929 provoked the message.
7931 @item mode
7932 (string). Default to 'all'. One of:
7933 @table @code
7934 @item all
7935 Send mail about all builds, bothpassing and failing
7936 @item failing
7937 Only send mail about builds which fail
7938 @item problem
7939 Only send mail about a build which failed when the previous build has passed.
7940 If your builds usually pass, then this will only send mail when a problem
7941 occurs.
7942 @end table
7944 @item builders
7945 (list of strings). A list of builder names for which mail should be
7946 sent. Defaults to None (send mail for all builds). Use either builders
7947 or categories, but not both.
7949 @item categories
7950 (list of strings). A list of category names to serve status
7951 information for. Defaults to None (all categories). Use either
7952 builders or categories, but not both.
7954 @item addLogs
7955 (boolean). If True, include all build logs as attachments to the
7956 messages. These can be quite large. This can also be set to a list of
7957 log names, to send a subset of the logs. Defaults to False.
7959 @item relayhost
7960 (string). The host to which the outbound SMTP connection should be
7961 made. Defaults to 'localhost'
7963 @item lookup
7964 (implementor of @code{IEmailLookup}). Object which provides
7965 IEmailLookup, which is responsible for mapping User names (which come
7966 from the VC system) into valid email addresses. If not provided, the
7967 notifier will only be able to send mail to the addresses in the
7968 extraRecipients list. Most of the time you can use a simple Domain
7969 instance. As a shortcut, you can pass as string: this will be treated
7970 as if you had provided Domain(str). For example,
7971 lookup='twistedmatrix.com' will allow mail to be sent to all
7972 developers whose SVN usernames match their twistedmatrix.com account
7973 names. See buildbot/status/mail.py for more details.
7975 @item customMesg
7976 This is a optional function that can be used to generate a custom mail
7977 message. The customMesg function takes a single dict and must return a
7978 tuple containing the message text and type ('html' or 'plain'). Below is a list
7979 of availale keys in the dict passed to customMesg:
7981 @table @code
7982 @item builderName
7983 (str) Name of the builder that generated this event.
7984 @item projectName
7985 (str) Name of the project.
7986 @item mode
7987 (str) Mode set in MailNotifier. (failing, passing, problem).
7988 @item result
7989 (str) Builder result as a string. 'success', 'warnings', 'failure', 'skipped', or 'exception'
7990 @item buildURL
7991 (str) URL to build page.
7992 @item buildbotURL
7993 (str) URL to buildbot main page.
7994 @item buildText
7995 (str) Build text from build.getText().
7996 @item buildProperties
7997 (Properties instance) Mapping of property names to values.
7998 @item slavename
7999 (str) Slavename.
8000 @item reason
8001 (str) Build reason from build.getReason().
8002 @item responsibleUsers
8003 (List of str) List of responsible users.
8004 @item branch
8005 (str) Name of branch used. If no SourceStamp exists branch
8006 is an empty string.
8007 @item revision
8008 (str) Name of revision used. If no SourceStamp exists revision
8009 is an empty string.
8010 @item patch
8011 (str) Name of patch used. If no SourceStamp exists patch
8012 is an empty string.
8013 @item changes
8014 (list of objs) List of change objects from SourceStamp. A change
8015 object has the following useful information:
8016 @table @code
8017 @item who
8018 (str) who made this change
8019 @item revision
8020 (str) what VC revision is this change
8021 @item branch
8022 (str) on what branch did this change occur
8023 @item when
8024 (str) when did this change occur
8025 @item files
8026 (list of str) what files were affected in this change
8027 @item comments
8028 (str) comments reguarding the change.
8029 @end table
8030 The functions asText and asHTML return a list of strings with
8031 the above information formatted.
8032 @item logs
8033 (List of Tuples) List of tuples where each tuple contains the log name, log url,
8034 log contents as a list of strings, and the status of the corresponding build step,
8035 i.e. SUCCESS, WARNING, or FAILURE.
8036 @end table
8038 @item extraHeaders
8039 (dictionary) A dictionary containing key/value pairs of extra headers to add
8040 to sent e-mails. Both the keys and the values may be a WithProperties instance.
8042 @end table
8044 @node IRC Bot, PBListener, MailNotifier, Status Delivery
8045 @section IRC Bot
8047 @cindex IRC
8048 @stindex buildbot.status.words.IRC
8051 The @code{buildbot.status.words.IRC} status target creates an IRC bot
8052 which will attach to certain channels and be available for status
8053 queries. It can also be asked to announce builds as they occur, or be
8054 told to shut up.
8056 @example
8057 from buildbot.status import words
8058 irc = words.IRC("irc.example.org", "botnickname",
8059                 channels=["channel1", "channel2"],
8060                 password="mysecretpassword",
8061                 notify_events=@{
8062                   'exception': 1,
8063                   'successToFailure': 1,
8064                   'failureToSuccess': 1,
8065                 @})
8066 c['status'].append(irc)
8067 @end example
8069 Take a look at the docstring for @code{words.IRC} for more details on
8070 configuring this service. The @code{password} argument, if provided,
8071 will be sent to Nickserv to claim the nickname: some IRC servers will
8072 not allow clients to send private messages until they have logged in
8073 with a password.
8075 To use the service, you address messages at the buildbot, either
8076 normally (@code{botnickname: status}) or with private messages
8077 (@code{/msg botnickname status}). The buildbot will respond in kind.
8079 Some of the commands currently available:
8081 @table @code
8083 @item list builders
8084 Emit a list of all configured builders
8085 @item status BUILDER
8086 Announce the status of a specific Builder: what it is doing right now.
8087 @item status all
8088 Announce the status of all Builders
8089 @item watch BUILDER
8090 If the given Builder is currently running, wait until the Build is
8091 finished and then announce the results.
8092 @item last BUILDER
8093 Return the results of the last build to run on the given Builder.
8094 @item join CHANNEL
8095 Join the given IRC channel
8096 @item leave CHANNEL
8097 Leave the given IRC channel
8098 @item notify on|off|list EVENT
8099 Report events relating to builds.  If the command is issued as a
8100 private message, then the report will be sent back as a private
8101 message to the user who issued the command.  Otherwise, the report
8102 will be sent to the channel.  Available events to be notified are:
8104 @table @code
8105 @item started
8106 A build has started
8107 @item finished
8108 A build has finished
8109 @item success
8110 A build finished successfully
8111 @item failed
8112 A build failed
8113 @item exception
8114 A build generated and exception
8115 @item xToY
8116 The previous build was x, but this one is Y, where x and Y are each
8117 one of success, warnings, failure, exception (except Y is
8118 capitalized).  For example: successToFailure will notify if the
8119 previous build was successful, but this one failed
8120 @end table
8122 @item help COMMAND
8123 Describe a command. Use @code{help commands} to get a list of known
8124 commands.
8125 @item source
8126 Announce the URL of the Buildbot's home page.
8127 @item version
8128 Announce the version of this Buildbot.
8129 @end table
8131 Additionally, the config file may specify default notification options
8132 as shown in the example earlier.
8134 If the @code{allowForce=True} option was used, some addtional commands
8135 will be available:
8137 @table @code
8138 @item force build BUILDER REASON
8139 Tell the given Builder to start a build of the latest code. The user
8140 requesting the build and REASON are recorded in the Build status. The
8141 buildbot will announce the build's status when it finishes.
8143 @item stop build BUILDER REASON
8144 Terminate any running build in the given Builder. REASON will be added
8145 to the build status to explain why it was stopped. You might use this
8146 if you committed a bug, corrected it right away, and don't want to
8147 wait for the first build (which is destined to fail) to complete
8148 before starting the second (hopefully fixed) build.
8149 @end table
8151 @node PBListener, Writing New Status Plugins, IRC Bot, Status Delivery
8152 @section PBListener
8154 @cindex PBListener
8155 @stindex buildbot.status.client.PBListener
8158 @example
8159 import buildbot.status.client
8160 pbl = buildbot.status.client.PBListener(port=int, user=str,
8161                                         passwd=str)
8162 c['status'].append(pbl)
8163 @end example
8165 This sets up a PB listener on the given TCP port, to which a PB-based
8166 status client can connect and retrieve status information.
8167 @code{buildbot statusgui} (@pxref{statusgui}) is an example of such a
8168 status client. The @code{port} argument can also be a strports
8169 specification string.
8171 @node Writing New Status Plugins,  , PBListener, Status Delivery
8172 @section Writing New Status Plugins
8174 TODO: this needs a lot more examples
8176 Each status plugin is an object which provides the
8177 @code{twisted.application.service.IService} interface, which creates a
8178 tree of Services with the buildmaster at the top [not strictly true].
8179 The status plugins are all children of an object which implements
8180 @code{buildbot.interfaces.IStatus}, the main status object. From this
8181 object, the plugin can retrieve anything it wants about current and
8182 past builds. It can also subscribe to hear about new and upcoming
8183 builds.
8185 Status plugins which only react to human queries (like the Waterfall
8186 display) never need to subscribe to anything: they are idle until
8187 someone asks a question, then wake up and extract the information they
8188 need to answer it, then they go back to sleep. Plugins which need to
8189 act spontaneously when builds complete (like the MailNotifier plugin)
8190 need to subscribe to hear about new builds.
8192 If the status plugin needs to run network services (like the HTTP
8193 server used by the Waterfall plugin), they can be attached as Service
8194 children of the plugin itself, using the @code{IServiceCollection}
8195 interface.
8199 @node Command-line tool, Resources, Status Delivery, Top
8200 @chapter Command-line tool
8202 The @command{buildbot} command-line tool can be used to start or stop a
8203 buildmaster or buildbot, and to interact with a running buildmaster.
8204 Some of its subcommands are intended for buildmaster admins, while
8205 some are for developers who are editing the code that the buildbot is
8206 monitoring.
8208 @menu
8209 * Administrator Tools::
8210 * Developer Tools::
8211 * Other Tools::
8212 * .buildbot config directory::
8213 @end menu
8215 @node Administrator Tools, Developer Tools, Command-line tool, Command-line tool
8216 @section Administrator Tools
8218 The following @command{buildbot} sub-commands are intended for
8219 buildmaster administrators:
8221 @heading create-master
8223 This creates a new directory and populates it with files that allow it
8224 to be used as a buildmaster's base directory.
8226 @example
8227 buildbot create-master BASEDIR
8228 @end example
8230 @heading create-slave
8232 This creates a new directory and populates it with files that let it
8233 be used as a buildslave's base directory. You must provide several
8234 arguments, which are used to create the initial @file{buildbot.tac}
8235 file.
8237 @example
8238 buildbot create-slave @var{BASEDIR} @var{MASTERHOST}:@var{PORT} @var{SLAVENAME} @var{PASSWORD}
8239 @end example
8241 @heading start
8243 This starts a buildmaster or buildslave which was already created in
8244 the given base directory. The daemon is launched in the background,
8245 with events logged to a file named @file{twistd.log}.
8247 @example
8248 buildbot start BASEDIR
8249 @end example
8251 @heading stop
8253 This terminates the daemon (either buildmaster or buildslave) running
8254 in the given directory.
8256 @example
8257 buildbot stop BASEDIR
8258 @end example
8260 @heading sighup
8262 This sends a SIGHUP to the buildmaster running in the given directory,
8263 which causes it to re-read its @file{master.cfg} file.
8265 @example
8266 buildbot sighup BASEDIR
8267 @end example
8269 @node Developer Tools, Other Tools, Administrator Tools, Command-line tool
8270 @section Developer Tools
8272 These tools are provided for use by the developers who are working on
8273 the code that the buildbot is monitoring.
8275 @menu
8276 * statuslog::
8277 * statusgui::
8278 * try::
8279 @end menu
8281 @node statuslog, statusgui, Developer Tools, Developer Tools
8282 @subsection statuslog
8284 @example
8285 buildbot statuslog --master @var{MASTERHOST}:@var{PORT}
8286 @end example
8288 This command starts a simple text-based status client, one which just
8289 prints out a new line each time an event occurs on the buildmaster.
8291 The @option{--master} option provides the location of the
8292 @code{buildbot.status.client.PBListener} status port, used to deliver
8293 build information to realtime status clients. The option is always in
8294 the form of a string, with hostname and port number separated by a
8295 colon (@code{HOSTNAME:PORTNUM}). Note that this port is @emph{not} the
8296 same as the slaveport (although a future version may allow the same
8297 port number to be used for both purposes). If you get an error message
8298 to the effect of ``Failure: twisted.cred.error.UnauthorizedLogin:'',
8299 this may indicate that you are connecting to the slaveport rather than
8300 a @code{PBListener} port.
8302 The @option{--master} option can also be provided by the
8303 @code{masterstatus} name in @file{.buildbot/options} (@pxref{.buildbot
8304 config directory}).
8306 @node statusgui, try, statuslog, Developer Tools
8307 @subsection statusgui
8309 @cindex statusgui
8311 If you have set up a PBListener (@pxref{PBListener}), you will be able
8312 to monitor your Buildbot using a simple Gtk+ application invoked with
8313 the @code{buildbot statusgui} command:
8315 @example
8316 buildbot statusgui --master @var{MASTERHOST}:@var{PORT}
8317 @end example
8319 This command starts a simple Gtk+-based status client, which contains
8320 a few boxes for each Builder that change color as events occur. It
8321 uses the same @option{--master} argument as the @command{buildbot
8322 statuslog} command (@pxref{statuslog}).
8324 @node try,  , statusgui, Developer Tools
8325 @subsection try
8327 This lets a developer to ask the question ``What would happen if I
8328 committed this patch right now?''. It runs the unit test suite (across
8329 multiple build platforms) on the developer's current code, allowing
8330 them to make sure they will not break the tree when they finally
8331 commit their changes.
8333 The @command{buildbot try} command is meant to be run from within a
8334 developer's local tree, and starts by figuring out the base revision
8335 of that tree (what revision was current the last time the tree was
8336 updated), and a patch that can be applied to that revision of the tree
8337 to make it match the developer's copy. This (revision, patch) pair is
8338 then sent to the buildmaster, which runs a build with that
8339 SourceStamp. If you want, the tool will emit status messages as the
8340 builds run, and will not terminate until the first failure has been
8341 detected (or the last success).
8343 There is an alternate form which accepts a pre-made patch file
8344 (typically the output of a command like 'svn diff'). This ``--diff''
8345 form does not require a local tree to run from. See @xref{try --diff}.
8347 For this command to work, several pieces must be in place:
8350 @heading TryScheduler
8352 @slindex buildbot.scheduler.Try_Jobdir
8353 @slindex buildbot.scheduler.Try_Userpass
8355 The buildmaster must have a @code{scheduler.Try} instance in
8356 the config file's @code{c['schedulers']} list. This lets the
8357 administrator control who may initiate these ``trial'' builds, which
8358 branches are eligible for trial builds, and which Builders should be
8359 used for them.
8361 The @code{TryScheduler} has various means to accept build requests:
8362 all of them enforce more security than the usual buildmaster ports do.
8363 Any source code being built can be used to compromise the buildslave
8364 accounts, but in general that code must be checked out from the VC
8365 repository first, so only people with commit privileges can get
8366 control of the buildslaves. The usual force-build control channels can
8367 waste buildslave time but do not allow arbitrary commands to be
8368 executed by people who don't have those commit privileges. However,
8369 the source code patch that is provided with the trial build does not
8370 have to go through the VC system first, so it is important to make
8371 sure these builds cannot be abused by a non-committer to acquire as
8372 much control over the buildslaves as a committer has. Ideally, only
8373 developers who have commit access to the VC repository would be able
8374 to start trial builds, but unfortunately the buildmaster does not, in
8375 general, have access to VC system's user list.
8377 As a result, the @code{TryScheduler} requires a bit more
8378 configuration. There are currently two ways to set this up:
8380 @table @strong
8381 @item jobdir (ssh)
8383 This approach creates a command queue directory, called the
8384 ``jobdir'', in the buildmaster's working directory. The buildmaster
8385 admin sets the ownership and permissions of this directory to only
8386 grant write access to the desired set of developers, all of whom must
8387 have accounts on the machine. The @code{buildbot try} command creates
8388 a special file containing the source stamp information and drops it in
8389 the jobdir, just like a standard maildir. When the buildmaster notices
8390 the new file, it unpacks the information inside and starts the builds.
8392 The config file entries used by 'buildbot try' either specify a local
8393 queuedir (for which write and mv are used) or a remote one (using scp
8394 and ssh).
8396 The advantage of this scheme is that it is quite secure, the
8397 disadvantage is that it requires fiddling outside the buildmaster
8398 config (to set the permissions on the jobdir correctly). If the
8399 buildmaster machine happens to also house the VC repository, then it
8400 can be fairly easy to keep the VC userlist in sync with the
8401 trial-build userlist. If they are on different machines, this will be
8402 much more of a hassle. It may also involve granting developer accounts
8403 on a machine that would not otherwise require them.
8405 To implement this, the buildslave invokes 'ssh -l username host
8406 buildbot tryserver ARGS', passing the patch contents over stdin. The
8407 arguments must include the inlet directory and the revision
8408 information.
8410 @item user+password (PB)
8412 In this approach, each developer gets a username/password pair, which
8413 are all listed in the buildmaster's configuration file. When the
8414 developer runs @code{buildbot try}, their machine connects to the
8415 buildmaster via PB and authenticates themselves using that username
8416 and password, then sends a PB command to start the trial build.
8418 The advantage of this scheme is that the entire configuration is
8419 performed inside the buildmaster's config file. The disadvantages are
8420 that it is less secure (while the ``cred'' authentication system does
8421 not expose the password in plaintext over the wire, it does not offer
8422 most of the other security properties that SSH does). In addition, the
8423 buildmaster admin is responsible for maintaining the username/password
8424 list, adding and deleting entries as developers come and go.
8426 @end table
8429 For example, to set up the ``jobdir'' style of trial build, using a
8430 command queue directory of @file{MASTERDIR/jobdir} (and assuming that
8431 all your project developers were members of the @code{developers} unix
8432 group), you would first create that directory (with @command{mkdir
8433 MASTERDIR/jobdir MASTERDIR/jobdir/new MASTERDIR/jobdir/cur
8434 MASTERDIR/jobdir/tmp; chgrp developers MASTERDIR/jobdir
8435 MASTERDIR/jobdir/*; chmod g+rwx,o-rwx MASTERDIR/jobdir
8436 MASTERDIR/jobdir/*}), and then use the following scheduler in the
8437 buildmaster's config file:
8439 @example
8440 from buildbot.scheduler import Try_Jobdir
8441 s = Try_Jobdir("try1", ["full-linux", "full-netbsd", "full-OSX"],
8442                jobdir="jobdir")
8443 c['schedulers'] = [s]
8444 @end example
8446 Note that you must create the jobdir before telling the buildmaster to
8447 use this configuration, otherwise you will get an error. Also remember
8448 that the buildmaster must be able to read and write to the jobdir as
8449 well. Be sure to watch the @file{twistd.log} file (@pxref{Logfiles})
8450 as you start using the jobdir, to make sure the buildmaster is happy
8451 with it.
8453 To use the username/password form of authentication, create a
8454 @code{Try_Userpass} instance instead. It takes the same
8455 @code{builderNames} argument as the @code{Try_Jobdir} form, but
8456 accepts an addtional @code{port} argument (to specify the TCP port to
8457 listen on) and a @code{userpass} list of username/password pairs to
8458 accept. Remember to use good passwords for this: the security of the
8459 buildslave accounts depends upon it:
8461 @example
8462 from buildbot.scheduler import Try_Userpass
8463 s = Try_Userpass("try2", ["full-linux", "full-netbsd", "full-OSX"],
8464                  port=8031, userpass=[("alice","pw1"), ("bob", "pw2")] )
8465 c['schedulers'] = [s]
8466 @end example
8468 Like most places in the buildbot, the @code{port} argument takes a
8469 strports specification. See @code{twisted.application.strports} for
8470 details.
8473 @heading locating the master
8475 The @command{try} command needs to be told how to connect to the
8476 @code{TryScheduler}, and must know which of the authentication
8477 approaches described above is in use by the buildmaster. You specify
8478 the approach by using @option{--connect=ssh} or @option{--connect=pb}
8479 (or @code{try_connect = 'ssh'} or @code{try_connect = 'pb'} in
8480 @file{.buildbot/options}).
8482 For the PB approach, the command must be given a @option{--master}
8483 argument (in the form HOST:PORT) that points to TCP port that you
8484 picked in the @code{Try_Userpass} scheduler. It also takes a
8485 @option{--username} and @option{--passwd} pair of arguments that match
8486 one of the entries in the buildmaster's @code{userpass} list. These
8487 arguments can also be provided as @code{try_master},
8488 @code{try_username}, and @code{try_password} entries in the
8489 @file{.buildbot/options} file.
8491 For the SSH approach, the command must be given @option{--tryhost},
8492 @option{--username}, and optionally @option{--password} (TODO:
8493 really?) to get to the buildmaster host. It must also be given
8494 @option{--trydir}, which points to the inlet directory configured
8495 above. The trydir can be relative to the user's home directory, but
8496 most of the time you will use an explicit path like
8497 @file{~buildbot/project/trydir}. These arguments can be provided in
8498 @file{.buildbot/options} as @code{try_host}, @code{try_username},
8499 @code{try_password}, and @code{try_dir}.
8501 In addition, the SSH approach needs to connect to a PBListener status
8502 port, so it can retrieve and report the results of the build (the PB
8503 approach uses the existing connection to retrieve status information,
8504 so this step is not necessary). This requires a @option{--master}
8505 argument, or a @code{masterstatus} entry in @file{.buildbot/options},
8506 in the form of a HOSTNAME:PORT string.
8509 @heading choosing the Builders
8511 A trial build is performed on multiple Builders at the same time, and
8512 the developer gets to choose which Builders are used (limited to a set
8513 selected by the buildmaster admin with the TryScheduler's
8514 @code{builderNames=} argument). The set you choose will depend upon
8515 what your goals are: if you are concerned about cross-platform
8516 compatibility, you should use multiple Builders, one from each
8517 platform of interest. You might use just one builder if that platform
8518 has libraries or other facilities that allow better test coverage than
8519 what you can accomplish on your own machine, or faster test runs.
8521 The set of Builders to use can be specified with multiple
8522 @option{--builder} arguments on the command line. It can also be
8523 specified with a single @code{try_builders} option in
8524 @file{.buildbot/options} that uses a list of strings to specify all
8525 the Builder names:
8527 @example
8528 try_builders = ["full-OSX", "full-win32", "full-linux"]
8529 @end example
8531 @heading specifying the VC system
8533 The @command{try} command also needs to know how to take the
8534 developer's current tree and extract the (revision, patch)
8535 source-stamp pair. Each VC system uses a different process, so you
8536 start by telling the @command{try} command which VC system you are
8537 using, with an argument like @option{--vc=cvs} or @option{--vc=tla}.
8538 This can also be provided as @code{try_vc} in
8539 @file{.buildbot/options}.
8541 The following names are recognized: @code{cvs} @code{svn} @code{baz}
8542 @code{tla} @code{hg} @code{darcs}
8545 @heading finding the top of the tree
8547 Some VC systems (notably CVS and SVN) track each directory
8548 more-or-less independently, which means the @command{try} command
8549 needs to move up to the top of the project tree before it will be able
8550 to construct a proper full-tree patch. To accomplish this, the
8551 @command{try} command will crawl up through the parent directories
8552 until it finds a marker file. The default name for this marker file is
8553 @file{.buildbot-top}, so when you are using CVS or SVN you should
8554 @code{touch .buildbot-top} from the top of your tree before running
8555 @command{buildbot try}. Alternatively, you can use a filename like
8556 @file{ChangeLog} or @file{README}, since many projects put one of
8557 these files in their top-most directory (and nowhere else). To set
8558 this filename, use @option{--try-topfile=ChangeLog}, or set it in the
8559 options file with @code{try_topfile = 'ChangeLog'}.
8561 You can also manually set the top of the tree with
8562 @option{--try-topdir=~/trees/mytree}, or @code{try_topdir =
8563 '~/trees/mytree'}. If you use @code{try_topdir}, in a
8564 @file{.buildbot/options} file, you will need a separate options file
8565 for each tree you use, so it may be more convenient to use the
8566 @code{try_topfile} approach instead.
8568 Other VC systems which work on full projects instead of individual
8569 directories (tla, baz, darcs, monotone, mercurial, git) do not require
8570 @command{try} to know the top directory, so the @option{--try-topfile}
8571 and @option{--try-topdir} arguments will be ignored.
8572 @c is this true? I think I currently require topdirs all the time.
8574 If the @command{try} command cannot find the top directory, it will
8575 abort with an error message.
8577 @heading determining the branch name
8579 Some VC systems record the branch information in a way that ``try''
8580 can locate it, in particular Arch (both @command{tla} and
8581 @command{baz}). For the others, if you are using something other than
8582 the default branch, you will have to tell the buildbot which branch
8583 your tree is using. You can do this with either the @option{--branch}
8584 argument, or a @option{try_branch} entry in the
8585 @file{.buildbot/options} file.
8587 @heading determining the revision and patch
8589 Each VC system has a separate approach for determining the tree's base
8590 revision and computing a patch.
8592 @table @code
8594 @item CVS
8596 @command{try} pretends that the tree is up to date. It converts the
8597 current time into a @code{-D} time specification, uses it as the base
8598 revision, and computes the diff between the upstream tree as of that
8599 point in time versus the current contents. This works, more or less,
8600 but requires that the local clock be in reasonably good sync with the
8601 repository.
8603 @item SVN
8604 @command{try} does a @code{svn status -u} to find the latest
8605 repository revision number (emitted on the last line in the ``Status
8606 against revision: NN'' message). It then performs an @code{svn diff
8607 -rNN} to find out how your tree differs from the repository version,
8608 and sends the resulting patch to the buildmaster. If your tree is not
8609 up to date, this will result in the ``try'' tree being created with
8610 the latest revision, then @emph{backwards} patches applied to bring it
8611 ``back'' to the version you actually checked out (plus your actual
8612 code changes), but this will still result in the correct tree being
8613 used for the build.
8615 @item baz
8616 @command{try} does a @code{baz tree-id} to determine the
8617 fully-qualified version and patch identifier for the tree
8618 (ARCHIVE/VERSION--patch-NN), and uses the VERSION--patch-NN component
8619 as the base revision. It then does a @code{baz diff} to obtain the
8620 patch.
8622 @item tla
8623 @command{try} does a @code{tla tree-version} to get the
8624 fully-qualified version identifier (ARCHIVE/VERSION), then takes the
8625 first line of @code{tla logs --reverse} to figure out the base
8626 revision. Then it does @code{tla changes --diffs} to obtain the patch.
8628 @item Darcs
8629 @code{darcs changes --context} emits a text file that contains a list
8630 of all patches back to and including the last tag was made. This text
8631 file (plus the location of a repository that contains all these
8632 patches) is sufficient to re-create the tree. Therefore the contents
8633 of this ``context'' file @emph{are} the revision stamp for a
8634 Darcs-controlled source tree.
8636 So @command{try} does a @code{darcs changes --context} to determine
8637 what your tree's base revision is, and then does a @code{darcs diff
8638 -u} to compute the patch relative to that revision.
8640 @item Mercurial
8641 @code{hg identify} emits a short revision ID (basically a truncated
8642 SHA1 hash of the current revision's contents), which is used as the
8643 base revision. @code{hg diff} then provides the patch relative to that
8644 revision. For @command{try} to work, your working directory must only
8645 have patches that are available from the same remotely-available
8646 repository that the build process' @code{step.Mercurial} will use.
8648 @item Git
8649 @code{git branch -v} lists all the branches available in the local
8650 repository along with the revision ID it points to and a short summary
8651 of the last commit. The line containing the currently checked out
8652 branch begins with '* ' (star and space) while all the others start
8653 with '  ' (two spaces). @command{try} scans for this line and extracts
8654 the branch name and revision from it. Then it generates a diff against
8655 the base revision.
8656 @c TODO: I'm not sure if this actually works the way it's intended
8657 @c since the extracted base revision might not actually exist in the
8658 @c upstream repository. Perhaps we need to add a --remote option to
8659 @c specify the remote tracking branch to generate a diff against.
8661 @c TODO: monotone
8662 @end table
8664 @heading waiting for results
8666 If you provide the @option{--wait} option (or @code{try_wait = True}
8667 in @file{.buildbot/options}), the @command{buildbot try} command will
8668 wait until your changes have either been proven good or bad before
8669 exiting. Unless you use the @option{--quiet} option (or
8670 @code{try_quiet=True}), it will emit a progress message every 60
8671 seconds until the builds have completed.
8673 @menu
8674 * try --diff::
8675 @end menu
8677 @node try --diff,  , try, try
8678 @subsubsection try --diff
8680 Sometimes you might have a patch from someone else that you want to
8681 submit to the buildbot. For example, a user may have created a patch
8682 to fix some specific bug and sent it to you by email. You've inspected
8683 the patch and suspect that it might do the job (and have at least
8684 confirmed that it doesn't do anything evil). Now you want to test it
8685 out.
8687 One approach would be to check out a new local tree, apply the patch,
8688 run your local tests, then use ``buildbot try'' to run the tests on
8689 other platforms. An alternate approach is to use the @command{buildbot
8690 try --diff} form to have the buildbot test the patch without using a
8691 local tree.
8693 This form takes a @option{--diff} argument which points to a file that
8694 contains the patch you want to apply. By default this patch will be
8695 applied to the TRUNK revision, but if you give the optional
8696 @option{--baserev} argument, a tree of the given revision will be used
8697 as a starting point instead of TRUNK.
8699 You can also use @command{buildbot try --diff=-} to read the patch
8700 from stdin.
8702 Each patch has a ``patchlevel'' associated with it. This indicates the
8703 number of slashes (and preceding pathnames) that should be stripped
8704 before applying the diff. This exactly corresponds to the @option{-p}
8705 or @option{--strip} argument to the @command{patch} utility. By
8706 default @command{buildbot try --diff} uses a patchlevel of 0, but you
8707 can override this with the @option{-p} argument.
8709 When you use @option{--diff}, you do not need to use any of the other
8710 options that relate to a local tree, specifically @option{--vc},
8711 @option{--try-topfile}, or @option{--try-topdir}. These options will
8712 be ignored. Of course you must still specify how to get to the
8713 buildmaster (with @option{--connect}, @option{--tryhost}, etc).
8716 @node Other Tools, .buildbot config directory, Developer Tools, Command-line tool
8717 @section Other Tools
8719 These tools are generally used by buildmaster administrators.
8721 @menu
8722 * sendchange::
8723 * debugclient::
8724 @end menu
8726 @node sendchange, debugclient, Other Tools, Other Tools
8727 @subsection sendchange
8729 This command is used to tell the buildmaster about source changes. It
8730 is intended to be used from within a commit script, installed on the
8731 VC server. It requires that you have a PBChangeSource
8732 (@pxref{PBChangeSource}) running in the buildmaster (by being set in
8733 @code{c['change_source']}).
8736 @example
8737 buildbot sendchange --master @var{MASTERHOST}:@var{PORT} --username @var{USER} @var{FILENAMES..}
8738 @end example
8740 There are other (optional) arguments which can influence the
8741 @code{Change} that gets submitted:
8743 @table @code
8744 @item --branch
8745 This provides the (string) branch specifier. If omitted, it defaults
8746 to None, indicating the ``default branch''. All files included in this
8747 Change must be on the same branch.
8749 @item --category
8750 This provides the (string) category specifier. If omitted, it defaults
8751 to None, indicating ``no category''. The category property is used
8752 by Schedulers to filter what changes they listen to.
8754 @item --revision_number
8755 This provides a (numeric) revision number for the change, used for VC systems
8756 that use numeric transaction numbers (like Subversion).
8758 @item --revision
8759 This provides a (string) revision specifier, for VC systems that use
8760 strings (Arch would use something like patch-42 etc).
8762 @item --revision_file
8763 This provides a filename which will be opened and the contents used as
8764 the revision specifier. This is specifically for Darcs, which uses the
8765 output of @command{darcs changes --context} as a revision specifier.
8766 This context file can be a couple of kilobytes long, spanning a couple
8767 lines per patch, and would be a hassle to pass as a command-line
8768 argument.
8770 @item --comments
8771 This provides the change comments as a single argument. You may want
8772 to use @option{--logfile} instead.
8774 @item --logfile
8775 This instructs the tool to read the change comments from the given
8776 file. If you use @code{-} as the filename, the tool will read the
8777 change comments from stdin.
8778 @end table
8781 @node debugclient,  , sendchange, Other Tools
8782 @subsection debugclient
8784 @example
8785 buildbot debugclient --master @var{MASTERHOST}:@var{PORT} --passwd @var{DEBUGPW}
8786 @end example
8788 This launches a small Gtk+/Glade-based debug tool, connecting to the
8789 buildmaster's ``debug port''. This debug port shares the same port
8790 number as the slaveport (@pxref{Setting the slaveport}), but the
8791 @code{debugPort} is only enabled if you set a debug password in the
8792 buildmaster's config file (@pxref{Debug options}). The
8793 @option{--passwd} option must match the @code{c['debugPassword']}
8794 value.
8796 @option{--master} can also be provided in @file{.debug/options} by the
8797 @code{master} key. @option{--passwd} can be provided by the
8798 @code{debugPassword} key.
8800 The @code{Connect} button must be pressed before any of the other
8801 buttons will be active. This establishes the connection to the
8802 buildmaster. The other sections of the tool are as follows:
8804 @table @code
8805 @item Reload .cfg
8806 Forces the buildmaster to reload its @file{master.cfg} file. This is
8807 equivalent to sending a SIGHUP to the buildmaster, but can be done
8808 remotely through the debug port. Note that it is a good idea to be
8809 watching the buildmaster's @file{twistd.log} as you reload the config
8810 file, as any errors which are detected in the config file will be
8811 announced there.
8813 @item Rebuild .py
8814 (not yet implemented). The idea here is to use Twisted's ``rebuild''
8815 facilities to replace the buildmaster's running code with a new
8816 version. Even if this worked, it would only be used by buildbot
8817 developers.
8819 @item poke IRC
8820 This locates a @code{words.IRC} status target and causes it to emit a
8821 message on all the channels to which it is currently connected. This
8822 was used to debug a problem in which the buildmaster lost the
8823 connection to the IRC server and did not attempt to reconnect.
8825 @item Commit
8826 This allows you to inject a Change, just as if a real one had been
8827 delivered by whatever VC hook you are using. You can set the name of
8828 the committed file and the name of the user who is doing the commit.
8829 Optionally, you can also set a revision for the change. If the
8830 revision you provide looks like a number, it will be sent as an
8831 integer, otherwise it will be sent as a string.
8833 @item Force Build
8834 This lets you force a Builder (selected by name) to start a build of
8835 the current source tree.
8837 @item Currently
8838 (obsolete). This was used to manually set the status of the given
8839 Builder, but the status-assignment code was changed in an incompatible
8840 way and these buttons are no longer meaningful.
8842 @end table
8845 @node .buildbot config directory,  , Other Tools, Command-line tool
8846 @section .buildbot config directory
8848 Many of the @command{buildbot} tools must be told how to contact the
8849 buildmaster that they interact with. This specification can be
8850 provided as a command-line argument, but most of the time it will be
8851 easier to set them in an ``options'' file. The @command{buildbot}
8852 command will look for a special directory named @file{.buildbot},
8853 starting from the current directory (where the command was run) and
8854 crawling upwards, eventually looking in the user's home directory. It
8855 will look for a file named @file{options} in this directory, and will
8856 evaluate it as a python script, looking for certain names to be set.
8857 You can just put simple @code{name = 'value'} pairs in this file to
8858 set the options.
8860 For a description of the names used in this file, please see the
8861 documentation for the individual @command{buildbot} sub-commands. The
8862 following is a brief sample of what this file's contents could be.
8864 @example
8865 # for status-reading tools
8866 masterstatus = 'buildbot.example.org:12345'
8867 # for 'sendchange' or the debug port
8868 master = 'buildbot.example.org:18990'
8869 debugPassword = 'eiv7Po'
8870 @end example
8872 @table @code
8873 @item masterstatus
8874 Location of the @code{client.PBListener} status port, used by
8875 @command{statuslog} and @command{statusgui}.
8877 @item master
8878 Location of the @code{debugPort} (for @command{debugclient}). Also the
8879 location of the @code{pb.PBChangeSource} (for @command{sendchange}).
8880 Usually shares the slaveport, but a future version may make it
8881 possible to have these listen on a separate port number.
8883 @item debugPassword
8884 Must match the value of @code{c['debugPassword']}, used to protect the
8885 debug port, for the @command{debugclient} command.
8887 @item username
8888 Provides a default username for the @command{sendchange} command.
8890 @end table
8893 The following options are used by the @code{buildbot try} command
8894 (@pxref{try}):
8896 @table @code
8897 @item try_connect
8898 This specifies how the ``try'' command should deliver its request to
8899 the buildmaster. The currently accepted values are ``ssh'' and ``pb''.
8900 @item try_builders
8901 Which builders should be used for the ``try'' build.
8902 @item try_vc
8903 This specifies the version control system being used.
8904 @item try_branch
8905 This indicates that the current tree is on a non-trunk branch.
8906 @item try_topdir
8907 @item try_topfile
8908 Use @code{try_topdir} to explicitly indicate the top of your working
8909 tree, or @code{try_topfile} to name a file that will only be found in
8910 that top-most directory.
8912 @item try_host
8913 @item try_username
8914 @item try_dir
8915 When try_connect is ``ssh'', the command will pay attention to
8916 @code{try_host}, @code{try_username}, and @code{try_dir}.
8918 @item try_username
8919 @item try_password
8920 @item try_master
8921 Instead, when @code{try_connect} is ``pb'', the command will pay
8922 attention to @code{try_username}, @code{try_password}, and
8923 @code{try_master}.
8925 @item try_wait
8926 @item masterstatus
8927 @code{try_wait} and @code{masterstatus} are used to ask the ``try''
8928 command to wait for the requested build to complete.
8930 @end table
8934 @node Resources, Developer's Appendix, Command-line tool, Top
8935 @chapter Resources
8937 The Buildbot home page is @uref{http://buildbot.net/}.
8939 For configuration questions and general discussion, please use the
8940 @code{buildbot-devel} mailing list. The subscription instructions and
8941 archives are available at
8942 @uref{http://lists.sourceforge.net/lists/listinfo/buildbot-devel}
8944 @node Developer's Appendix, Index of Useful Classes, Resources, Top
8945 @unnumbered Developer's Appendix
8947 This appendix contains random notes about the implementation of the
8948 Buildbot, and is likely to only be of use to people intending to
8949 extend the Buildbot's internals.
8951 The buildmaster consists of a tree of Service objects, which is shaped
8952 as follows:
8954 @example
8955 BuildMaster
8956  ChangeMaster  (in .change_svc)
8957   [IChangeSource instances]
8958  [IScheduler instances]  (in .schedulers)
8959  BotMaster  (in .botmaster)
8960   [IBuildSlave instances]
8961  [IStatusTarget instances]  (in .statusTargets)
8962 @end example
8964 The BotMaster has a collection of Builder objects as values of its
8965 @code{.builders} dictionary.
8968 @node Index of Useful Classes, Index of master.cfg keys, Developer's Appendix, Top
8969 @unnumbered Index of Useful Classes
8971 This is a list of all user-visible classes. There are the ones that
8972 are useful in @file{master.cfg}, the buildmaster's configuration file.
8973 Classes that are not listed here are generally internal things that
8974 admins are unlikely to have much use for.
8977 @heading Change Sources
8978 @printindex cs
8980 @heading Schedulers and Locks
8981 @printindex sl
8983 @heading Build Factories
8984 @printindex bf
8986 @heading Build Steps
8987 @printindex bs
8989 @c undocumented steps
8990 @bsindex buildbot.steps.source.Git
8991 @bsindex buildbot.steps.maxq.MaxQ
8994 @heading Status Targets
8995 @printindex st
8997 @c TODO: undocumented targets
8999 @node Index of master.cfg keys, Index, Index of Useful Classes, Top
9000 @unnumbered Index of master.cfg keys
9002 This is a list of all of the significant keys in master.cfg . Recall
9003 that master.cfg is effectively a small python program with exactly one
9004 responsibility: create a dictionary named @code{BuildmasterConfig}.
9005 The keys of this dictionary are listed here. The beginning of the
9006 master.cfg file typically starts with something like:
9008 @example
9009 BuildmasterConfig = c = @{@}
9010 @end example
9012 Therefore a config key of @code{change_source} will usually appear in
9013 master.cfg as @code{c['change_source']}.
9015 @printindex bc
9018 @node Index,  , Index of master.cfg keys, Top
9019 @unnumbered Index
9021 @printindex cp
9024 @bye