Skip to content

Instantly share code, notes, and snippets.

@lvthillo
Created April 11, 2018 20:30
Show Gist options
  • Save lvthillo/35ee5b1e5806b216657409ff04a3b01d to your computer and use it in GitHub Desktop.
Save lvthillo/35ee5b1e5806b216657409ff04a3b01d to your computer and use it in GitHub Desktop.
Groovy script to send Slack Notifications
#!/usr/bin/env groovy
def call(String buildResult) {
if ( buildResult == "SUCCESS" ) {
slackSend color: "good", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was successful"
}
else if( buildResult == "FAILURE" ) {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was failed"
}
else if( buildResult == "UNSTABLE" ) {
slackSend color: "warning", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was unstable"
}
else {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} its resulat was unclear"
}
}
@harikrishna456
Copy link

NA

@puneet-kr-sh
Copy link

puneet-kr-sh commented Mar 18, 2021

Hi !
This is to send a message in slack channel via message: parameter of slackSend, can you please share an example using the blocks: parameter of slackSend ?
I have generated the block code from https://app.slack.com/block-kit-builder/ to send that to a slack but there is some syntax error with groovy script.

Sample block :
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New Paid Time Off request from <example.com|Fred Enriquez>\n\n<https://example.com|View request>"
}
}
]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment