如何使用Jenkins Pipeline插件实施Post-Build阶段? [英] How to implement Post-Build stage using Jenkins Pipeline plug-in?
问题描述
在阅读了詹金斯的教程之后,解释了
After reading Jenkins tutorial explaining Pipeline plug-in, it seems that plug-in should make it possible to implement Post-Build steps. However documentation is rather limited in regard to specific instructions.
例如,我想知道如何实现:
For example I wonder how to implement:
- 仅在构建成功的情况下运行
- 仅在构建成功或不稳定的情况下运行
- 不管构建结果如何运行
- Run only if build succeeds
- Run only if build succeeds or is unstable
- Run regardless of build result
-
仅在构建成功后运行
stage 'build' ... build ... tests stage 'post-build' ...
(或将
-Dmaven.test.failure.ignore=false
添加到MAVEN_OPTS
)仅在构建成功或不稳定的情况下运行
stage 'build' ... build try { ... tests } catch { ... } stage 'post-build' ...
(或将
-Dmaven.test.failure.ignore=true
添加到MAVEN_OPTS
)不管构建结果如何运行-可以使用
try / catch / finally
完成吗?Run regardless of build result - could it be done using
try / catch / finally
?try { stage 'build' ... } catch { ... } finally { stage 'post-build' ... }
(我注意到最终构建状态设置为 SUCCESS ,即使某些阶段(即构建")基于最后一个阶段设置失败了.这是否意味着最终构建状态需要显式设置,即currentBuild.result = 'UNSTABLE'
?)
(I've noticed that final build status is set as SUCCESS even though some stages, ie. 'build', have failed as it set based on last stage. Does that mean final build status need to explicitly set, ie.currentBuild.result = 'UNSTABLE'
? )
推荐答案
最好的方法是在管道脚本中使用后期构建操作.
The best way is to use post build action in the pipeline script.
处理失败
声明式管道支持强大的故障 默认情况下,通过其post部分进行处理,从而可以声明 不同的后期条件"的数量,例如:总是,不稳定, 成功,失败和改变.管道语法部分提供 有关如何使用各种后期条件的更多详细信息.
Handling Failures
Declarative Pipeline supports robust failure handling by default via its post section which allows declaring a number of different "post conditions" such as: always, unstable, success, failure, and changed. The Pipeline Syntax section provides more detail on how to use the various post conditions.
Jenkinsfile(声明性管道)
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'make check'
}
}
}
post {
always {
junit '**/target/*.xml'
}
failure {
mail to: team@example.com, subject: 'The Pipeline failed :('
}
}
}
文档在下面 https://jenkins.io/doc/book/pipeline/syntax/#post
这篇关于如何使用Jenkins Pipeline插件实施Post-Build阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!