設(shè)置超時(shí)
timeout(20) {
..
}
默認(rèn)時(shí)間單位為MINUTES,如果其他時(shí)間單位,則使用unit
參數(shù):SECONDS、MINUTES和HOURS
timeout(time: 20, unit: 'SECONDS') {
..
}
示例
可以在不同級(jí)別(每個(gè)整體管道或每個(gè)階段)使用options指定超時(shí)
任務(wù)- 超時(shí)時(shí)間
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
stages { .. }
// ..
}
步驟 - 超時(shí)
pipeline {
agent any
stages {
stage('Run') {
steps {
retry(3) {
sh './deploy.sh'
}
timeout(time: 3, unit: 'MINUTES') {
sh './ren_test.sh'
}
}
}
}
}
超時(shí)后繼續(xù)執(zhí)行
在上面的示例中,在階段超時(shí)之后,流水線中止,并顯示以下消息:
Sending interrupt signal to process Cancelling nested steps due to timeout
如果超時(shí)后,想要繼續(xù)執(zhí)行后續(xù)步驟,需要捕獲異常。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-583238.html
pipeline {
agent any
stages {
stage('Build-1') {
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
script {
try {
sh './run_test.sh'
} catch (error) {
println "Error happened, continuing"
}
}
}
}
}
超時(shí)異常:
org.jenkinsci.plugins.workflow.steps.FlowInterruptedException文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-583238.html
pipeline {
agent any
options{
timestamps()
}
stages {
stage("A") {
options {
timeout(time: env.timeout, unit: "SECONDS")
//MINUTES
}
steps {
script {
Exception caughtException = null
catchError(buildResult: 'SUCCESS', stageResult: 'ABORTED') {
try {
echo "Started stage A"
sleep(time: 5, unit: "SECONDS")
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
error "Caught ${e.toString()}"
} catch (Throwable e) {
caughtException = e
}
}
if (caughtException) {
error caughtException.message
}
}
}
}
stage("B") {
steps {
echo "Started stage B"
}
}
}
}
到了這里,關(guān)于【Jenkins】Pipeline - 設(shè)置超時(shí)時(shí)間的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!