class buildbot.schedulers.timed.NightlyTriggerableThe
The force scheduler uses the web interface’s authorization framework to determine which user has the right to force which build. Here is an example of code on how you can define which user has which right:
user_mapping = {
re.compile("project1-builder"): ["project1-maintainer", "john"] ,
re.compile("project2-builder"): ["project2-maintainer", "jack"],
re.compile(".*"): ["root"]
}
def force_auth(user, status):
global user_mapping
for r,users in user_mapping.items():
if r.match(status.name):
if user in users:
return True
return False
# use authz_cfg in your WebStatus setup
authz_cfg=authz.Authz(
auth=my_auth,
forceBuild = force_auth,
)
ForceScheduler Parameters
Most of the arguments to
NestedParameter(name="options", label="Build options", layout="vertical", fields=[...]),
This parameter type is a special parameter which contains other parameters. This can be used to group a set of parameters together, and define the layout of your form. You can recursively include NestedParameter into NestedParameter, to build very complex UIs.
It adds the following arguments:
layout
(optional, default is “vertical”)
The layout defines how the fields are placed in the form.
The layouts implemented in the standard web application are:
simple
: fields are displayed one by one without alignment.
They take the horizontal space that they need.
vertical
: all fields are displayed vertically, aligned in columns (as per the column
attribute of the NestedParameter)
tabs
: each field gets its own tab.
This can be used to declare complex build forms which won’t fit into one screen. The children fields are usually other NestedParameters with vertical layout.
columns
(optional, accepted values are 1, 2, 3, 4)
The number of columns to use for a vertical layout. If omitted, it is set to 1 unless there are more than 3 visible child fields in which case it is set to 2.
FixedParameter
FixedParameter(name="branch", default="trunk"),
This parameter type will not be shown on the web form and always generates a property with its default value.
StringParameter
StringParameter(name="pull_url",
label="optionally give a public Git pull url:",
default="", size=80)
This parameter type will show a single-line text-entry box, and allow the user to enter an arbitrary string. It adds the following arguments:
regex
(optional)
A string that will be compiled as a regex and used to validate the input of this parameter.
size
(optional; default is 10)
The width of the input field (in characters).
TextParameter
TextParameter(name="comments",
label="comments to be displayed to the user of the built binary",
default="This is a development build", cols=60, rows=5)
This parameter type is similar to StringParameter, except that it is represented in the HTML form as a textarea
, allowing multi-line input. It adds the StringParameter arguments and the following ones:
cols
(optional; default is 80)
The number of columns the textarea
will have.
rows
(optional; default is 20)
The number of rows the textarea
will have.
This class could be subclassed to have more customization, e.g.
developer could send a list of Git branches to pull from
developer could send a list of Gerrit changes to cherry-pick,
developer could send a shell script to amend the build.
Beware of security issues anyway.
IntParameter
IntParameter(name="debug_level",
label="debug level (1-10)", default=2)
This parameter type accepts an integer value using a text-entry box.
BooleanParameter
BooleanParameter(name="force_build_clean",
label="force a make clean", default=False)
This type represents a boolean value. It will be presented as a checkbox.
UserNameParameter
UserNameParameter(label="your name:", size=80)
This parameter type accepts a username. If authentication is active, it will use the authenticated user instead of displaying a text-entry box.
size
(optional; default is 10)
The width of the input field (in characters).
need_email
(optional; default is True)
If true, requires a full email address rather than arbitrary text.
ChoiceStringParameter
ChoiceStringParameter(name="branch",
choices=["main","devel"], default="main")
This parameter type lets the user choose between several choices (e.g. the list of branches you are supporting, or the test campaign to run). If multiple
is false, then its result is a string with one of the choices. If multiple
is true, then the result is a list of strings from the choices.
Note that for some use cases, the choices need to be generated dynamically. This can be done via subclassing and overriding the ‘getChoices’ member function. An example of this is provided by the source for the InheritBuildParameter
class.
Its arguments, in addition to the common options, are:
choices
The list of available choices.
strict
(optional; default is True)
If true, verify that the user’s input is from the list. Note that this only affects the validation of the form request; even if this argument is False, there is no HTML form component available to enter an arbitrary value.
multiple
If true, then the user may select multiple choices.
Example:
ChoiceStringParameter(name="forced_tests",
label="smoke test campaign to run",
default=default_tests,
multiple=True,
strict=True,
choices=["test_builder1", "test_builder2",
"test_builder3"])
# .. and later base the schedulers to trigger off this property:
# triggers the tests depending on the property forced_test
builder1.factory.addStep(Trigger(name="Trigger tests",
schedulerNames=Property("forced_tests")))
Example of scheduler allowing to choose which worker to run on:
worker_list = ["worker1", "worker2", "worker3"]
ChoiceStringParameter(name="worker",
label="worker to run the build on",
default="*",
multiple=False,
strict=True,
choices=worker_list)
# .. and in nextWorker, use this property:
def nextWorker(bldr, workers, buildrequest):
forced_worker = buildrequest.properties.getProperty("worker", "*")
if forced_worker == "*":
return random.choice(workers) if workers else None
for w in workers:
if w.worker.workername == forced_worker:
return w
return None # worker not yet available
c['builders'] = [
BuilderConfig(name='mybuild', factory=f, nextWorker=nextWorker,
workernames=worker_list),
]
CodebaseParameter
CodebaseParameter(codebase="myrepo")
This is a parameter group to specify a sourcestamp for a given codebase.
codebase
The name of the codebase.
branch
(optional; default is StringParameter)
A
This parameter allows the user to upload a file to a build. The user can either write some text to a text area, or select a file from the browser. Note that the file is then stored inside a property, so a maxsize
of 10 megabytes has been set. You can still override that maxsize
if you wish.
PatchParameter
This parameter allows the user to specify a patch to be applied at the source step. The patch is stored within the sourcestamp, and associated to a codebase. That is why
Note
InheritBuildParameter is not yet ported to data API, and cannot be used with buildbot nine yet (bug #3521).
This is a special parameter for inheriting force build properties from another build. The user is presented with a list of compatible builds from which to choose, and all forced-build parameters from the selected build are copied into the new build. The new parameter is:
compatible_builds
A function to find compatible builds in the build history. This function is given the master instance as first argument, and the current builder name as second argument, or None when forcing all builds.
Example:
@defer.inlineCallbacks
def get_compatible_builds(master, builder):
if builder is None: # this is the case for force_build_all
return ["cannot generate build list here"]
# find all successful builds in builder1 and builder2
builds = []
for builder in ["builder1", "builder2"]:
# get 40 last builds for the builder
build_dicts = yield master.data.get(('builders', builder, 'builds'),
order=['-buildid'], limit=40)
for build_dict in build_dicts:
if build_dict['results'] != SUCCESS:
continue
builds.append(builder + "/" + str(build_dict['number']))
return builds
# ...
sched = Scheduler(...,
properties=[
InheritBuildParameter(
name="inherit",
label="promote a build for merge",
compatible_builds=get_compatible_builds,
required = True),
])
WorkerChoiceParameter
Note
WorkerChoiceParameter is not yet ported to data API, and cannot be used with buildbot nine yet (bug #3521).
This parameter allows a scheduler to require that a build is assigned to the chosen worker. The choice is assigned to the workername property for the build. The enforceChosenWorker
functor must be assigned to the canStartBuild
parameter for the Builder
.
Example:
from buildbot.plugins import util
# schedulers:
ForceScheduler(
# ...
properties=[
WorkerChoiceParameter(),
]
)
# builders:
BuilderConfig(
# ...
canStartBuild=util.enforceChosenWorker,
)
AnyPropertyParameter
This parameter type can only be used in properties
, and allows the user to specify both the property name and value in the web form.
This Parameter is here to reimplement old Buildbot behavior, and should be avoided. Stricter parameter names and types should be preferred.
发布评论