Skip to content
Latchkey

How to Post a Slack Notification from a Jenkins Pipeline

Jenkins posts to Slack with the Slack Notification plugin's slackSend step, usually from a post block.

Install and configure the Slack Notification plugin (workspace + token), then call slackSend in a post { failure {} } (or always) block so results reach a channel.

Notify Slack on failure

The post block posts a red message to Slack only when the build fails.

Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Test') {
      steps { sh 'npm ci && npm test' }
    }
  }
  post {
    failure {
      slackSend(
        channel: '#builds',
        color: 'danger',
        message: "Build FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER} (${env.BUILD_URL})"
      )
    }
  }
}

Gotchas

  • slackSend needs the Slack Notification plugin configured globally with a workspace and token credential.
  • Put notifications in a post block so they fire on the final result, not mid-stage.
  • Use color: 'danger'/'good'/'warning' (or a hex) - arbitrary status strings are ignored.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →