Jenkins声明式管道发布失败或已修复

时间:2019-03-26 17:40:08

标签: jenkins groovy jenkins-groovy jenkins-declarative-pipeline

Jenkins声明性管道允许声明要执行的不同发布阶段。我有这样的东西:

post {
    fixed {
        emailext (
            ... code to send email
        )
    }
    failure {
        emailext (
            ... code to send email
        )
    }
}

我的真实代码更长,并且完全重复。是否存在将这些代码组合在一起的方法?像

post {
    fixed || failure {
        emailext (
            ... code to send email
        )
    }
}

1 个答案:

答案 0 :(得分:0)

一种实现方法是定义在函数中发送电子邮件并在两种情况下都调用该函数的代码。

def SendEmail(){
   ... code to send email
}
post {
    fixed {
        emailext (
            SendEmail()
        )
    }
    failure {
        emailext (
            SendEmail()
        )
    }
}

如果您真正在寻找固定的||失败,建议您查看when(){}命令。 https://jenkins.io/blog/2018/04/09/whats-in-declarative/