2013-01-08 40 views
5

我有一個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] 
+0

什麼'haltOnFailure'屬性值有你的腳步?如果它設置爲True,那麼進一步的步驟(例如日誌存儲)將被跳過,除非它們的'alwaysRun'屬性設置爲True。詳情請參閱http://docs.buildbot.net/latest/manual/cfg-buildsteps.html?highlight=haltonfailure#common-parameters – rutsky

回答

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) 

我看到了一個有點不同的方法(link)的一些例子,但這應該工作了。

getSteps()將返回一列全部步驟。只需要找出哪些已經運行。

注意:此代碼是部分解決方案,因爲如果腳本打印任何東西都不起作用。只有當有沒有輸出時,它纔會起作用。

相關問題