Created
April 11, 2018 20:30
-
-
Save lvthillo/35ee5b1e5806b216657409ff04a3b01d to your computer and use it in GitHub Desktop.
Groovy script to send Slack Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
} | |
} |
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
NA