Telegram Bot integration with Jenkins
Telegram is one of the popular messaging app and Jenkins is most popular CI-CD tools , Here we will be creating a Jenkins Bot that can be used to trigger your builds remotely from your telegram Bot .
Requirements :
1- Telegram App [ Mobile/Desktop]
2- Jenkins Server up and running
3- Python IDE
What this Bot will do ?
This Bot will display the list of current jobs present on your Jenkins Server , and will allow you to trigger it remotely from your app [Mobile/Desktop] and even allow you to cancel current job if triggered by Mistake — All this is done based on selecting the Prompts of the Bot.
Below are the steps –
Step1– Create a bot in telegram using BotFather and get the token.
Open Telegram and search for @botfather and click on it
Type /newbot and Follow the steps in the screenshot
Your Bot will get created , Capture the token generated in the bot as it will be used to communicate to the bot
Step 2 — Open Python IDE[ Here we have used Pycharm]
- Import packages— telegram ,telegrm.ext , jenkins, logging, configparser
- Create a config File to store token and also limiting the users to access the bot
- Use Jenkins package to retrieve the Jobs present on current Jenkins server and display on the screen
- Configure Parameters if the Job is Parametriezed
- Implement a basic logic for fallback — display a message if user types instead of selecting a Prompt.
You can get the code from here –
Note — The example shared is for a basic Telegram Bot to trigger jenkins build remotely — However this can be further extended to include additional jenkins features like getting status of current build, etc.
Ten articles before and after
🤖 How to create a Telegram Crypto Bot in Javascript – Telegram Group
How to Make a Telegram Pokédex Bot Using Python – Telegram Group
How to restart a python program from inside – Telegram Group
How to use the MOONCLONE Bot. To being using MOONCLONE BOT open up… – Telegram Group
Je vais booster vos abonnés/ventes grâce à une grosse promotion sur Telegram – Telegram Group
PyCryptoBot with Telegram. I received a feature request in the… – Telegram Group
RSA with telegram bot using Python – Telegram Group
Creating a Telegram bot with python – Telegram Group
Get Telegram Group Members with Python and Telethon – Telegram Group