我正在使用Jenkins管道来运行构建。
如何避免执行相同代码(失败和不稳定)的2个post状态的代码重复?
示例代码片段:
post {
failure
{
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
unstable
{
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
发布于 2018-07-10 19:47:11
你可以写一个函数并使用它,f.e.
post {
failure
{
sendMail()
}
unstable
{
sendMail()
}
def sendMail() {
emailext(
attachmentsPattern: '**/log.txt',
body: "Something is wrong with ${env.BUILD_URL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
to: "test@test.gmail"
)
}
https://stackoverflow.com/questions/51262760
复制相似问题