我在Windows机器上的Jenkins管道(声明式)中有一个阶段。 有一个脚本可以永远运行。但是我需要日志,并且必须确保它不会在两者之间中断,所以我不能在后台运行它。 基本上,我正在寻找是否有一段时间在jenkins中填充日志,它应该以该阶段的“成功”状态进入下一阶段。
我使用了时间选项,但是它会将作业标记为失败,并且后续阶段将无法运行,并且作业被中止。
timeout(time: 150, unit: 'SECONDS', activity: true)
无论如何,只要能在某段时间之后标记出成功的状态,就可以。
谢谢
答案 0 :(得分:1)
您可以尝试使用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
}
来自管道语法文档(通过链接访问您本地的詹金斯-http://localhost:8080/pipeline-syntax/globals#currentBuild):
currentBuild
变量可用于引用当前 运行构建。它具有以下可读属性:
result
- 通常为SUCCESS,UNSTABLE或FAILURE(对于正在进行的操作,可以为null 构建)
currentResult
-通常为成功,不稳定或失败。将 永远不会为空。
另请参阅:How to manipulate the build result of a Jenkins pipeline job?
答案 1 :(得分:0)
我试图运行永久运行的“ npm start”。但是我知道有替代命令“ npm build”修复了我的问题。所以我不需要包括尝试捕获块和超时。 我走错了方向。这很简单。