diff --git a/vars/trySlackSend.groovy b/vars/trySlackSend.groovy new file mode 100644 index 0000000..c077c84 --- /dev/null +++ b/vars/trySlackSend.groovy @@ -0,0 +1,19 @@ +/* + * Sends a notification to Slack. If the Slack Notification Plugin is not + * configured the the notification will be echoed to the Jenkins build log. + */ + +def call(Map args) { + Map colorMap = [ + 'grey' :'#C0C0C0', + 'persian' :'#2020C0', + ] + String channel = args.channel ?: '' + String color = args.color ? colorMap.get(args.color, args.color) : 'good' + + try { + slackSend(channel: channel, color: color, message: args.message) + } catch (NoSuchMethodError err) { + echo 'Slack Notification (' + args.color + '): ' + args.message + } +} diff --git a/vars/trySlackSend.txt b/vars/trySlackSend.txt new file mode 100644 index 0000000..5bbc8e2 --- /dev/null +++ b/vars/trySlackSend.txt @@ -0,0 +1,6 @@ +The trySlackSend function sends a notification to Slack. If the Slack +Notification Plugin is not configured the the notification will be echoed to +the Jenkins build log. + +Takes a string parameter 'message' and optional string parameters 'channel' and +'color'.