简体   繁体   English

如何使buildbot通过特定事件运行任务?

[英]How to make buildbot run the task by certain event?

Is there any way to configure master.cfg as to schedule a builder to be executing the code by the time the project folder or file in it has been modified(or its FileVersionInfo changed)? 有什么方法可以配置master.cfg,以计划生成器在修改项目文件夹或文件(或更改其FileVersionInfo)时执行该代码?

I know it is quite of a workaround, but i need this as to run the Build Verification Tests right after developers have compiled a newer version of a product, and since developing of a number of projects are not in CVS, I need a scanner for project folders. 我知道这是一个解决方法,但是我需要它来在开发人员编译产品的较新版本后立即运行构建验证测试,并且由于许多项目的开发不在CVS中进行,因此我需要使用扫描仪项目文件夹。

Here are the extracts from master.cfg: 以下是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))

There's a typical class derived from BuildFactory: 有一个从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

Now as we have the method and the class, we 现在有了方法和类,我们

create_builders_and_schedule_it(
    Autotests("devel").run_BVT_Prod(),
    ['VIX_runner'],
    nightly = (2,0)
)

Is there a common way to perform this kind of check? 有执行这种检查的常用方法吗? Or should I look in another direction? 还是我应该朝另一个方向看?

You can use a customized version of FileExists , something on the following lines: 您可以在以下行上使用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

From the name it seems it just checks for the file but you can do whatever with the file, eg with the stat command. 从名称看来,它似乎只是检查文件,但是您可以对文件执行任何操作,例如,使用stat命令。

In your main build configuration for this builder you need to add a new step before you execute the tests. 在此构建器的主要构建配置中,您需要在执行测试之前添加一个新步骤。 Something like: 就像是:

project_file = r'path\to\the\built\product\image'
factory.addStep(CustomFileExists(project_file))

If the file is not found (or didn't satisfy your constraints), it will stop there and tests will not be executed. 如果找不到该文件(或不满足您的约束),它将在此停止并不会执行测试。

Important to note that this step will be executed on the slave, meaning the file will be checked on the slave and not on the master. 重要的是要注意,此步骤将在从属设备上执行,这意味着将在从属设备而不是主设备上检查文件。

I hope this helps you. 我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM