-
Notifications
You must be signed in to change notification settings - Fork 111
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
jenkins: Add Slack notifications for job status changes #306
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ node(NODE) { | |
utils = load("pipeline-utils.groovy") | ||
utils.define_properties(TIMER) | ||
|
||
try { | ||
def manifest = "host-${OS_NAME}.yaml" | ||
def manifest_data = readYaml file: "${manifest}"; | ||
// TODO - stop using the ref in favor of oscontainer:// pivot | ||
|
@@ -105,5 +106,11 @@ node(NODE) { | |
stage("Cleanup") { sh """ | ||
rm ${treecompose_workdir} -rf | ||
""" } | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks! |
||
} catch (Throwable e) { | ||
currentBuild.result = 'FAILURE' | ||
throw e | ||
} finally { | ||
utils.notify_status_change currentBuild | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,4 +169,36 @@ def inside_assembler_container(args, fn) { | |
} | ||
} | ||
|
||
// Send a notification when a job's status changes. | ||
// Treat non-SUCCESS states the same, so it does not send notifications when | ||
// changes go between UNSTABLE and FAILURE. | ||
def notify_status_change(build) { | ||
def color = '' | ||
def message = "<${env.BUILD_URL}|Build ${env.BUILD_NUMBER} of ${env.JOB_NAME}>" | ||
|
||
if (build.currentResult == build.previousBuild?.result) | ||
return | ||
|
||
if (build.previousBuild?.result == null) { | ||
echo 'The previous build is still running; ignoring its build state.' | ||
return | ||
} else if (build.currentResult == 'SUCCESS') { | ||
message = ":partyparrot: ${message} is working again." | ||
color = 'good' | ||
} else if (build.previousBuild.result == 'SUCCESS') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth filtering out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could filter previously aborted job states, but I'm not sure what to do about when the current job is aborted. You apparently can't set the state to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's unfortunate. That's fine then, we can live with it. |
||
message = ":trashfire: ${message} has started failing." | ||
color = 'danger' | ||
} else { | ||
echo 'This and the previous build have different non-success states.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, let's just notify in that case, too. Maybe something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you still want this additional notification while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think that's fine. Thinking more on this, if this case happens, it means that the previous build was not successful, and we already notified about the |
||
return | ||
} | ||
|
||
try { | ||
slackSend channel: '#jenkins-coreos', color: color, message: message | ||
} catch (NoSuchMethodError err) { | ||
// Log the message in the console if the Slack plugin is not installed. | ||
echo message | ||
} | ||
} | ||
|
||
return this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just do
try-finally
and move this statement as part of thefinally
block?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you differentiate between success and failure then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what I was thinking when I made that suggestion. :)