是否有任何方法可以配置master.cfg,以便在修改(或更改其FileVersionInfo)项目文件夹或文件时安排构建器执行代码?
我知道这是一个很好的解决方法,但我需要它来在开发人员编译了新版本的产品后立即运行构建验证测试,并且由于许多项目的开发不在CVS中,我需要一个项目文件夹的扫描仪。
以下是master.cfg的摘录:
def create_builders_and_schedule_it(factory, build_slaves, **kwargs):
# kwargs: change_filter=None, nightly=None, trigger_name=None)
builder_names = []
if hasattr(factory, 'subcategory'):
cat = "%s_%s" % (factory.category, factory.subcategory)
else:
cat = factory.category
if 'change_filter' in kwargs:
change_filter = kwargs['change_filter']
else:
change_filter = filter.ChangeFilter( branch = factory.branch )
for i_slave in build_slaves:
builder_name = "%s_%s" % (cat, i_slave)
builder_names.append(builder_name)
c['builders'].append(
BuilderConfig(name = builder_name,
category = factory.category,
factory = factory,
slavename = i_slave
))
# every task has 'forced' scheduler at least
c['schedulers'].append(
ForceScheduler(name = cat + "_force",
builderNames = builder_names))
# every task has 'on commit' scheduler
c['schedulers'].append(
SingleBranchScheduler(name = cat + "_singlebranch",
builderNames = builder_names,
change_filter = change_filter))
# some task can be scheduled
if 'nightly' in kwargs:
c['schedulers'].append( timed.Nightly(
name = cat + '_nightly',
branch = factory.branch,
builderNames = builder_names,
hour = kwargs['nightly'][0], minute = kwargs['nightly'][1]))
if 'trigger_name' in kwargs:
c['schedulers'].append(
Triggerable(
name = kwargs['trigger_name'],
builderNames = builder_names))
有一个典型的类派生自BuildFactory:
class Autotests(BuildFactory):
""" Build products from Autotests repository """
def __init__(self, branch):
BuildFactory.__init__(self)
self.category = "autotests"
self.branch = branch
self.addStep(
Git(repourl = AUTOTESTS_REPO, branch = branch))
def build_source_archive(self):
self.subcategory = "source"
self.addStep(
ShellCommand(
workdir = "build",
command = ["./upload_to_binary_repo.sh"]))
return self
def run_BVT_prod(self):
self.subcategory = "BVT_prod"
self.addStep(
ShellCommand(
workdir = "build/BVT_tests/prod",
env = {'PATH':"/usr/bin:/bin", 'VIRTUAL_ENV':''},
command = ["./bvt_runner.sh"] ))
return self
现在我们有了方法和类,我们
create_builders_and_schedule_it(
Autotests("devel").run_BVT_Prod(),
['VIX_runner'],
nightly = (2,0)
)
有没有一种常见的方法来进行这种检查?或者我应该换个方向看?
您可以使用FileExists的自定义版本,如下所示:
from buildbot.steps.slave import FileExists
class CustomFileExists(FileExists):
# By default false
output_files_exist = False
def __init__(self, file, **kwargs):
CustomFileExists.output_files_exist = False
FileExists.__init__(self, file, **kwargs)
# Override the commandComplete
def commandComplete(self, cmd):
if not cmd.didFail():
# for e.g. check the last modification time on the file
# or do your own cooking to check whether to proceed or not !!
s = cmd.updates["stat"][-1]
if s[stat.ST_MTIME] > s[stat.ST_CTIME]:
# If it satisfies your condition, then set it to True
CustomFileExists.output_files_exist = True
self.finished(SUCCESS)
return
从名称来看,它似乎只是检查文件,但您可以对文件执行任何操作,例如使用stat
命令。
在这个构建器的主构建配置中,您需要在执行测试之前添加一个新步骤。类似于:
project_file = r'pathtothebuiltproductimage'
factory.addStep(CustomFileExists(project_file))
如果找不到该文件(或者不满足您的约束),它将停止,并且不会执行测试。
需要注意的是,此步骤将在从设备上执行,这意味着将在从机上而不是在主机上检查文件。
我希望这对你有帮助。