【问题标题】:How to run a conditional step if previous timed out如果先前超时,如何运行条件步骤
【发布时间】:2013-01-08 02:20:07
【问题描述】:

我有一个包含几个步骤的 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]

【问题讨论】:

  • haltOnFailure 属性值有你的步骤吗?如果设置为 True,则将跳过进一步的步骤(例如日志存储),除非它们将 alwaysRun 属性设置为 True。详情见docs.buildbot.net/latest/manual/…

标签: python buildbot


【解决方案1】:

这里是部分解决方案:

##-----------------------------------------------------------------------------
# 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)

我看到了一些不同方法的示例 (link),但这也应该有效。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-06
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多