CrankyElderGod
CrankyElderGod

Reputation: 433

Conditional steps in BuildBot

I'm trying to create a build configuration with BuildBot using conditional steps. In particular, I want to have conditional steps based on whether or not a preceding step failed, something like this:

factory = util.BuildFactory()
factory.addStep(MyCoolStep())
factory.addStep(CommitWork(), doStepIf='MyCoolStepWorked')
factory.addStep(RollbackWork(), doStepIf='MyCoolStepFailed')

According to the docs, the 'doStepIf' takes a boolean qualifier. How do I access the result of a preceding step? Or do I need to set a custom property somewhere? I'm somewhat new to Python, so I'm not sure about the scoping of various variables and objects in the buildbot master config.

Upvotes: 3

Views: 1046

Answers (1)

An Ky
An Ky

Reputation: 133

Each step in Buildbot returns as status either SUCCESS, WARNINGS, SKIPPED, FAILURE, CANCELLED, EXCEPTION, RETRY

So if MyCoolStep worked, it sets the build status to SUCCESS, which you can check for CommitWork to execute it.

For RollbackWorkflow you can check whether the build is in FAILURE state and execute it. Since CommitWork is skipped in this state, the overall state won't upgrade to SKIPPED

Both steps are hidden if SKIPPED so they won't pollute the buildbot output when not executed.

def success(build):
  return build.getStatus() == SUCCESS

def failure(build):
  return build.getStatus() == FAILURE

def skipped(results, build):
  return results == SKIPPED

factory = util.BuildFactory()
factory.addStep(MyCoolStep())
factory.addStep(CommitWork(), doStepIf=success, hideStepIf=skipped)
factory.addStep(RollbackWork(), doStepIf=failure, hideStepIf=skipped)

Upvotes: 3

Related Questions