0

有没有办法配置 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)
)

有没有一种通用的方法来执行这种检查?还是我应该往另一个方向看?

4

1 回答 1

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'path\to\the\built\product\image'
factory.addStep(CustomFileExists(project_file))

如果找不到文件(或不满足您的约束),它将停在那里并且不会执行测试。

需要注意的是,这一步将在从属服务器上执行,这意味着文件将在从属服务器而不是主服务器上检查。

我希望这可以帮助你。

于 2014-09-19T10:24:39.237 回答