Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created January 18, 2020 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThabetAmer/4a01aa6cbabad052b815a63ff9359cfe to your computer and use it in GitHub Desktop.
Save ThabetAmer/4a01aa6cbabad052b815a63ff9359cfe to your computer and use it in GitHub Desktop.
Jenkins Groovy function to return an emoji from a pool based on the build status, can be used with Slack notifications
#!/usr/bin/env groovy
/**
* Returns an emoji from a pool based on the build status, can be used with Slack notifications
* @author thabet.amer@gmail.com
* @since Jenkins 2.204.1
* @param String status default 'success'
* @return String emoji
*
*/
def getEmoji(String status = "success") {
def emojis = status == "success" ?
[":v:", ":ok_hand:", ":clap:", ":man_dancing:", ":trollface:",
":rocket:", ":ghost:", ":thumbsup:", ":tada:", ":confetti_ball:"]
:
[":thumbsdown:", ":scream_cat:", ":triumph:", ":rage:", ":bangbang:",
":see_no_evil:", ":hear_no_evil:", ":speak_no_evil:", ":gun:"]
def RandomIndex = (new Random()).nextInt(emojis.size())
return emojis[RandomIndex]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment