SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
НазадМетки: buildbot
The GerritChangeSource class connects to a Gerrit server by its SSH interface and uses its event source mechanism, gerrit stream-events.
Note that the Gerrit event stream is stateless and any events that occur while buildbot is not connected to Gerrit will be lost. See GerritEventLogPoller for a stateful change source.
The patchset-created and ref-updated events will be deduplicated, that is, if multiple events related to the same revision are received, only the first will be acted upon. This allows GerritChangeSource to be used together with GerritEventLogPoller.
The GerritChangeSource accepts the following arguments:
gerritserverThe dns or ip that host the Gerrit ssh server
gerritportThe port of the Gerrit ssh server
usernameThe username to use to connect to Gerrit
identity_fileSsh identity file to for authentication (optional). Pay attention to the ssh passphrase
handled_eventsEvent to be handled (optional). By default processes patchset-created and ref-updated
get_filesPopulate the files attribute of emitted changes (default False). Buildbot will run an extra query command for each handled event to determine the changed files.
debugPrint Gerrit event in the log (default False). This allows to debug event content, but will eventually fill your logs with useless Gerrit event logs.
By default this class adds a change to the Buildbot system for each of the following events:
patchset-createdA change is proposed for review. Automatic checks like checkpatch.pl can be automatically triggered. Beware of what kind of automatic task you trigger. At this point, no trusted human has reviewed the code, and a patch could be specially crafted by an attacker to compromise your workers.
ref-updatedA change has been merged into the repository. Typically, this kind of event can lead to a complete rebuild of the project, and upload binaries to an incremental build results server.
But you can specify how to handle events:
Any event with change and patchSet will be processed by universal collector by default.
In case you’ve specified processing function for the given kind of events, all events of this kind will be processed only by this function, bypassing universal collector.
An example:
from buildbot.plugins import changes
class MyGerritChangeSource(changes.GerritChangeSource):
"""Custom GerritChangeSource
"""
def eventReceived_patchset_created(self, properties, event):
"""Handler events without properties
"""
properties = {}
self.addChangeFromEvent(properties, event)
This class will populate the property list of the triggered build with the info received from Gerrit server in JSON format.
Warning
If you selected GerritChangeSource, you must use Gerrit source step: the branch property of the change will be target_branch/change_id and such a ref cannot be resolved, so the Git source step would fail.
In case of patchset-created event, these properties will be:
event.change.branchBranch of the Change
event.change.idChange’s ID in the Gerrit system (the ChangeId: in commit comments)
event.change.numberChange’s number in Gerrit system
event.change.owner.emailChange’s owner email (owner is first uploader)
event.change.owner.nameChange’s owner name
event.change.projectProject of the Change
event.change.subjectChange’s subject
event.change.urlURL of the Change in the Gerrit’s web interface
event.patchSet.numberPatchset’s version number
event.patchSet.refPatchset’s Gerrit “virtual branch”
event.patchSet.revisionPatchset’s Git commit ID
event.patchSet.uploader.emailPatchset uploader’s email (owner is first uploader)
event.patchSet.uploader.namePatchset uploader’s name (owner is first uploader)
event.typeEvent type (patchset-created)
event.uploader.emailPatchset uploader’s email
event.uploader.namePatchset uploader’s name
In case of ref-updated event, these properties will be:
event.refUpdate.newRevNew Git commit ID (after merger)
event.refUpdate.oldRevPrevious Git commit ID (before merger)
event.refUpdate.projectProject that was updated
event.refUpdate.refNameBranch that was updated
event.submitter.emailSubmitter’s email (merger responsible)
event.submitter.nameSubmitter’s name (merger responsible)
event.typeEvent type (ref-updated)
event.submitter.emailSubmitter’s email (merger responsible)
event.submitter.nameSubmitter’s name (merger responsible)
A configuration for this source might look like:
from buildbot.plugins import changes
c['change_source'] = changes.GerritChangeSource(
"gerrit.example.com",
"gerrit_user",
handled_events=["patchset-created", "change-merged"])
See master/docs/examples/git_gerrit.cfg or master/docs/examples/repo_gerrit.cfg in the Buildbot distribution for a full example setup of Git+Gerrit or Repo+Gerrit of GerritChangeSource.