How to run a conditional step if previous timed out
Asked Answered
R

1

6

I have a buildbot build factory with several steps. One of the steps periodically times out causing buildbot to throw an exception and exit. However, even in this case I'd like to be able to store the logs generated. One option would be to add a step that only runs if the previous step timed out. Using doStepIf is possible. However, there is no way to see status as TIMEOUT there are just SUCCESS, WARNINGS, FAILURE, or SKIPPED. What is the best way to solve this problem?

AN example of the doStepIf function:

from buildbot.status.builder import Results, SUCCESS

def doStepIf(step):
    allSteps = step.build.getStatus().getSteps()
    lastStep = allSteps[-1]
    rc = lastStep.getResults()[0] # returns a tuple of (rc, string)
    # if the rc == SUCCESS then don't continue, since we don't want to run this step
    return Results[rc] == Results[SUCCESS]
Remodel answered 8/1, 2013 at 2:20 Comment(1)
What haltOnFailure attribute value have your step? If it's set to True, then further steps (e.g. logs storing) will be skipped, unless they have alwaysRun attribute set to True. See docs.buildbot.net/latest/manual/… for detailsStereoscopy
R
0

Here is the partial solution:

##-----------------------------------------------------------------------------
# Run checker for the timeout condition.
# It will return True if the last step timed out.
def if_tmo(step):
    allSteps = step.build.getStatus().getSteps()
    lastStep = allSteps[0]
    for bldStep in allSteps:
        if (bldStep.isFinished() == True):
            (result, strings) = bldStep.getResults()       # returns a tuple of (rc, string)
            lastStep = bldStep
        else:
            # this step didn't run yet. The one before is the last one
            break;

    # In the timed out step the log is either empty or has the proper string
    logText = lastStep.getLogs()[0].getText()
    timedOutStep = False
    if (len(logText) == 0 or (logText.find("command timed out") != -1)):
        timedOutStep = True

    return (timedOutStep)

I saw some examples of a bit different methodology (link), but this should work too.

getSteps() will return a list of all steps. Just need to find out which ones did run already.

Note: This code is a partial solution because if the script printed anything it will not work. It will work only if there was no output at all.

Remodel answered 11/1, 2013 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.