mercredi 21 mai 2008

BuildBot tutorial

buildBot is a powerfull tools which allows you to automate your project building and unit tests. Simply put, buildbot use two main programs :
  • the master, which is responsible for detecting change in the code, and define different builders.
  • one or many slaves, which can be run on different computers, and run the builders defined in the master.

1 Installation

buildBot can be easily installed under Debian or Ubuntu with the following command:
#apt-get install buildbot

1.1 Master configuration

It is advised to create a specific user for the master program. As root, run :

# adduser buildbot

Then, create a repository for your master in buildbot user home.

%su buildbot
% cd
% mkdir projectBuildBot

And create the build master :

% buildbot create-master /home/buildmaster/projectBuildRoot

This command has created a file master.cfg.sample. Rename it master.cfg :

% cp master.cfg.sample master.cfg

Now we configure the different sections.

1.1.1 BUILDSLAVES

In this section you can specify the name and the password used by the slaves.

c[’slaves’] = [BuildSlave("project", "password")]
c[’slavePortnum’] = 9989

You can also specify the port used by the slaves to connect to the master server.

1.1.2 SCHEDULERS

In this section, you can create the schedulers used run by the master.

from buildbot.scheduler import Scheduler
c[’schedulers’] = []
c[’schedulers’].append(Scheduler(name="all", branch=None,
treeStableTimer=2*60,
builderNames=["simpleBuild"]))

The scheduler name must be unique. builderNames specify the names of the builders ran by these schedulers. branch=None means that we use the svn trunk.

1.1.3 CHANGESOURCES

In this section, we specify how the project source are fetched. The following example use a svn repository.

from buildbot.changes.pb import PBChangeSource
c[’change_source’] = PBChangeSource()

from buildbot.changes.svnpoller import SVNPoller
c[’change_source’] = SVNPoller("http://my.project.com/svn/trunk/")

1.1.4 BUILDERS

In this section, we create the builders, which are responsible for building the code. The following lines are self-explaining. I simply use scons as a construction tool, but Make or autotools can be used as well.

from buildbot.steps import source, shell
from buildbot.process import factory

f = factory.BuildFactory()
f.addStep(source.SVN(svnurl="http://my.project.com/svn/trunk/"))
f.addStep(shell.ShellCommand(command=["scons"]))

b1 = {’name’: "simpleBuild",
’slavename’: "project",
’builddir’: "full",
’factory’: f,}

c[’builders’] = [b1]

slavename must match the name of one of the slaves defined in BUILDSLAVES section. The buildir field specify in which directory the project will be built.

1.1.5 STATUS TARGETS

This section specifies how the master inform the world of compilation status.

c[’status’] = []

from buildbot.status import html
c[’status’].append(html.WebStatus(http_port=8010))

from buildbot.status import mail
c[’status’].append(mail.MailNotifier(fromaddr="buildbot@localhost",
extraRecipients=["lapin@gmail.com"],
sendToInterestedUsers=False))

That’s all. Once we have done with the master configuration file, we can check its consistence using :

% buildbot checkconfig master.cfg

2 Running

And we start the master :

% buildbot start /home/buildmaster/projectBuildRoot/

Before running the slave, we must create it. It must not necesarry run on the same computer.

% mkdir /path/to/slave/
% buildbot create-slave /path/to/slave MASTERHOST:PORT SLAVENAME PASSWORD

Start the slave :

% buildbot start /path/to/slave/


Ce document a été traduit de LATEX par HEVEA

1 commentaire:

Unknown a dit…

thanks for the clear and succinct tutorial. this certainly helped.