Skip to end of metadata
Go to start of metadata

Plugin Information

View Slack Notification on the plugin site for more information.

This plugin allows to post build notifications to a Slack channel.

Documentation

The instructions presented below are incomplete. Follow the instructions on the Slack Plugin's GithHub home page.  They work great.

The Slack plugin allows for configuring a default Slack channel, or a Slack channel may be defined on a per build task basis.  There are several things that need to be done to get the Slack plugin working.  The projects home page is on Github.

Global configuration

  1. Configure the "Jenkins", "Manage Jenkins", "Configure System", "Global Slack Notifier Settings" values.  Scroll to the bottom of the screen or search for the word "Slack" to find the entry.
  2. Enter the Team domain, Integration Token, and Build Server URL into the indicated text fields.
  3. If you have a default channel name (e.g. #builds) enter this name into the "Channel" text field.
  4. If you have entered a default channel name, click the "Test Connection" button.
  5. Verify a test message is displayed in the default Slack channel.

Project Configuration

  1. Configure the "Jenkins", <project>, "Configure", "Slack Notifications" values.
  2. Select the check boxes for the notifications desired when the build task is executed.
  3. If the project has a different channel from the default perform the following steps.
    1. Click on the "Advanced..." button.
    2. Enter the "Team Domain", "Integration Token" (probably the same as the Global token), and "Project Channel" name in the indicated text fields.  Do not rely on the defaults to populate any of the fields.  Enter the information even if it is redundant with the Global configuration. 
  4. Click on the "Test Connection" button.
  5. Verify a test message was sent to the appropriate Slack channel.
  6. Click on the "Save" button to retain these changes.

 

Post-build Actions

If you forget this section, the test buttons will show the channel test messages, but the build execution will not post anything to the channel.

  1. Scroll to the "Post-build Actions" section of the project configuration.
  2. Click on the "Add post-build action" button.
  3. Select the "Slack Notifications" entry from the list displayed.  The "Slack Notifications" section will appear in the window.
  4. Click on the "Save" button to retain these changes.

      

Jenkins Pipeline Support

slackSend channel: '#jenkins-latest', color: 'good', message: 'Slack Message', teamDomain: 'beedemo', token: 'token'

Test the configuration

Once the project has been configured run a test build and confirm the Slack messages are posted as expected.

Configure plugin via Groovy script

Either automatically upon Jenkins post-initialization or through Jenkins script console, example:

import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.Domain
import com.cloudbees.plugins.credentials.impl.*
import hudson.util.Secret
import java.nio.file.Files
import jenkins.model.Jenkins
import net.sf.json.JSONObject
import org.jenkinsci.plugins.plaincredentials.impl.*

// parameters
def slackCredentialParameters = [
  description:  'Slack Jenkins integration token',
  id:           'slack-token',
  secret:       '1234567890asdfghjklqwert'
]

def slackParameters = [
  slackBaseUrl:             'https://mycompany.slack.com/services/hooks/jenkins-ci/',
  slackBotUser:             'true',
  slackBuildServerUrl:      'https://jenkins.mycompany.com:8083/',
  slackRoom:                '#jenkins',
  slackSendAs:              'Jenkins',
  slackTeamDomain:          'mycompany',
  slackToken:               '',
  slackTokenCredentialId:   'slack-token'
]

// get Jenkins instance
Jenkins jenkins = Jenkins.getInstance()

// get credentials domain
def domain = Domain.global()

// get credentials store
def store = jenkins.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()

// get Slack plugin
def slack = jenkins.getExtensionList(jenkins.plugins.slack.SlackNotifier.DescriptorImpl.class)[0]

// define secret
def secretText = new StringCredentialsImpl(
  CredentialsScope.GLOBAL,
  slackCredentialParameters.id,
  slackCredentialParameters.description,
  Secret.fromString(slackCredentialParameters.secret)
)

// define form and request
JSONObject formData = ['slack': ['tokenCredentialId': 'slack-token']] as JSONObject
def request = [getParameter: { name -> slackParameters[name] }] as org.kohsuke.stapler.StaplerRequest

// add credential to Jenkins credentials store
store.addCredentials(domain, secretText)

// add Slack configuration to Jenkins
slack.configure(request, formData)

// save to disk
slack.save()
jenkins.save()

Changelog

Also on Github

43 Comments

  1. I have set up the integration with Jenkins and tested connection from Configure System@Jenkins and it worked OK. Than I added Slack notification post build action for some job and executed it. When the job is completed, I do not get any notification on my Slack channel. Anyone with the same issue?

    1. Yes, our Linux Jenkins server has the same problem.  Our test post goes through great.  Nothing else makes it to the Slack Channel.

      I found out our problem was that we hadn't turned on the post build action for Slack.

  2. The plugin works well and shows notification in slack upon build failure for first time but for the second time build failure i don't get any notifications. I don't see any option Notify Repeated Failure either. Please help I am using v1.8.1 which is the latest version.

    1. Hi Venkata,

      I think that is supposed to be a feature :)

      If you want continued nagging about broken builds, you can ask for it, by setting this in your job(s) configurations:

      Slack Notifications > Advanced (button at bottom right of Slack Notifications) > Notify Repeated Failure > checkbox

      Hope this helps!

  3. I've just upgraded to 2.0 from 1.8.1. I now get the fiollowing NPE...

    java.lang.NullPointerException
    at java.util.TreeMap.put(TreeMap.java:568)
    at java.util.TreeSet.add(TreeSet.java:267)
    at jenkins.model.Jenkins.getUnprotectedRootActions(Jenkins.java:3916)
    at jenkins.model.Jenkins.getTarget(Jenkins.java:3885)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:674)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
    at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:132)
    at hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:59)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:129)
    at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:123)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:49)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
    at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:135)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
    at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
    at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:370)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
    at java.lang.Thread.run(Thread.java:863)
    

    What's changed that would cause this?

    1. I should add that I'm running Jenkins 1.652.

  4. It seems odd that the config is not in the Post-build action, as is typical for other post-build actions (pretty sure).

    I found this confusing when following someone else's config, because the Post-build "Slack Notifications" widget has no information at all. Does it have to be separate like that?

  5. I see a section for Slack Webhook Settings in the global configuration settings. Can someone explain how how to use this?

  6. Thanks for providing an example on using this plugin with Pipelines. It would be even better if you could extend it a little bit to tag the person that triggered the build or all the committers. Now the "Slack message" body is not really useful.

  7. Hi!

    We are using this plugin a lot and I have a question about it.

    I changed the configuration setting "Global Slack Notifier Settings / Build Server URL" but in all Slack messages still contains old server URL.
    Do we have to restart Jenkins to make new setting work?

    Regards, Primoz.

  8. We are using this plug-in extensively to notify us during the post-build phase.  
    Is there support for a Slack widget during the pre-build phase?

    1. I only found a way to send post build notifications.

      But, is it possible to send a notification before build ?

  9. Is there a way to use slackSend to send a message to particular user?

  10. Is it possible to add pipeline support towards the include test summary option ?

  11. Hello,  I have slack plugin configured in Jenkins 1.651.3 and it publishes build status such as `Smoke-Tests - #1234 Unstable after 4 min 53 sec (Open)` but I would like for it to also publish detailed counts such as  `Test Status: Passed: 76, Failed: 0, Skipped: 0`.   I am using TestNG and the job's "Publish JUnit test result report" is configured as "**/test-output/junitreports/*.xml".   My understanding is that when publishing JUnit test result report, the Slack plugin should automatically publish the test result count, but this is not happening.

     

    Could you please advise?  Thank you.

  12. How to trigger a notification in matrix project? I would like to send consolidated notification for parent job.

    1. I have found one way, that uses Parameterized Trigger Plugin

      You need a separate job just for sending notifications that accepts a single string parameter for the success message. It will then use the parameter as a customised message in the slack plugin.

      Then on the matrix project, Add a post-build action to "Trigger parameterized build on other projects" to pass a success message to that separate job. This works as it only gets build after all matrix configurations are built.

  13. Upgraded to Jenkins ver. 2.60.2 with Slack Notification Plugin 2.2 but the testing runs in an infinite loop with no message occurring in slack. Logs give no info why this happens :(  

    1. I finally got something from the logs (with including a test message in my pipeline)

      Aug 11, 2017 1:16:18 PM hudson.security.csrf.CrumbFilter doFilter
      WARNING: No valid crumb was included in request for /secrettoken. Returning 403.
      Aug 11, 2017 1:16:18 PM jenkins.plugins.slack.StandardSlackService publish
      WARNING: Slack post may have failed. Response: <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Error 403 No valid crumb was included in the request</title>
      </head>
      <body><h2>HTTP ERROR 403</h2>
      <p>Problem accessing /secrettoken. Reason:
      <pre>    No valid crumb was included in the request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
      
      </body>
      </html>
      
      Aug 11, 2017 1:16:18 PM jenkins.plugins.slack.StandardSlackService publish
      WARNING: Response Code: 403
      Aug 11, 2017 1:16:18 PM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
      
      
      1. Christian,

        You need to add https://<yourteam>.slack.com/services/hooks/jenkins-ci/

        to the BASE URL.

        Thanks.

        -Nadeem Syed

        1. Nadeem Syed: Do you we need to configure something else? I gave the base URL as per your suggestion  https://<yourteam>.slack.com/services/hooks/jenkins-ci/ (replaced yourteam with my team name) but I get no token. Any help?

          1. Ok, here is what you need to do.

            Option 1. If you have slack channel already created, then ask your slack admin to give you the token for that channel.

            Option 2. Ask your slack admin to create a new channel and get the token for that channel.

            I. In Team Subdomain: type the name of <yourteam> as mentioned in my last post

            2. copy paste the Slack Token you got from option 1 or 2, in Integration Token edit box. Then copy the channel name from option 1 or 2 as #<yourchannel> name and test connection by clicking on Test Connection button.  And OR

             3. in Integration Token Credential ID edit box, click on Add Key button. A pop will display (see below image). 

            4. In the Kind dropdown select Secret Text.

            5. In the Secret  edit box, copy the token you got from  Option 1 or 2 above.

            6. Give it name in Description. eg. slackjenkins

            7. Click Add button and you will be back on configuration page

            8. Make sure in Integration Token Credential ID dropdown , you have newly created id in step 6 selected

            9. Click on Test, And if you see success then click on apply and save.

             

             

            Below is image of how my settings look like.

             

             

            1. Like this?

               

               

              That is now exactly what I testing all the time (wink) Unfortunately the "Testing" spinner spins until eternity.

              1. If you setup everything correctly then it should have worked. Did you check the Jenkins log? Also see if you have any network or firewall setting that might preventing it to connect. If nothing works then ask your Slack Admin to regenerate a new token for your channel and then update the token in your settings as I mentioned in my previous post and try again.

  14. Hi, can anyone confirm if the Slack integration plug-in is able to notify private channels? Or only public ones?

    1. Can someone answer this question please?

      1. Yes it sends notification to private channel, you need to configure Integration Token and base url at `Global Slack Notifier Settings` at https://yourjenkins/configure

  15. How can this be used with MultiBranch Pipeline workflow? 

  16. It appears that the plugin does not correctly replace environment variables when it sends out "started" messages.  For example, ${COMMIT_BRANCH} is not resolved for the started message, but it is on success:

    Feature Branch Build - #1095 Started by changes from Daniel Kirkdorffer (6 file(s) changed) (Open)
    Branch: ${COMMIT_BRANCH}
    Feature Branch Build - #1095 Success after 2 min 34 sec (Open)
    No Tests found.
    Branch: EPC-648_Ordering_Filters

     

    This seems like a bug to me.  I can't see why the plugin wouldn't know the COMMIT_BRANCH when it sends out the "started" message.

  17. I do not receive a notification in Slack if the project has fallen, tell me what can be the reason

  18. Thanks for developing this useful plugin! I have a small suggestion. I use Matrix Jobs often and it used to be the case (at least in version 1.8) that I'd get one notification per job. As of 2.2 I get one notification per job configuration which is way, way too verbose. Is there a way to get back the previous behaviour? Thanks!

  19. Hi. How do I put attachments (such as buttons) on my post-build notifications?

  20. Hi,

    When i try to use slack plugin i get  this message.

    WARNING: Error posting to Slack

                                                     
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

  21. Hello,

    I use Jenkins 2.63 with and Slack Notifier plugin 2.2

    I need to generate Jobs with SlackNotifier by Job DSL but  I can not set the Base URL in the DSL, I get this message :

    ERROR: (script, line 145) No signature of method: baseUrl() is applicable for argument types: (java.lang.String) values: [https://my.domain.slack.com/services/hooks/jenkins-ci/] Possible solutions: authToken(), authTokenCredentialId(), botUser(), commitInfoChoice(), customMessage(), includeCustomMessage(), includeTestSummary(), notifyAborted(), notifyBackToNormal(), notifyFailure(), notifyNotBuilt(), notifyRegression(), notifyRepeatedFailure(), notifySuccess(), notifyUnstable(), room(), sendAs(), startNotification(), teamDomain() Finished: FAILURE

     here is my DSL script

                publishers  {
                  def slackParam = new groovy.json.JsonSlurper().parse(new File(channelFile))

                  slackNotifier {
                    baseUrl(slackParam.url)
                    authTokenCredentialId(slackParam.authTokenCredentialId) 
                    includeTestSummary(true)
                    notifyAborted(true)
                    notifyBackToNormal(true)
                    notifyFailure(true)
                    notifyNotBuilt(true)
                    notifyRegression(true)
                    notifyRepeatedFailure(true) 
                    notifyUnstable(true)
                    room(slackParam.room) 
                  }
                }

     

    But in the job config.xml I can find this parameter.

    Can anyone help me to set the base URL parameter ?

    Thanks a lot.

    Wognin

     

    1. Your Syntax looks very strange... Why do you use method calls instead of parameters?

      I already use a different Plugin but this is how my Syntax looks like:

      slackSend(
          color: '#00a00d',
          message: "The pipeline *${currentBuild.fullDisplayName}* completed *successfully*."
      )
  22. Not strange, it's Job DSL synthaxe.

    Il you have Jenkins with Job DSL plugin installed, you can browse this url :

    http://host:port/plugin/job-dsl/api-viewer/index.html#path/job-publishers-slackNotifier.

    And you will see the documentation of slackNotifier plugin.

    Best regards,

    1. I can not access this page due to not having this plugin installed. But searching the wiki I find this https://plugins.jenkins.io/job-dsl and the syntax clearly IS different!

      And also your error message        

      ERROR: (script, line 145) No signature of method: baseUrl() is applicable for argument types: (java.lang.String)

      shows clearly that there is no method baseUrl. 

      Quoting the wiki for the Syntax:

      Basics

      The DSL allows the definition of a job, and then offers a useful set of functions to configure common Jenkins items. A configure is available to give direct access to the config.xml before generating the job. The script is groovy code, which can be very powerful. Here's an example to create a job for each branch in a git repo:

      def project = 'quidryan/aws-sdk-test'
      def branchApi = new URL("https://api.github.com/repos/${project}/branches")
      def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
      branches.each {
          def branchName = it.name
          def jobName = "${project}-${branchName}".replaceAll('/','-')
          job(jobName) {
              scm {
                  git("git://github.com/${project}.git", branchName)
              }
              steps {
                  maven("test -Dproject.name=${project}/${branchName}")
              }
          }
      }
      1. Yes this method "baseUr" is absent but it should not because it's present in the config.xml of the job so I should be able to have it through Job DSL.

        That the problem, so I'm looking to know how to set the base url other way in the JOB DSL.

        Thanks a lot.

  23. Dears Slack Plugin developpers,

    Can anyone help me to set the Job's "baseUrl" parameter in job DSL ?

    Thanks a lot.

  24. "Test Connection" button returns "Failure". All settings are correct. Was working a few days ago. Not sure what's wrong.

    1. I'm suffering from the the same issue since I've upgraded to the last version (2.3). 

  25. Hello,

    Since, I upgraded the plugin version from 2.0 to 2.3, I got the error bellow each one I hit the button "Test connection" :

    java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory
    	at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:912)
    	at jenkins.plugins.slack.StandardSlackService.getHttpClient(StandardSlackService.java:200)
    	at jenkins.plugins.slack.StandardSlackService.publish(StandardSlackService.java:132)
    	at jenkins.plugins.slack.StandardSlackService.publish(StandardSlackService.java:95)
    	at jenkins.plugins.slack.SlackNotifier$DescriptorImpl.doTestConnection(SlackNotifier.java:510)
    	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:625)
    	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343)
    	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:184)
    	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:117)
    	at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:129)
    	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
    	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
    Caused: javax.servlet.ServletException

     

    Any chance someone knows how to fix this ? 

     

    Thanks in advance.

  26. Hello,

    What are the goal of "Outgoing Webhook Token" and "Outgoing Webhook URL Endpoint" in section Slack Webhook Settings of the global configuration?

    Thanks.

Write a comment…