在我的windows机器上,我有一个Jenkins流水线(声明式)的阶段。有一个永远运行的脚本。然而,我需要日志,并且必须确保它不会中断,所以我不能在后台运行它。基本上,我正在寻找如果没有日志填充在jenkins中的一段时间,它应该进行到下一个阶段的“成功”状态。
我使用了时间选项,但是它将作业标记为失败,后续阶段不会运行,作业被中止。
timeout(time: 150, unit: 'SECONDS', activity: true)任何方式,如果我可以标记阶段的状态为成功后,这样的持续时间。
谢谢,
发布于 2018-08-29 15:55:45
您可以尝试使用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 -通常为成功、不稳定或失败(对于正在进行的构建,可能为null )
currentResult -通常是成功、不稳定或失败。永远不会为空。
另请参阅:How to manipulate the build result of a Jenkins pipeline job?
发布于 2018-09-04 16:44:41
我在试着运行永远运行的npm start
然而,我知道还有其他的命令
npm build这解决了我的问题。因此,我不需要包含try catch块和超时。
https://stackoverflow.com/questions/52071893
复制相似问题