From 5c11ec8afef2f8ac1dca1ff3001f3a3973990af4 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 13 Apr 2014 19:27:22 +0200 Subject: [PATCH] Add a master git+Gerrit configuration sample --- master/docs/examples/git_gerrit.cfg | 230 +++++++++++++++++++++++ master/docs/manual/cfg-changesources.rst | 4 +- 2 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 master/docs/examples/git_gerrit.cfg diff --git a/master/docs/examples/git_gerrit.cfg b/master/docs/examples/git_gerrit.cfg new file mode 100644 index 00000000000..c4c011bae7c --- /dev/null +++ b/master/docs/examples/git_gerrit.cfg @@ -0,0 +1,230 @@ +# -*- python -*- +# ex: set syntax=python: + +# This is a sample buildmaster config file. It must be installed as +# 'master.cfg' in your buildmaster's base directory. + +# This is the dictionary that the buildmaster pays attention to. We also use +# a shorter alias to save typing. +c = BuildmasterConfig = {} + +####### BUILDSLAVES + +# The 'slaves' list defines the set of recognized buildslaves. Each element is +# a BuildSlave object, specifying a unique slave name and password. The same +# slave name and password must be configured on the slave. +from buildbot.buildslave import BuildSlave +c['slaves'] = [BuildSlave("example-slave", "pass")] + +# 'protocols' contains information about protocols which master will use for +# communicating with slaves. +# You must define at least 'port' option that slaves could connect to your master +# with this protocol. +# 'port' must match the value configured into the buildslaves (with their +# --master option) +c['protocols'] = {'pb': {'port': 9989}} + +####### CHANGESOURCES + +# the 'change_source' setting tells the buildmaster how it should find out +# about source code changes. Here we point to the buildbot clone of pyflakes. + +#Gerrit Configuration +gerrit_url = "gerrit.example.com" +gerrit_user = "gerrit" +gerrit_port = "29418" +gerrit_project = "mygerritproject" + +gerrit_repo = "ssh://" + gerrit_user + "@" + gerrit_url + ":" + gerrit_port + "/" + gerrit_project + +#Add comment-added to handled_events to have approvals information (Code-Review...) +from buildbot.changes.gerritchangesource import GerritChangeSource +c['change_source'] = GerritChangeSource(gerrit_url, gerrit_user, + handled_events=["patchset-created", "comment-added"] + ) + +####### SCHEDULERS + +# Configure the Schedulers, which decide how to react to incoming changes. In this +# case, just kick off a 'runtests' build + +from buildbot.schedulers.basic import SingleBranchScheduler +from buildbot.schedulers.forcesched import ForceScheduler +from buildbot.changes import filter + +#Check there is Code-Review=+2 in Approvals (of comment-added) + +def change_code_review_plus_2(change): + if "event.approvals" in change.properties: + for a in change.properties["event.approvals"]: + if "Code-Review" in a["type"] and "2" in a["value"]: + return True + return False + + +c['schedulers'] = [] +c['schedulers'].append(SingleBranchScheduler( + name="all", + change_filter=filter.ChangeFilter(branch_re="master/*", filter_fn=change_code_review_plus_2), + treeStableTimer=None, + builderNames=["runtests-gcc","runtests-clang"])) +c['schedulers'].append(ForceScheduler( + name="force", + builderNames=["runtests-gcc","runtests-clang"])) + +####### BUILDERS + +# The 'builders' list defines the Builders, which tell Buildbot how to perform a build: +# what steps, and which slaves can execute them. Note that any particular build will +# only take place on one slave. + +from buildbot.process.factory import BuildFactory +#from buildbot.steps.source.git import Git +from buildbot.steps.source.gerrit import Gerrit +from buildbot.steps.shell import ShellCommand +from buildbot.steps.shell import Compile +from buildbot.steps.shell import Configure + +#Build with GCC +f_gcc = BuildFactory() +f_gcc.addStep(Gerrit(repourl=gerrit_repo, mode="full",retry=[60,60],timeout=3600)) +f_gcc.addStep(ShellCommand(command=["bash","./autogen.sh"],timeout=3600)) +f_gcc.addStep(Configure(command=["./configure"])) +f_gcc.addStep(Compile(command=["make", "-j", "4"])) +f_gcc.addStep(Compile(command=["make", "test"])) + +#Build with Clang +f_clang = BuildFactory() +f_clang.addStep(Gerrit(repourl=gerrit_repo, mode="full",retry=[60,60],timeout=3600)) +f_clang.addStep(ShellCommand(command=["bash","./autogen.sh"],timeout=3600)) +f_clang.addStep(Configure(command=["./configure"],env={ "CC":"clang", "CXX":"clang++"})) +f_clang.addStep(Compile(command=["make", "-j", "4"])) +f_clang.addStep(Compile(command=["make", "test"])) + +from buildbot.config import BuilderConfig + +c['builders'] = [] +c['builders'].append( + BuilderConfig(name="runtests-gcc", + slavenames=["example-slave"], + factory=f_gcc)) + +c['builders'].append( + BuilderConfig(name="runtests-clang", + slavenames=["example-slave"], + factory=f_clang)) + + +####### STATUS TARGETS + +# 'status' is a list of Status Targets. The results of each build will be +# pushed to these targets. buildbot/status/*.py has a variety to choose from, +# including web pages, email senders, and IRC bots. + +c['status'] = [] + +from buildbot.status import html +from buildbot.status.web import authz, auth + +authz_cfg=authz.Authz( + # change any of these to True to enable; see the manual for more + # options + auth=auth.BasicAuth([("pyflakes","pyflakes")]), + gracefulShutdown = False, + forceBuild = 'auth', # use this to test your slave once it is set up + forceAllBuilds = False, + pingBuilder = False, + stopBuild = False, + stopAllBuilds = False, + cancelPendingBuild = False, +) +c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg)) + +from buildbot.status.status_gerrit import GerritStatusPush +from buildbot.status.builder import Results, SUCCESS, RETRY + +def gerritReviewCB(builderName, build, result, status, arg): + if result == RETRY: + return None, 0, 0 + + message = "Buildbot finished compiling your patchset\n" + message += "on configuration: %s\n" % builderName + message += "The result is: %s\n" % Results[result].upper() + + if arg: + message += "\nFor more details visit:\n" + message += status.getURLForThing(build) + "\n" + + # message, verified, reviewed + return message, (result == SUCCESS or -1), 0 + +def gerritStartCB(builderName, build, arg): + print "gerritStartCB..." + message = "Buildbot started compiling your patchset\n" + message += "on configuration: %s\n" % builderName + + return message + +def gerritSummaryCB(buildInfoList, results, status, arg): + success = False + failure = False + + msgs = [] + + for buildInfo in buildInfoList: + msg = "Builder %(name)s %(resultText)s (%(text)s)" % buildInfo + link = buildInfo.get('url', None) + if link: + msg += " - " + link + else: + msg += "." + msgs.append(msg) + + if buildInfo['result'] == SUCCESS: + success = True + else: + failure = True + + msg = '\n\n'.join(msgs) + + if success and not failure: + verified = 1 + else: + verified = -1 + + reviewed = 0 + return (msg, verified, reviewed) + +c['buildbotURL'] = 'http://buildbot.example.com/' +c['status'].append(GerritStatusPush(gerrit_url, gerrit_user, + reviewCB=gerritReviewCB, + reviewArg=c['buildbotURL'], + startCB=gerritStartCB, + startArg=c['buildbotURL'], + summaryCB=gerritSummaryCB, + summaryArg=c['buildbotURL'])) + +####### PROJECT IDENTITY + +# the 'title' string will appear at the top of this buildbot +# installation's html.WebStatus home page (linked to the +# 'titleURL') and is embedded in the title of the waterfall HTML page. + +c['title'] = "Buildbot with Gerrit" +c['titleURL'] = "https://" + gerrit_url + +# the 'buildbotURL' string should point to the location where the buildbot's +# internal web server (usually the html.WebStatus page) is visible. This +# typically uses the port number set in the Waterfall 'status' entry, but +# with an externally-visible host name which the buildbot cannot figure out +# without some help. + +c['buildbotURL'] = "http://localhost:8010/" + +####### DB URL + +c['db'] = { + # This specifies what database buildbot uses to store its state. You can leave + # this at its default for all but the largest installations. + 'db_url' : "sqlite:///state.sqlite", +} diff --git a/master/docs/manual/cfg-changesources.rst b/master/docs/manual/cfg-changesources.rst index 82b1480e42d..724f8cec490 100644 --- a/master/docs/manual/cfg-changesources.rst +++ b/master/docs/manual/cfg-changesources.rst @@ -1267,8 +1267,8 @@ A configuration for this source might look like:: "gerrit_user", handled_events=["patchset-created", "change-merged"]) -see :file:`master/docs/examples/repo_gerrit.cfg` in the Buildbot distribution -for a full example setup of :bb:chsrc:`GerritChangeSource`. +see :file:`master/docs/examples/git_gerrit.cfg` or :file:`master/docs/examples/repo_gerrit.cfg` in the Buildbot distribution +for a full example setup of Git+Gerrit or Repo+Gerrit of :bb:chsrc:`GerritChangeSource`. .. bb:chsrc:: Change Hooks