slack-plugin
slack-plugin copied to clipboard
Ability to have multiple Slack-Notifications as Post-Build-Actions
Feature request:
Right now, it appears as though I can add "Slack-Notifications" once for a job, but I would love to be able to more granularly add notifications, ie have separate channels for success and failure.
Any time I see a message in the failure channel, I drop everything that I'm doing and go check it out, but I would also like to receive messages about successes.
Please advise if there's a better place to put this feature request.
i have 2 slack steps as post-build steps. one as regular post-build and one in flexible publish. The job config file has both however, their setting are identical and equal to whichever one is first in the sequence.
If I edit manually the job config file, will the different sets of paramters stay put?
Hi @richardpringle,
You can achieve that by using Jenkins Declarative Pipeline OR Scripted Pipeline.
A job example (Jenkinsfile);
pipeline {
agent { label 'master' }
options {
disableConcurrentBuilds()
timeout(time: 10, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '10'))
} // options
parameters {
string(name: 'SLACK_CHANNEL_1',
description: 'Default Slack channel to send messages to',
defaultValue: '#my_channel_1')
string(name: 'SLACK_CHANNEL_2',
description: 'Default Slack channel to send messages to',
defaultValue: '#my_channel_2')
} // parameters
environment {
// Slack configuration
SLACK_COLOR_DANGER = '#E01563'
SLACK_COLOR_INFO = '#6ECADC'
SLACK_COLOR_WARNING = '#FFC300'
SLACK_COLOR_GOOD = '#3EB991'
} // environment
stages {
stage("Check requirements") {
steps {
// get user that has started the build
wrap([$class: 'BuildUser']) { script { env.USER_ID = "${BUILD_USER_ID}" } }
// first of all, notify the team
slackSend (color: "${env.SLACK_COLOR_INFO}",
channel: "${params.SLACK_CHANNEL_1}",
message: "*STARTED:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${env.USER_ID}\n More info at: ${env.BUILD_URL}")
// now, check the requirements
script {
// binaries - host machine
echo "Checking binaries"
sh "ssh -V"
} // script
} // steps
} // stage
stage("Clean Workspace") {
steps {
echo "Cleaning-up job workspace"
deleteDir()
} // steps
} // stage
} // stages
post {
aborted {
echo "Sending message to Slack"
slackSend (color: "${env.SLACK_COLOR_WARNING}",
channel: "${params.SLACK_CHANNEL_2}",
message: "*ABORTED:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${env.USER_ID}\n More info at: ${env.BUILD_URL}")
} // aborted
failure {
echo "Sending message to Slack"
slackSend (color: "${env.SLACK_COLOR_DANGER}",
channel: "${params.SLACK_CHANNEL_2}",
message: "*FAILED:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${env.USER_ID}\n More info at: ${env.BUILD_URL}")
} // failure
success {
echo "Sending message to Slack"
slackSend (color: "${env.SLACK_COLOR_GOOD}",
channel: "${params.SLACK_CHANNEL_1}",
message: "*SUCCESS:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${env.USER_ID}\n More info at: ${env.BUILD_URL}")
} // success
} // post
} // pipeline
I understand that you were trying to achieve it through Jenkins UI and it seems that it is not possible at the moment, thus, I think that the feature request should still open to have this option for those who prefer to stick to the graphical mode. This is just a workaround.
If you need, you can find more information about the declarative pipeline here.
Cheers!
👍 thanks @ivan-pinatti
Thanks @ivan-pinatti
What's the status of above? Is it on the roadmap? Is it a slack plugin or Jenkins related issue?
Unlikely to happen, unless someone contribute it, but it's not an easy feature to do. Easily achieved with pipeline