Slack integration in Jenkins to remotely invoke Jenkins jobs from a Slack channel. For a full version of this document, including images, please refer to the pdf file available at this same repository.
Author: Marco Da Pieve
- Project Scope
- Procedure
- Conclusion
To create a Slack channel, receive Jenkins build notifications, and use it to invoke Jenkins jobs remotely by configuring slash commands in Slack.
- Set up an AWS EC2 instance running Ubuntu 24.04.
- Ensure that the instance is accessible via SSH and a public IP for communication between Jenkins and Slack.
Follow this guide to install Jenkins on AWS, ensuring the instance's security group allows inbound traffic.
- Install OpenJDK 17 using:
sudo apt -y install fontconfig openjdk-17-jre
java -version
Verify the installation with java -version
.
- Add the Jenkins repository:
wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt-get update
- Install Jenkins:
sudo apt-get -y install jenkins
- Verify Jenkins is running:
systemctl status jenkins
- Access Jenkins via
http://<public-ip>:8080
. - Retrieve the admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Install recommended plugins, create an admin user, and complete the setup.
- Log in to GitHub.
- Create a repository and add necessary files, including a
README.md
.
- Create a new Slack channel and name it appropriately.
- Use this channel for Jenkins notifications.
- Add the "Jenkins CI" app in Slack via the "Integrations" tab.
- Obtain the integration token and configure Jenkins for Slack notifications.
- Install the "Slack Notification" plugin in Jenkins.
- Configure Slack workspace and credentials in Jenkins settings.
- Test the Slack connection to confirm successful integration.
- Create a freestyle Jenkins job.
- Configure source code management with a GitHub repository.
- Add build steps and enable Slack notifications under "Post-build Actions."
- Trigger a build and check Slack for notifications.
- Test error scenarios by introducing intentional build failures.
- Set up a Pipedream webhook to handle Slack slash commands.
- Configure it to send HTTP POST requests to Jenkins.
- Configure Slack's legacy integration with slash commands.
- Use the integration token to trigger builds in Jenkins.
The integration of Slack with Jenkins using modern and legacy approaches streamlines build notifications and remote job triggers, enhancing team collaboration and productivity.