Jenkins + Slack = ChatOps

Updated: Sep 4, 2020











Hello Readers , hope you liked our series of articles on Jenkins. Once we are done with our setup and jobs are up and running as desired. Next thing is getting a notification on timely basis which will let us know whether the build was a success or a failure.


There are a number of ways to get the notification eg. via email, here we will discuss about how to get jenkins notification on one of the most popular chat messenger i.e. Slack


Below steps will let us integrate slack with Jenkins.



  • Go to this link and sign in with slack . It will ask us for the email id and then we will create a workspace where we will add our team members who should get the jenkins notifications. ( I have created a workspace with the name LinuxAdvise)

  • Once we are inside the slack , we will create a channel and here we will invite the team members who will get slack notifications.







  • In the next step, we will add a slack application called Jenkins CI to our slack channel.




  • Once we add the app to slack channel, steps will be auto-populated but there are a few changes . Exact steps are given below.






  • Go To Jenkins Console -- Manage Jenkins -- Manage Plugins -- Click on Available Tab -- Install Slack Notification




  • After the plugin has been installed, Go to Manage Jenkins -- Configure System -- Under Slack -- Create a credential of type secret text( and provide the token which was generated when application was added to slack channel.)




Once the secret is configured, do the below configuration according to your parameter values.




  • Click on Test Connection and it should be successful.





Note: Please remember to replace the Integration Token in the screenshot below with your own.


Once everything is in place create and build below pipeline



pipeline{
    agent any 
    stages{
        stage("HelloWorld"){
        steps{
            echo "Hello World"
            
        }
    }
    stage(SlackNotification){
        steps{
            slackSend channel: 'jenkins-notifications', message: "started ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)", teamDomain: 'linuxadviseworkspace', tokenCredentialId: 'slack-token'
        }
    }
}
}

  • Once we execute the job will get the notification as below.




Hope this was helpful. Thanks for reading.
















470 views0 comments
 

Subscribe Form

©2020 by Linux Advise