Process Flow - Slack notifications
Jenkins Job Starts
Build Executes
Check Build Result
Send Slack
Success Msg
Notification Sent
Jenkins runs a job, checks if it succeeded or failed, then sends a Slack message accordingly.
pipeline {
agent any
stages {
stage('Build') {
steps { echo 'Building...' }
}
}
post {
success { slackSend channel: '#general', message: 'Build succeeded!' }
failure { slackSend channel: '#general', message: 'Build failed!' }
}
}| Step | Build Status | Action | Slack Message | Notification Sent |
|---|---|---|---|---|
| 1 | N/A | Start build | N/A | No |
| 2 | Running | Execute build steps | N/A | No |
| 3 | Success | Check post conditions | Build succeeded! | Yes |
| 4 | End | Finish pipeline | N/A | No further notifications |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| buildStatus | N/A | Running | Success | Success |
| slackMessage | N/A | N/A | Build succeeded! | Build succeeded! |
| notificationSent | No | No | Yes | Yes |
Jenkins Slack Notifications: - Use 'post' section in pipeline for notifications - 'success' and 'failure' blocks send messages - Use slackSend step with channel and message - Notifications happen after build completes - Customize messages per build result
slackSend step must be inside the post section to run after job completion.post { always { slackSend ... } } which is the correct syntax to send notifications after any build result.pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
success {
slackSend channel: '#dev', message: 'Build succeeded!'
}
}
}post { success { ... } } block runs only if the job finishes successfully.slackSend step inside success sends the message to the specified Slack channel.post {
always {
slackSend channel: '#alerts', message: 'Job finished'
}
}post { failure { ... } } block runs only when the job fails.env.VAR_NAME inside double quotes with ${} syntax."Job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed" to include dynamic info.Pass the test and this pattern moves unknown