@@ -62,21 +62,32 @@ def getTestFailures() {
6262 def messages = []
6363 messages << " *Test Failures*"
6464
65- def list = failures. collect { " • <${ it.url} |${ it.fullDisplayName} >" }. join(" \n " )
65+ def list = failures. collect { " • <${ it.url} |${ it.fullDisplayName.split('.', 2)[-1] } >" }. join(" \n " )
6666 return " *Test Failures*\n ${ list} "
6767}
6868
69- def sendFailedBuild (Map params = [:]) {
70- def displayName = " ${ env.JOB_NAME} ${ env.BUILD_DISPLAY_NAME} "
69+ def getDefaultDisplayName () {
70+ return " ${ env.JOB_NAME} ${ env.BUILD_DISPLAY_NAME} "
71+ }
7172
73+ def getDefaultContext () {
74+ def duration = currentBuild. durationString. replace(' and counting' , ' ' )
75+
76+ return contextBlock([
77+ " ${ buildUtils.getBuildStatus().toLowerCase().capitalize()} after ${ duration} " ,
78+ " <https://ci.kibana.dev/${ env.JOB_BASE_NAME} /${ env.BUILD_NUMBER} |ci.kibana.dev>" ,
79+ ]. join(' · ' ))
80+ }
81+
82+ def sendFailedBuild (Map params = [:]) {
7283 def config = [
73- channel : ' #kibana-operations' ,
74- title : " :broken_heart: *<${ env.BUILD_URL} |${ displayName } >*" ,
75- message : " :broken_heart: ${ displayName } " ,
84+ channel : ' #kibana-operations-alerts ' ,
85+ title : " :broken_heart: *<${ env.BUILD_URL} |${ getDefaultDisplayName() } >*" ,
86+ message : " :broken_heart: ${ getDefaultDisplayName() } " ,
7687 color : ' danger' ,
7788 icon : ' :jenkins:' ,
7889 username : ' Kibana Operations' ,
79- context : contextBlock( " ${ displayName } · <https://ci.kibana.dev/ ${ env.JOB_BASE_NAME } / ${ env.BUILD_NUMBER } |ci.kibana.dev> " ),
90+ context : getDefaultContext( ),
8091 ] + params
8192
8293 def blocks = [markdownBlock(config. title)]
@@ -94,18 +105,24 @@ def sendFailedBuild(Map params = [:]) {
94105 )
95106}
96107
108+ def onFailure (Map options = [:]) {
109+ catchError {
110+ def status = buildUtils. getBuildStatus()
111+ if (status != " SUCCESS" ) {
112+ catchErrors {
113+ sendFailedBuild(options)
114+ }
115+ }
116+ }
117+ }
118+
97119def onFailure (Map options = [:], Closure closure ) {
98120 // try/finally will NOT work here, because the build status will not have been changed to ERROR when the finally{} block executes
99121 catchError {
100122 closure()
101123 }
102124
103- def status = buildUtils. getBuildStatus()
104- if (status != " SUCCESS" && status != " UNSTABLE" ) {
105- catchErrors {
106- sendFailedBuild(options)
107- }
108- }
125+ onFailure(options)
109126}
110127
111128return this
0 commit comments