Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.8] [CI] Add slack alerts to tracked branch jobs, change default channel, change formatting (#66580) #66742

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ stage("Kibana Pipeline") { // This stage is just here to help the BlueOcean UI a
}
}

retryable.printFlakyFailures()
kibanaPipeline.sendMail()
if (params.NOTIFY_ON_FAILURE) {
slackNotifications.onFailure()
kibanaPipeline.sendMail()
}
}
}
}
Expand Down
43 changes: 30 additions & 13 deletions vars/slackNotifications.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,32 @@ def getTestFailures() {
def messages = []
messages << "*Test Failures*"

def list = failures.collect { "• <${it.url}|${it.fullDisplayName}>" }.join("\n")
def list = failures.collect { "• <${it.url}|${it.fullDisplayName.split('.', 2)[-1]}>" }.join("\n")
return "*Test Failures*\n${list}"
}

def sendFailedBuild(Map params = [:]) {
def displayName = "${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}"
def getDefaultDisplayName() {
return "${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}"
}

def getDefaultContext() {
def duration = currentBuild.durationString.replace(' and counting', '')

return contextBlock([
"${buildUtils.getBuildStatus().toLowerCase().capitalize()} after ${duration}",
"<https://ci.kibana.dev/${env.JOB_BASE_NAME}/${env.BUILD_NUMBER}|ci.kibana.dev>",
].join(' · '))
}

def sendFailedBuild(Map params = [:]) {
def config = [
channel: '#kibana-operations',
title: ":broken_heart: *<${env.BUILD_URL}|${displayName}>*",
message: ":broken_heart: ${displayName}",
channel: '#kibana-operations-alerts',
title: ":broken_heart: *<${env.BUILD_URL}|${getDefaultDisplayName()}>*",
message: ":broken_heart: ${getDefaultDisplayName()}",
color: 'danger',
icon: ':jenkins:',
username: 'Kibana Operations',
context: contextBlock("${displayName} · <https://ci.kibana.dev/${env.JOB_BASE_NAME}/${env.BUILD_NUMBER}|ci.kibana.dev>"),
context: getDefaultContext(),
] + params

def blocks = [markdownBlock(config.title)]
Expand All @@ -94,18 +105,24 @@ def sendFailedBuild(Map params = [:]) {
)
}

def onFailure(Map options = [:]) {
catchError {
def status = buildUtils.getBuildStatus()
if (status != "SUCCESS") {
catchErrors {
sendFailedBuild(options)
}
}
}
}

def onFailure(Map options = [:], Closure closure) {
// try/finally will NOT work here, because the build status will not have been changed to ERROR when the finally{} block executes
catchError {
closure()
}

def status = buildUtils.getBuildStatus()
if (status != "SUCCESS" && status != "UNSTABLE") {
catchErrors {
sendFailedBuild(options)
}
}
onFailure(options)
}

return this