Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
vars: Add trySlackSend function
Browse files Browse the repository at this point in the history
Adds a new library function trySlackSend that echos the message to the
build log if the Slack Notification Plugin is not configured.

Signed-off-by: Geoff Levand <geoff@infradead.org>
  • Loading branch information
glevand committed Feb 23, 2018
1 parent 8c4fabe commit 05af62c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions vars/trySlackSend.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions vars/trySlackSend.txt
Original file line number Diff line number Diff line change
@@ -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'.

0 comments on commit 05af62c

Please sign in to comment.