Unverified Commit cbcf2ff8 authored by Keshav Prasad's avatar Keshav Prasad Committed by GitHub
Browse files

fix: Adding exception block for missing env var

Showing with 41 additions and 36 deletions
+41 -36
def call(String status) {
try {
ansiColor('xterm') {
String ANSI_GREEN = "\u001B[32m"
String ANSI_NORMAL = "\u001B[0m"
String ANSI_BOLD = "\u001B[1m"
String ANSI_RED = "\u001B[31m"
String ANSI_YELLOW = "\u001B[33m"
stage('slack_notify') {
mainDir = sh(returnStdout: true, script: "echo $JOB_NAME").split('/')[-4].trim()
channel_env_name = mainDir.toUpperCase() + "_NOTIFY_SLACK_CHANNEL"
slack_channel = evaluate "$channel_env_name"
if(status == "FAILURE"){
slack_status = 'danger'
build_status = "Failed"
}
else {
slack_status = 'good'
build_status = "Succeded"
}
if (slack_channel != null)
slackSend (
channel: slack_channel,
color: slack_status,
message: "Build ${build_status} - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
)
else if(env.GLOBAL_NOTIFY_SLACK_CHANNEL != null)
slackSend (
try {
ansiColor('xterm') {
String ANSI_GREEN = "\u001B[32m"
String ANSI_NORMAL = "\u001B[0m"
String ANSI_BOLD = "\u001B[1m"
String ANSI_RED = "\u001B[31m"
String ANSI_YELLOW = "\u001B[33m"
stage('slack_notify') {
env = sh(returnStdout: true, script: "echo $JOB_NAME").split('/')[-3].trim()
channel_env_name = env.toUpperCase() + "_NOTIFY_SLACK_CHANNEL"
try {
slack_channel = evaluate "$channel_env_name"
}
catch (MissingPropertyException ex) {
println ANSI_YELLOW + ANSI_BOLD + "Could not find env specific Slack channel.." + ANSI_NORMAL
}
if(status == "FAILURE"){
slack_status = 'danger'
build_status = "Failed"
}
else {
slack_status = 'good'
build_status = "Succeded"
}
if (slack_channel != null)
slackSend (
channel: slack_channel,
color: slack_status,
message: "Build ${build_status} - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
)
else if(env.GLOBAL_NOTIFY_SLACK_CHANNEL != null)
slackSend (
channel: "${env.GLOBAL_NOTIFY_SLACK_CHANNEL}",
color: slack_status,
message: "Build ${build_status} - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
)
else
println ANSI_YELLOW + ANSI_BOLD + "Could not find slack environment variable. Skipping slack notification.." + ANSI_NORMAL
}
)
else
println ANSI_YELLOW + ANSI_BOLD + "Could not find slack environment variable. Skipping slack notification.." + ANSI_NORMAL
}
}
catch (err){
throw err
}
}
}
catch (err){
throw err
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment