Telegram Bot integration with Jenkins | by Alok Srivastav | Medium – Telegram 安装

Haley

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

Track SSH Logins via Telegram. If you are a Dev-Ops Engineer, You and… | by Amith Chandrappa | Medium – Telegram 安装

977 Minutes to Days | Telegram

857 Months to Years | – Telegram 下载

20 Minutes to Days | Telegram

93 Minutes to Days | Telegram

28 Milliseconds to Minutes | – Telegram 下载

270 Minutes to Days | Telegram

833 Minutes to Days | Telegram

1333 Minutes to Days | Telegram

About Me

Pretium lorem primis senectus habitasse lectus donec ultricies tortor adipiscing fusce morbi volutpat pellentesque consectetur risus curae malesuada dignissim lacus convallis massa mauris.