Jenkins 管道构建失败后如何发送 Slack 通知? [英] How to send Slack notification after Jenkins pipeline build failed?
问题描述
我在 Jenkins v2.19 中有一个管道 groovy 脚本.我也有一个
Slack 通知插件"v2.0.1 和Groovy Postbuild 插件".
I have a pipeline groovy script in Jenkins v2.19. Also I have a
"Slack Notification Plugin" v2.0.1 and "Groovy Postbuild Plugin".
我已成功发送消息构建开始"和构建完成"(如果有).
I have successfully send a message "build started" and "build finished" (if it had).
当某些构建步骤失败时——我如何向 Slack 频道发送消息构建失败"?
When some build step failed – how I can send a message "Build failed" to the Slack channel?
推荐答案
以防万一,如果在声明式语法中,
现在,Jenkins 提供了post
.您可以在管道结束时检查结果.
Now, Jenkins provides post
. You can check result at the end of pipeline.
https://jenkins.io/doc/book/pipeline/syntax/#post-example
使用像:
pipeline {
stages { ... }
post {
// only triggered when blue or green sign
success {
slackSend ...
}
// triggered when red sign
failure {
slackSend ...
}
// trigger every-works
always {
slackSend ...
}
}
}
它也将用于每个stage
.请查看文档链接.
It would be used in every stage
also. See the document link please.
这篇关于Jenkins 管道构建失败后如何发送 Slack 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!