Using Telegram to monitor your Gitlab pipelines
Tags: gitlab, telegram, ci, devops
Published: 2019-12-10 14:58:39

## How to be aware of what your pipelines are doing without wallboards and separate browser windows

As a Freelancer I often work with customers who have their own servers, but leave most of the technical work to me. I don't enjoy working directly on servers that much, so the first thing I do when a new server needs to be configured, is installing a Gitlab Runner.

## Setting up pipelines

This service is then connected to Gitlab.com, the customers Gitlab instance or my own self-hosted Gitlab. Then I set up a deployment pipeline which matches to the project. So for PHP projects I usually choose [TYPO3 Surf](https://github.com/TYPO3/Surf) to execute actual deployments. [Deployer](https://deployer.org/) is also an option, but I just got lately into using it more and primarily use it of other tasks. For other kinds of projects you would of course choose the tool which matches best. For Ruby projects it could be [Capistrano](https://capistranorb.com/), or you just have a bunch of Shell/Docker scripts.

After setting up a pipeline in Gitlab to automatically run builds, tests, deployments and other tasks, my project workflow is usually only based on pushing data to Gitlab. So I push via Git and then start working on the next task. Gitlab then handles the rest by communicating to the Gitlab Runner that is running on the server. The runner will then build the project, run some tests and finally deploy new releases. And the whole thing might work out or fail...

![List of pipelines in Gitlab](https://thepracticaldev.s3.amazonaws.com/i/klsaezn5cm3v60zatpew.png)

## How to know what the pipeline is doing

So for quite a while I was looking for a way to monitor what happens after builds succeed or fail. I'm usually interested in any kind of failure in any stage of the pipeline, to start fixing the issue. Or success messages, when a deployment went through, after which I like to run some manual tests and inform the customer of the finished update.

Of course you can simply go to the Gitlab instance and watch the pipeline view and see what's going on. You can also setup awesome wallboards on separate screens, or have a Raspberry PI to create some interesting output. But all these things were to time consuming for me, or didn't work out if I'm working from somewhere else.

Therefore I was searching for a way to passively monitor the pipelines with the least amount of distraction. After quite some time of searching I found out that a Gitlab integration for the [Telegram](https://telegram.org/) messenger exists. It's called [Integram](https://integram.org/), is Open Source and works really well. It also supports the todo list [Trello](https://trello.com/) and the code management tool [Bitbucket](https://bitbucket.org/).

## Using Integram

Integram basically offers a chatbot for Telegram. This bot allows you to interact via messages with your Gitlab instance. You can add hooks to the projects that should be connected and the bot will then inform you of the progress of these projects pipelines.

![Feedback from Gitlab via Telegram](https://thepracticaldev.s3.amazonaws.com/i/75jirlbdifwbincdcos3.jpg)

As Telegram offers apps for iOS, Android, Mac OS X, Windows etc.. you can receive those messages everywhere. For example, I do a git push with a new release tag, then go make a coffee in the kitchen and a few minutes later my Apple Watch notifies me that the triggered deployment when through.

If you don't trust the Integram bot, you can also host the service [yourself](https://github.com/requilence/integram#how-to-host-integram-on-your-own-server-using-your-private-bots). This way you can keep the whole CI infrastructure to yourself.

Of course you can also attach the bot to a group chat, so a whole team can be informed.

Find the information on how to set it up in their [Github repository](https://github.com/requilence/integram#how-to-use-integram-in-telegram-using-public-bots) based on the integration you need. You basically setup the bot in your Telegram chat and add service hooks to your individual project repositories in Gitlab. The bot will guide you through the whole process. I didn't want to copy the whole procedure here as their readme is always up-to-date and has all the details.

One note: when you configure the service hook make sure you select all the events you need. I usually select *Push Events*, *Tag push events*, *Job events* and *Pipeline events*.

## Summary

In my opinion, the Integram bot is a non-intrusive way of being informed of builds & deployments. As Telegram allows you to treat the chatbot like any other user, you can even mute it for a while if necessary. 
If you or your company uses Slack, there are of course integrations which might suit you better.