Integrating Slack with Jenkins allows you to receive build notifications directly in your Slack channels, which helps in monitoring the status of your CI/CD pipeline. Here’s a step-by-step guide to set up this integration:
1) Create Slack Account - First create a Slack account and then subsequently the slack workspace and channel:-
- Give your workspace name and some more details:-
- Select your team mates to include them. If you are individual then you can skip this. Select the free trial:-
- Once you selected, Dashboard will look like:-
- Create a channel (I have given name as 'cicd-implementation')
2) Create Token - Now we need to create a token for Jenkins to authenticate slack and for that we need to add an app into our slack account. Refer below steps:-
- Do a google search 'slack app'
- Open the first link ‘Add app to Slack’ and search for Jenkins:-
- Click on ‘Add to Slack’
- Select the channel and ‘Add Jenkins to CI Integration’. For me it would be 'cicd-implementation'
- In the same page, refer the steps to integrate slack with Jenkins. Also copy the token given in step 3 and save it somewhere. Now come down and click on ‘Save Settings’
3) Integrate Jenkins & Slack - Now we will go to Jenkins and integrate the slack by using plugins and slack token.
- Go to Jenkins (Manage Jenkins-> Plugins-> Available Plugins) and look for slack notification plugins and install it.
- Now, lets integrate the slack with Jenkins. Go to Manage Jenkins-> Systems and look out for Slack plugin.
- Get your Slack workspace name correctly as this could cause issue when you are going to test connection in Jenkins. Refer below to get your slack workspace name:-
- Provide workspace name based on slack setup and click add credential
- Select 'Secret text', add the token which you have copied earlier and then give some ID & description. Later click on Add button.
- Select the 'slackpass', give the channel id and then click on test connection.
- A 'success' message should show over here to make sure there is proper integration between Jenkins and Slack.
Note:- It might be possible that you may get Failure message here, this could be because of some setup or plugins issue. So you can just logout from your slack account, login back and do the whole setup again. You should be able to see success message.
- Lets add these things in our pipeline code. Add below set of codes to your pipelines. Here define a function to do color mapping in slack. In slack 'good' means green color and 'danger' means red.
- Its time to create a new pipeline and paste your Pipeline as a code to Jenkins and test.
- Go to Slack channel and see if there any message coming in with 'Success'?
- If the pipeline failed then you will see the red color in your slack channel with 'Failed' message
Conclusion!
This configuration sends notifications to Slack on build success and failure with links to the Jenkins build.
By following these steps, you should be able to integrate Slack with Jenkins and receive notifications in your specified Slack channels.
Happy Learnings!
Top comments (0)