在Jenkins声明式管道中对发布条件进行分组 [英] Grouping post conditions in a Jenkins declarative pipeline
问题描述
是否可以在Jenkins声明性管道中对发布条件进行分组?
Is there a way to group post conditions in a Jenkins declarative pipeline ?
例如,我想对状态aborted
failure
和success
做同样的事情.
是否有比以下方法更短的方法?
For instance, I want to do the same thing for statuses aborted
failure
and success
.
Is there a shorter way to do it than the following ?
post {
aborted { sendNotification(currentBuild.result, "$LIST_NOTIFICATION_JENKINS")
failure { sendNotification(currentBuild.result, "$LIST_NOTIFICATION_JENKINS")
success { sendNotification(currentBuild.result, "$LIST_NOTIFICATION_JENKINS")
}
推荐答案
存在总是"情况:
post {
always {sendNotification(currentBuild.result, "$LIST_NOTIFICATION_JENKINS")}
}
无论阶段结果如何,始终"条件都会运行.
The 'always' condition will run regardless of the stage result.
请参阅帖子部分的文档.
See the documentation on the post section.
如果您只想在几个条件之间进行一组通用操作,例如,如果您要为失败和中止做同样的事情,那么我建议您在脚本中创建一个函数,以从失败和中止后的情况中调用.
If you want a set of common actions between just a few conditions, for example if you wanted to do the same thing for failure and aborted, I would recommend creating a function in your script to call from the failure and aborted post conditions.
您还可以执行以下操作:
You can also do something like the following:
always {
script{
if (currentBuild.currentResult == "ABORTED" || currentBuild.currentResult == "FAILURE")
{
echo "was aborted or failed"
}
}
}
这篇关于在Jenkins声明式管道中对发布条件进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!