簡體   English   中英

詹金斯管道超時

[英]Jenkins pipeline timeout

我在 Windows 機器上的 Jenkins 管道(聲明性)中有一個階段。 有一個永遠運行的腳本。 但是我需要日志並且必須確保它不會中斷,所以我不能在后台運行它。 基本上,我正在尋找是否有一段時間沒有日志填充在 jenkins 中,它應該以該階段的“成功”狀態進入下一階段。

我使用了時間選項,但是它將作業標記為失敗並且后續階段不會運行並且作業被中止。

timeout(time: 150, unit: 'SECONDS', activity: true)

無論如何,如果我可以在某某持續時間后將階段的狀態標記為成功。

謝謝,

您可以嘗試使用try\\catch塊和currentBuild全局變量,例如(已測試):

try {
    stage("UNSTABLE"){
        timeout(time: 20, unit: 'MINUTES') {
        //do something
        echo "UNSTABLE stage"
        currentBuild.result = "UNSTABLE"
        }
    }
    stage("SUCCESS"){
        timeout(time: 20, unit: 'MINUTES') {
        //do something
        echo "SUCCESS stage"
        currentBuild.result = "SUCCESS"
        }
    }
    stage("FAILURE"){
        timeout(time: 20, unit: 'MINUTES') {
        //do something
        echo "FAILURE stage"
        //currentBuild.result = "FAILURE" //this will fail all the pipeline
        }
    }
} catch (err) {
    echo err
    currentBuild.result = "SUCCESS"
    //do job
} finally {
    currentBuild.result = "SUCCESS"
    //do job
}

來自管道語法文檔(在本地 jenkins 上訪問此鏈接的鏈接 - http://localhost:8080/pipeline-syntax/globals#currentBuild ):

currentBuild變量可用於引用當前運行的構建。 它具有以下可讀屬性:

result - 通常為 SUCCESS、UNSTABLE 或 FAILURE(對於正在進行的構建可能為空)

currentResult - 通常為成功、不穩定或失敗。 永遠不會為空。

另請參閱: 如何操作 Jenkins 管道作業的構建結果?

我試圖運行永遠運行的npm start

但是我知道有備用命令

npm build

解決了我的問題。 所以我不需要包括 try catch 塊和超時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM