2

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.

CrankyElderGod
  • 403
  • 4
  • 10

1 Answers1

2

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)

An Ky
  • 113
  • 11
  • Thank you. The key here is that, within master.cfg, the build.getStatus() call will return the result of the most recent step. What I ended up doing was coding MyCoolStep to detect the success/failure internally and perform any relevant rollback there, rather than have BuildBot manage it. – CrankyElderGod Dec 16 '20 at 03:34
  • It seems like in a recent buildbot (e.g. 3.5.0) body of `failure(build)` shall be changed: `return build.getStatus() == FAILURE` =>`return build.build.results == FAILURE` – tysonite Jun 21 '22 at 11:36