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
1373 Minutes to Days | Telegram
977 Minutes to Days | Telegram
857 Months to Years | – Telegram 下载
28 Milliseconds to Minutes | – Telegram 下载
270 Minutes to Days | Telegram