Jenkins声明性管道允许声明要执行的不同后期阶段。我有这样的事情:
post {
fixed {
emailext (
... code to send email
)
}
failure {
emailext (
... code to send email
)
}
}
我的真实代码更长,完全重复。是否存在将这些代码组合在一起的东西?就像是
post {
fixed || failure {
emailext (
... code to send email
)
}
}
关于这样做的一个方法是定义代码以在函数中发送电子邮件并从两个场景调用该函数。
def SendEmail(){
... code to send email
}
post {
fixed {
emailext (
SendEmail()
)
}
failure {
emailext (
SendEmail()
)
}
}
如果你真的在寻找一个固定的||失败,我建议查看when(){}命令。 https://jenkins.io/blog/2018/04/09/whats-in-declarative/