Requirements:
2 Servers (Minimum 4GB of RAM)
1 Docker Registry (Private or Public)
1 Telegram Bot
Know how to use "Linux", "Docker", and "Jenkins"
Installation Guide
Docker: installation
Jenkins: installation
Telegram: How to create tele bot
Prepare your application
I created a simple React application, which I made with the help of Lovable AI
GitHub Repo: https://github.com/hardikkangane/sample-reactjs-trading-dashboard
Setup Jenkins and Docker
I created one Docker repository on Docker Hub from where I pull and push my images.
I created Jenkins pipeline (In Jenkins, you need to configure your remote server's SSH key or password to deploy your application)
GitHub Repo: https://github.com/hardikkangane/react-cicd-with-alert
Workflow of the pipeline
Testing pipeline
Alert
I have added this line of code at the end of my pipeline to get Telegram alerts. (You will get this full pipeline code from my above GitHub repo)
post {
failure {
script {
def currentTime = new Date().format("dd-MM-yyyy HH:mm", TimeZone.getTimeZone("Asia/Kolkata"))
def message = "🚨 CICD FAILED 🚨:\nName: ${env.JOB_NAME}\nDateTime: ${currentTime}"
sh """
curl -s -X POST https://api.telegram.org/bot<BOT_TOKEN>/sendMessage \\
-d chat_id=CHAT_ID \\
-d text="${message}"
"""
}
}
}
Now, if my pipeline fails, I will get an alert on my Telegram.
Top comments (0)