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

问题描述 投票:0回答:1

Jenkins声明性管道允许声明要执行的不同后期阶段。我有这样的事情:

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

我的真实代码更长,完全重复。是否存在将这些代码组合在一起的东西?就像是

post {
    fixed || failure {
        emailext (
            ... code to send email
        )
    }
}
jenkins groovy jenkins-groovy jenkins-declarative-pipeline
1个回答
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/

© www.soinside.com 2019 - 2024. All rights reserved.