如果先前超时,如何运行条件步骤

ily*_*725 6 python buildbot

我有一个buildbot构建工厂,有几个步骤.其中一个步骤会定期超时,导致buildbot抛出异常并退出.但是,即使在这种情况下,我也希望能够存储生成的日志.一种选择是添加仅在上一步超时时才运行的步骤.使用doStepIf是可能的.但是,没有办法看到状态,因为TIMEOUT只有SUCCESS, WARNINGS, FAILURE, or SKIPPED.解决这个问题的最佳方法是什么?

doStepIf功能的一个例子:

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]
Run Code Online (Sandbox Code Playgroud)

ily*_*725 0

这是部分解决方案:

##-----------------------------------------------------------------------------
# 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)
Run Code Online (Sandbox Code Playgroud)

我看到了一些稍微不同的方法的例子(链接),但这也应该有效。

getSteps()将返回所有步骤的列表。只需要找出哪些已经运行了。

注意:此代码是部分解决方案,因为如果脚本打印任何内容,它将无法工作。仅当根本没有输出时它才会起作用。