Configuration Slack notification in jenkins

Jenkins is an open-source CI server that allows you to easily set up pipelines for the automation of testing, building, and deploying.

Install Jenkins app for Slack

1.Go to the Slack app on your desktop

2.On the bottom of the left side navigation bar, you will see Apps

3.Click on Add apps.



4.Search for “Jenkins CI” and click Add.



4.It will be sent to the Jenkins app page in your browser. Click Add.

Select the Slack channel you want to post to and click Add Jenkins CI integration. we can also create a new channel by selecting the bottom right link where it says to create a new channel



On the next page, scroll down to Integration Settings to find all the settings and info you need to customize our Slack notification in Jenkins. We will need the auto-generated Token later for configuration in Jenkins.


Install Slack Notifications plug-in for Jenkins

*Go to Jenkins > Manage Jenkins > Manage Plugins



Under the Available tab, filter and search for “slack notification.”


Select Slack Notification, then Install without restart on the bottom left.

Once the “Success” message appears, go back to the main page by clicking Go back to the top page.


Connecting Jenkins to our Slack

Before we set up a new pipeline job, we need to configure Jenkin’s settings to connect to our Slack. We will do this in Manage Jenkins > Configure System

Scroll all the way down on the Configure System page until you see the settings for Slack.

*Workspace: Team’s workspace name. If we sign in to slack at https://example.slack.com/, our workspace is ‘example’.

*Credential:

- Click Add → Jenkins and a pop-up will appear.

- Under the Kind dropdown, select secret text.



Copy and paste your Slack Token into Secret, and click Add.

If you forgot to save/copy your token, go to:

Slack app directory (https://.slack.com/apps/manage) > Jenkins CI > Configurations > Edit Configuration > Integration Settings

Make sure to select the newly added token credential from the drop-down.

Enter the channel name (i.e. #channel) or user ID (i.e. USD4536UK8) you want the notification to be sent to.


Once everything is filled out, click Save

Create a new job to test the Slack notification

*Go to New job

*select Pipeline, name a job then click OK 



Scroll all the way down to Pipeline. We will write the JenkinsFile script into the Script text box as below.

pipeline {

    agent any


    stages {

        stage('Slack it'){

            steps {

                slackSend channel: '#marketing', 

                          message: 'Hello, world'

            }

        }

    }

}


*Click Save.

Once we saved it will be redirected in to our Jenkins web Ui

*Click Build Now on the left side corner 



Click on Console Output to view what happens as it would in your terminal or command prompt.



If all goes well, a Slack message has been sent to our channel.


Recent Comments

No comments

Leave a Comment