The Ops Community ⚙️

Cover image for Jenkins Ft. Slack : Send Notification For Every State
Nurul Ramadhona
Nurul Ramadhona

Posted on • Updated on

Jenkins Ft. Slack : Send Notification For Every State

Maybe it's an important thing to know how is your deployment like does it work well or not and many more. Jenkins has a plugin that make it easy to do (send notifications). There are many options, it can be sent to email or to popular chat app like Slack.

So let's say you want to be notified when a job build started, the methods used to build job, then also get the results like did it success or fail. Yes, we can send these kinds of notifications to Slack.

1. Download and Install Plugin
But do you remember the steps when we integrate Jenkins with GitHub? I've asked you to remember that for in case we need it later. Now, we'll do same steps for Slack. We need to install plugin for Slack.

Slack 1

2. Provide a Slack Workspace
If you don't have a workspace to use, you can create new one. But if you already prepared, you can skip this step.

Slack 2

Slack 3

Slack 4

Slack 5

Slack 6

Slack 7

3. Manage Credential

  • Go to Jenkins CI.
  • Choose a channel where Jenkins will send the notifications. We can choose the existing channel or create new channel.

Slack 8

Slack 9

Slack 10

Slack 11

  • Click the link provided in the channel. It'll direct you to a page that contains token for Jenkins.

Slack 12

Slack 13

  • Just same as when we add SSH credential, add new credential for Slack but using Secret text type and enter the provided token.

Slack 14

Slack 15

4. Slack Workspace Setup

  • Go to Manage Jenkins => Configure System.
  • On the Slack section, enter Slack's workspace and the default channel as we configured above. The workspace can be found on the left hand side by clicking the name and it's the subdomain of slack.com. For example: jenkins-dhona is the workspace of jenkins-dhona.slack.com.

Slack 16

Slack 17

Slack 18

5. Add Post-Build Action
We've successfully connected with Slack. Now, add post-build action by choosing Slack Notification for the job. Choose the notification types you want.

Slack 19

Slack 20

Slack 21

I also make a change to the shell command to make it fail. I just wanna let you know how it works.

Slack 22

Let's try to build!

Slack 23

Slack 24

Slack 25

Then, I'll fix it back to the correct command. Slack should be get notified again.

Slack 26

Slack 27

Slack 28

Additional: Slack For Multiple Jobs
Since we used one same job from begin, now I'll create new job by copying from the existing job.

Slack 29

From this action, we can create job that very similar with the original one if we don't make any change. So, the Git and Slack integration will be applied too to the copied job (but it's all up to you if you wanna make any change). Let's try to build the new job!

Slack 30

Slack 31

Slack 32

Then, if you want to apply the Slack integration to multiple jobs. You have to configure it to each job, in every single job. The example above is just to show you how if we copy the existing job.

Alright, that's it for now! Any feedback are very welcome and thank you for coming. Follow me to get notified when new post is published by me! Thank you.

Let's continue to the next part!

Top comments (3)

Collapse
 
jatin profile image
Jatin Mehrotra

Thats a great series @nurulramadhona.

I wanted to ask how are you adding series to the blog?
what is the syntax of referencing series within your blog?

Collapse
 
nurulramadhona profile image
Nurul Ramadhona Author

Thank you @jatin

For the series, you have to create new one from the Setting icon that you can find at the bottom of the page when you create new post. Then, you can select existing series for the next post if you already created one.

Collapse
 
jatin profile image
Jatin Mehrotra

thanks a ton !!!!