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