Day 75: Setting up Slack for Jenkins

On Day 75 of my DevOps journey, I integrated Slack with Jenkins to receive real-time build notifications. This is a powerful way to stay updated on pipeline results without constantly monitoring Jenkins. Notifications directly in Slack keep the whole team informed about build successes, failures, and other important events.


๐Ÿ”ง Why Slack + Jenkins?

  • Instant Alerts โ€“ No need to refresh Jenkins UI.

  • Team Collaboration โ€“ Everyone gets notified in a shared channel.

  • Quick Debugging โ€“ Failures can be discussed immediately.

  • Customizable โ€“ Control what info is sent and how it looks.


โš™๏ธ Setup Steps

  1. Install Slack Plugin in Jenkins

    • Go to Manage Jenkins โ†’ Plugins โ†’ Available.

    • Search for Slack Notification Plugin and install it.

  2. Configure Slack in Jenkins

    • Create a new Incoming Webhook in Slack.

    • Copy the token and configure it under Manage Jenkins โ†’ Configure System โ†’ Slack.

  3. Update Jenkinsfile for Slack Notifications
    Add a post block to send messages after every build:

     post {
         always {
             echo 'Slack Notifications.'
             slackSend channel: '#jenkinscicd',
                 color: COLOR_MAP[currentBuild.currentResult],
                 message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"
         }
     }
    

    โœ… This ensures a message is sent whether the build succeeds or fails.


๐Ÿ“ฉ Example Slack Notification

  • Green โ†’ Build Success ๐ŸŽ‰

  • Red โ†’ Build Failure โŒ

  • Includes job name, build number, and a link for more details.


๐ŸŒŸ Takeaway

With Slack integrated into Jenkins, CI/CD pipelines become more transparent and collaborative. Instead of chasing logs manually, I now get instant build insights in Slack, keeping the workflow smooth and efficient.

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir