Search code examples
buildbot

Buildbot: Common buildsteps accross multiple factories


So I am configuring buildbot builders with build factories, and have quite a number of them, and many of them use common build steps. What i currently do is:

f1 = util.BuildFactory()
f1.addStep(step1)
f1.addStep(step2)
f1.addStep(step3)
f1.addStep(f1_specific_steps)
f1.addStep(step4)
f1.addStep(step5)
f1.addStep(step6)

f2 = util.BuildFactory()
f2.addStep(step1)
f2.addStep(step2)
f2.addStep(step3)
f2.addStep(f2_specific_steps)
f2.addStep(step4)
f2.addStep(step5)
f2.addStep(step6)

This makes my master.cfg file go huge. Is there a way to do that more inteligently? Something like f1 = f_common_start + f1_specific + f_common_end?


Solution

  • That's exactly what you can do! Remember that buildbot's config is python code. So, using your example you could do:

    f_common_start = [ step1,
                       step2
                       step3, ]
    f_common_end   = [ step4,
                       step5,
                       step6, ]
    f1_specific_steps = [ f1_step_A, f1_step_B ]
    f2_specific_steps = [ f2_step_Y, f2_step_Z ]
    
    f1 = util.BuildFactory()
    f1.addSteps(f_common_start + f1_specific_steps + f_common_end)
    
    f2 = util.BuildFactory()
    f2.addSteps(f_common_start + f2 specific_steps + f_common_end)
    

    Basically you're just combining lists of Step objects. Also, notice that I'm using the addSteps() command to add multiple steps.

    Here's an actual (shortened) working example:

    from buildbot.steps.shell    import Compile, ShellCommand, Test
    from buildbot.steps.transfer import DirectoryUpload
    
    clear_dregs = [ ShellCommand(command=["find", ".", "-name", "*.units.txt", "-delete"],
                                 workdir="build"),
                    RemovePYCs,
    ]
    common_steps = clear_dregs + [
      ShellCommand(command=["cmake", "../src",] workdir="build"),
      Compile(command="make all"),
    ]
    
    test_factory = factory.BuildFactory()
    test_factory.addSteps(common_steps)
    test_factory.addStep(Test(command="make test"))
    
    docs_factory = factory.BuildFactory()
    docs_factory.addSteps(common_steps)
    docs_factory.addStep(Compile(command="make docs"))
    docs_factory.addStep(DirectoryUpload(slavesrc="docs",
                                         masterdest="/opt/docs/"))
    
    rpm_factory = factory.BuildFactory()
    rpm_factory.addSteps(common_steps)
    rpm_factory.addStep(ShellCommand(command=["make", "rpm"]))
    

    Again, note where I use addStep() and addSteps().