Skip to content

Commit

Permalink
Slack developer on pipeline failure (#370)
Browse files Browse the repository at this point in the history
Albrja/Mic-5240/Slack developer on build failure

Slack developer on Jenkins pipeline failure
- *Category*: Feature
- *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-5240

Changes and notes
-Slack developer on Jenkins pipeline failure
  • Loading branch information
albrja authored Oct 15, 2024
1 parent 5ebbdfe commit 423eb4f
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
def githubUsernameToSlackName(github_author) {
// Add team members as necessary
def mapping = [
"Jim Albright": "albrja",
"Steve Bachmeier": "sbachmei",
"Hussain Jafari": "hjafari",
"Patrick Nast": "pnast",
"Rajan Mudambi": "rmudambi",
]
return mapping.get(github_author, "channel")
}

pipeline_name="vivarium_census_prl_synth_pop"
conda_env_name="${pipeline_name}-${BUILD_NUMBER}"
conda_env_path="/tmp/${conda_env_name}"
Expand Down Expand Up @@ -168,25 +180,44 @@ pipeline {
always {
sh "${ACTIVATE} && make clean"
sh "rm -rf ${CONDA_ENV_PATH}"
// Delete the workspace directory.
deleteDir()
// Tell BitBucket whether the build succeeded or failed.
// Generate a message to send to Slack.
script {
notifyBitbucket()
if (env.BRANCH == "main") {
channelName = "simsci-ci-status"
} else {
channelName = "simsci-ci-status-test"
}
// Run git command to get the author of the last commit
developerID = sh(
script: "git log -1 --pretty=format:'%an'",
returnStdout: true
).trim()
slackID = githubUsernameToSlackName(developerID)
slackMessage = """
Job: *${env.JOB_NAME}*
Build number: #${env.BUILD_NUMBER}
Build status: *${currentBuild.result}*
Author: @${slackID}
Build details: <${env.BUILD_URL}/console|See in web console>
""".stripIndent()
}

// Delete the workspace directory.
deleteDir()
}
failure {
slackSend channel: "#${params.SLACK_TO}",
message: ":x: JOB FAILURE: $JOB_NAME - $BUILD_ID\n\n${BUILD_URL}console\n\n<!channel>",
teamDomain: "ihme",
tokenCredentialId: "slack"
echo "This build triggered by ${developerID} failed on ${GIT_BRANCH}. Sending a failure message to Slack."
slackSend channel: "#${channelName}",
message: slackMessage,
teamDomain: "ihme",
tokenCredentialId: "slack"
}
success {
script {
if (params.DEBUG) {
echo 'Debug is enabled. Sending a success message to Slack.'
slackSend channel: "#${params.SLACK_TO}",
message: ":white_check_mark: (debugging) JOB SUCCESS: $JOB_NAME - $BUILD_ID\n\n${BUILD_URL}console",
slackSend channel: "#${channelName}",
message: slackMessage,
teamDomain: "ihme",
tokenCredentialId: "slack"
} else {
Expand Down

0 comments on commit 423eb4f

Please sign in to comment.