Ticket #428 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

ability to run shellCommand based on a conditional property

Reported by: mook Owned by:
Priority: minor Milestone: 0.7.11
Version: 0.7.9 Keywords: sprint
Cc: catlee, jhoos

Description

It would be nice if I could skip commands (or build steps in general?) based on having some property set (or unset, etc.). Attached is a (untested) patch that does something like this for shellCommand (would be nicer if it's more generic, I guess?). Unfortunately, I couldn't quite figure out the unit test system yet, so don't trust this code, please.

Attachments

0001-add-conditional-shellCommand-untested.patch Download (2.4 KB) - added by mook 4 years ago.
untested patch
buildbot-0.7.10p1-conditional-steps.patch Download (5.4 KB) - added by jhoos 4 years ago.
Conditional steps based on lambdas, with unit test

Change History

Changed 4 years ago by mook

untested patch

comment:1 Changed 4 years ago by dustin

  • Milestone changed from undecided to 0.7.10

I like, but can it take a "test" function, e.g.,

f.addStep(ConditionalShellCommand(
    conditionFn=lambda props : props['foo'] in ('bar', 'baz'),
    command=...))

putting this in the 0.7.10 milestone in hopes it can be done in time. If not, that's OK :)

comment:2 Changed 4 years ago by dustin

  • Milestone changed from 0.7.10 to 0.7.+

comment:3 Changed 4 years ago by dustin

  • Milestone changed from 0.7.+ to 0.7.11

Let's get this in 0.7.11, eh?

comment:4 Changed 4 years ago by catlee

  • Cc catlee added

I'd like to see this be able to run any build step conditionally, not just shell commands.

And it definitely needs to accept a "test" function.

comment:5 Changed 4 years ago by dustin

  • Keywords sprint added

comment:6 Changed 4 years ago by jhoos

I stumbled across this ticket earlier this week, and it so happens that we have a patch that implements the ability to conditionally run any step based on a function or lambda. We named the parameter "doStepIf" instead of "conditionFn", but otherwise it should fit the bill. If the function/lambda returns true, the step is run normally, otherwise the step returns SKIPPED and its start method is not called. The only other difference is that in our implementation the lambda takes the entire step object as its parameter, instead of just the properties.

Changed 4 years ago by jhoos

Conditional steps based on lambdas, with unit test

comment:7 Changed 4 years ago by jhoos

  • Cc jhoos added

comment:8 Changed 4 years ago by dustin

  • Status changed from new to closed
  • Resolution set to fixed

I changed the "== False" to just use "not", since doStepIf may return other false values.

 714             if isinstance(self.doStepIf, bool):
 715                 if not self.doStepIf:
 716                     skip = SKIPPED
 717             elif not self.doStepIf(self):
 718                 skip = SKIPPED

committed:

commit 830cb403ad59dff5da6102000827f90349dbfedd
Author: Jason Hoos <jason.hoos@syclo.com>
Date:   Sun Apr 12 13:39:41 2009 -0400

    (refs #428) add doStepIf parameter to buildsteps

Thank you for contributing!

comment:9 Changed 4 years ago by catlee

Very nice! Thanks for getting this done.

comment:10 Changed 3 years ago by dustin

commit 5d65dc65a03ec3a38648c42407f3163de3310aa6
Author: Dustin J. Mitchell <dustin@zmanda.com>
Date:   Sat Dec 26 19:22:05 2009 -0600

    document doStepIf
Note: See TracTickets for help on using tickets.