beiryu
  • Projects
  • Blog
  • About

© 2026 Khanh Dinh. I build software and write about the journey.

  • GitHub
  • LinkedIn
  • X
April 26, 2024 · 0 views

Jenkins Slack Integration

The tutorial outlines how to integrate Jenkins and Slack for monitoring CI/CD pipelines. It involves setting up a custom Slack app to receive messages from Jenkins, configuring Jenkins with the Slack Notification plugin, and adding the OAuth token from Slack as a secret text credential in Jenkins. Both traditional Jenkins jobs and Jenkins pipelines can be configured to send Slack notifications, with pipeline scripts used to send messages in the latter case.

  • DevOps

Overview#

When our teams are responsible for DevOps practices, we often need to monitor builds and other automated jobs.

In this tutorial, we’ll see how to configure two popular platforms, Jenkins and Slack, to work together and tell us what’s happening while our CI/CD pipelines are running.

Setting up Slack#

Let’s start by configuring Slack so Jenkins can send messages to it. To do this, we’ll create a custom Slack app, which requires an Administrator account.

In Slack, we’ll create an application and generate an OAuth token:

  • Visit https://api.slack.com
  • Login to the desired workspace
  • Click the Start Building button
  • Name the application Jenkins and click Create App
  • Click on OAuth & Permissions
  • In the Bot Token Scopes section, add the chat:write scope
  • Click the Install App to Workspace button
  • Click the Accept button

When this is done, we’ll see a summary screen:

Now, we need to take note of the OAuth token — we’ll need it later when we configure Jenkins. We should treat these as sensitive credentials and keep them safe.

To complete the Slack setup, we must invite the new Jenkins user into the channels we wish it to use. One easy way to do this is to mention the new user with the @ character inside each channel.

Setting up Jenkins#

To set up Jenkins, we’ll need an administrator account.

First, let’s start by logging into Jenkins and navigating to Manage Jenkins > Plugin Manager.

Then, on the Available tab, we’ll search for Slack:

Let’s select the checkbox for Slack Notification and click Install without restart.

Now, we need to configure new credentials. Let’s navigate to Jenkins > Credentials > System > Global Credentials and add a new Secret text credential:

We’ll put the OAuth token from Slack into the Secret field. We should also give these credentials a meaningful ID and description to help us easily identify them later. The Jenkins credentials store is a safe place to keep this token.

Once we save the credentials, there is one more global configuration to set. Under Jenkins > Manage Jenkins > Configure System, we need to check the Custom slack app bot user checkbox under the Slack section:

Now that we’ve completed the Jenkins setup, let’s look at how to configure Jenkins jobs and pipelines to send Slack messages.

Image

Configuring a Traditional Jenkins Job#

Image

Traditional Jenkins jobs usually execute one or more actions to accomplish their goals. These are configured via the Jenkins user interface.

In order to integrate a traditional job with Slack, we’ll use a post-build action.

Let’s pick any job, or create a new one. When we drop down the Add post-build action menu, we’ll find Slack Notifications:

Once selected, there are lots of available inputs to the Slack Notification action. Generally, most of the default values are sufficient. However, there are a few required pieces of information:

  • Which build phases to send messages for (start, success, failure, etc)
  • The name of the credentials to use – the ones we added previously
  • The Slack channel name or member ID to send messages to

We can also specify additional fields if desired, such as commit information used for the Jenkins job, custom messages, custom bot icons, and more:

When setting things up via the UI, we can use the Test Connection button to ensure that Jenkins can reach Slack. If successful, we’ll see a test message in the Slack channel from the Jenkins user:

If the message doesn’t show up, the Jenkins log files are useful for troubleshooting. Generally, we need to double-check that the post-build action has all required fields, that the OAuth token was copied correctly, and that the token was granted the proper scopes when we configured Slack.

Image

Configuring a Jenkins Pipeline#

Jenkins Pipelines differ from traditional jobs. They use a single Groovy script, broken into stages, to define a build. They also don’t have post-build actions, so we use the pipeline script itself to send Slack messages

The following snippet sends a message to Slack from a Jenkins pipeline:

  slackSend botUser: true,
  channel: 'builds',
  color: '#00ff00',
  message: 'Testing Jekins with Slack',
  tokenCredentialId: 'slack-token'

Just like with the traditional Jenkins job setup, we must still specify a channel name and the name of the credential to use.

Via a Jenkins pipeline, we can also use a variety of additional Slack features, such as file upload, message threads, and more.

One downside to using Jenkins pipelines is that there’s no test button. To test the integration with Slack, we have to execute the whole pipeline.

When first setting things up, we can create a new pipeline that contains only the Slack command while we’re getting things working.

Image

Conclusion#

Image

In this article, we’ve seen how to integrate Jenkins and Slack to gain feedback on our CI/CD pipelines.

Using a Jenkins plugin, along with a custom Slack application, we were able to send messages from Jenkins to Slack. This allows teams to notice the status of Jenkins jobs and address issues more quickly.

Enjoyed this? Get the next one by email.

Keep reading

Sep 18, 2024

Gaming Industry from the Inside: My Gameloft Experience

After facing challenges in job hunting and going through a rigorous 5-round interview process at Gameloft, I found myself in a professional environment that values work-life balance, documentation, and team bonding. The experience at Gameloft, from the welcoming first day to memorable team trips to Vinh Hy and Cam Ranh, has shown me that a workplace can be more than just about work - it can be a place where lasting relationships are built and professional growth is nurtured.

Sep 6, 2024

Consolidate various health tracking platforms (Garmin, Polar, Apple Watch, etc.) into a single system.

In the ever-evolving landscape of digital health, the need for a unified platform that consolidates data from various health tracking devices has become paramount. This article provides an in-depth look at how to create a system that seamlessly integrates data from popular platforms such as Garmin, Polar, Apple Watch, Dexcom, Withings, Fitbit, and Spotify.