Creating a Full CI/CD Pipeline on AWS with Jenkins, Slack, and GitHub: Part 2—Set up Slack and create a Bot

Rapidcode Technologies
5 min readNov 23, 2023

--

In this phase, we’ll prepare Slack for integration into our upcoming pipeline. We’ll walk you through setting up an account, establishing a workspace, creating an app (specifically, a bot), and experimenting a bit to become familiar with the Slack API.

Part 1 (here) → We’ll kick things off by setting up our project. We’ll download a Web App to test our infrastructure and pipeline. We’ll also create and test some Dockerfiles for the project and upload it all to GitHub.

Part 2 (Right now) → We’ll get Slack in on the action. We’ll create a Bot for Jenkins to keep us posted on how the pipeline’s doing.

Part 3 (here) → It’s time to build the AWS Infrastructure with Terraform. We’ll whip up some EC2 instances, set up SSH keys, create the network infrastructure, and lay the foundation for IAM roles.

Part 4 (here) → We’re not done with AWS yet. In this step, we’ll make S3 buckets, and ECR repositories, and finish defining the IAM roles with the right policies.

Part 5 (here) → We’ll fine-tune our Jenkins and Web App instances by making sure the user data is just right.

Part 6 (here) → We’ll put the icing on the cake by implementing the pipeline in a Jenkinsfile. We’ll run the pipeline and see everything come together smoothly. Then, we’ll wrap things up with some final thoughts.

Let’s get started!

Account, Workspace, and Channel Creation

If you do not have already a Slack account, just navigate to:

https://slack.com/

And we can sign up with a Google account. After some possible verifications, we should be redirected to the following page:

Slack get-started page after signing up

Let’s click the button Create a Workspace , and name it nodejs-web-app :

nodejs-web-app

After clicking Next we will be prompted with a question asking us what is your name is (Adding your name and profile photo helps your teammates to recognize and connect with you more easily). Let’s put it there by your choice.

After clicking the next skip the step following right now:

After clicking skip this stepwe will be prompted with a question asking us what we are currently working on. Let’s put there CI-CD Pipeline :

As we can see after hitting Next , on the left, we have:

And this will be the channel through which we will communicate from the Jenkins server.

Cool, we created a workspace and a new channel. At this point, we need to create an App in order to use the Slack API.

Bot/App Creation

Navigate to:

https://api.slack.com/

Click on the Create an App :

After the redirection, a pop-up should appear, and just select From Scratch :

In the next step, let’s assign a name and pick the nodejs-web-app workspace for our App:

and click Create App .

Wonderful, we have created the Jenkins Bot. At this point, we need to install it in our workspace. Click on the OAuth & Permissions on the left menu:

Then scroll down under Scopes and click the Add an OAuth Scope :

Select two permissions:

channels:read
chat:write

These permissions will allow our Bot to read the available channels and write on chats.

At this point, scroll up again and click the Install to Workspace button:

and click Allow .

Now we have a Bot User OAuth Token :

This Token will allow us to make API requests and will be used by the API to correctly authenticate us.

If we get back to the app.slack.com and we refresh, we should see our bot there:

The last thing that we need to do here is invite the bot in the channel, otherwise, it will not be able to send messages. In order to do that, in the ci-cd-pipeline chat, just type:

/invite @Jenkins Bot 

And press enter and we should see that the Bot correctly joined the channel:

Make Slack API Requests

At this point, we should be set and ready to make some API calls to test our workspace and Bot. Grab the Bot User OAuth Token and then let’s make some API requests. We’ll do requests via the cURL commands to be able to use them in the pipeline.

Type the following command on the terminal and change the token of your slack boat:

curl https://slack.com/api/chat.postMessage -X POST -d “channel=#ci-cd-pipeline” -d “text=Hello World “ -d “token=xoxb-6124311631473–6111686407890-yMIfCEB5AHw3V46Ejvbms8Fw” -d “icon_emoji=:simple_smile:”

After hitting enter you will receive “ok”:true in response.

Check the Slack channel you should see the Hellow World message:

Save that command somewhere, in which we have both the Bearer Token and the channel id .

And that wraps up this second segment! In the upcoming part, we’ll dive into the details of implementing the AWS infrastructure using Terraform. Catch you in the next one!

Cheers!

--

--

Rapidcode Technologies

Architecting the future of innovation and design with cloud-native skills. 🌟 Let's transform your business! 🌟 #Innovation #Perseverance