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

标签 python buildbot

我有一个包含多个步骤的 buildbot 构建工厂。其中一个步骤会定期超时,导致 buildbot 抛出异常并退出。但是,即使在这种情况下,我也希望能够存储生成的日志。 一种选择是添加一个仅在上一步超时时才运行的步骤。使用 doStepIf 是可能的。但是,无法将状态视为 TIMEOUT,只有 SUCCESS、WARNINGS、FAILURE 或 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 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() 将返回所有 步骤的列表。只需要找出哪些已经运行。

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

关于python - 如果先前超时,如何运行条件步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14207289/

相关文章:

python - 如何按日期范围和类别对 Pandas 进行分类?

python - 如何根据 CSV 列中的元素在 Matplotlib-Basemap 图上设置不同的标记?

java - 通过 cli 编译并创建可运行的 jar 文件,如 eclipse

windows - buildbot 和 cmake 无法创建 vs2010 生成器

python - Python 中的元编程 - 添加对象方法

python - Django 3.2 如何将 404 重定向到主页

python - 这段 python 代码有什么问题吗?输入后出现错误

buildbot - 如何访问 buildbot 的属性变量(字典)?

buildbot - 如何将变量传递给Buildbot?

python - 如何锁定buildbot中的步骤