Skip to content

Commit

Permalink
Merge pull request #3269 from AdamBrousseau/slack_add_all_casues
Browse files Browse the repository at this point in the history
Add upstream causes to Slack messages
  • Loading branch information
pshipton committed Oct 15, 2018
2 parents d2b42ea + e5dc9ca commit ebfc93e
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions buildenv/jenkins/common/pipeline-functions
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,24 @@ def build_with_artifactory(JOB_NAME, VARIABLE_FILE, VENDOR_REPO, VENDOR_BRANCH,
}
}

def get_causes(job) {
def cause_string = ''
for (cause in job.rawBuild.getCauses()) {
cause_string += get_causes_recursively(cause)
}
return cause_string
}

def get_causes_recursively(cause) {
def cause_string = cause.getShortDescription()
if (cause instanceof hudson.model.Cause.UpstreamCause) {
for (upCause in cause.getUpstreamCauses()) {
cause_string += '\n' + get_causes_recursively(upCause)
}
}
return cause_string
}

def build_with_slack(JOB_NAME, PARAMETERS) {
def DOWNSTREAM_JOB_NUMBER = ''
def DOWNSTREAM_JOB_URL = ''
Expand All @@ -211,20 +229,23 @@ def build_with_slack(JOB_NAME, PARAMETERS) {
} catch (err) {
echo "Couldn't retrieve downstream failed job url"
}


// Get build causes
build_causes_string = get_causes(currentBuild)

if (JOB.result == "UNSTABLE") {
echo "WARNING: Downstream job ${JOB_NAME} is unstable. Job Number: ${DOWNSTREAM_JOB_NUMBER} Job URL: ${DOWNSTREAM_JOB_URL}"
currentBuild.result = "UNSTABLE"
if (SLACK_CHANNEL) {
slackSend channel: SLACK_CHANNEL, color: 'warning', message: "Unstable: ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\nDownstream Job: ${JOB_NAME} #${DOWNSTREAM_JOB_NUMBER} (<${DOWNSTREAM_JOB_URL}|Open>)"
slackSend channel: SLACK_CHANNEL, color: 'warning', message: "Unstable: ${JOB_NAME} #${DOWNSTREAM_JOB_NUMBER} (<${DOWNSTREAM_JOB_URL}|Open>)\nStarted by ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\n${build_causes_string}"
}
} else {
if (SLACK_CHANNEL) {
slackSend channel: SLACK_CHANNEL, color: 'danger', message: "Failure in: ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\nDownstream Job: ${JOB_NAME} #${DOWNSTREAM_JOB_NUMBER} (<${DOWNSTREAM_JOB_URL}|Open>)"
}
error "Downstream job ${JOB_NAME} did not pass. Job Number: ${DOWNSTREAM_JOB_NUMBER} Job URL: ${DOWNSTREAM_JOB_URL}"
if (SLACK_CHANNEL) {
slackSend channel: SLACK_CHANNEL, color: 'danger', message: "Failure in: ${JOB_NAME} #${DOWNSTREAM_JOB_NUMBER} (<${DOWNSTREAM_JOB_URL}|Open>)\nStarted by ${env.JOB_NAME} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\n${build_causes_string}"
}
error "Downstream job ${JOB_NAME} did not pass. Job Number: ${DOWNSTREAM_JOB_NUMBER} Job URL: ${DOWNSTREAM_JOB_URL}"
}
}
}
return JOB
}

Expand Down

0 comments on commit ebfc93e

Please sign in to comment.