DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Building Data Pipelines With Jira API
  • Building a Scalable ML Pipeline and API in AWS
  • CI/CD Pipelines for Kubernetes Using GitLab CI
  • Securing Secrets: A Guide To Implementing Secrets Management in DevSecOps Pipelines

Trending

  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Grafana Loki Fundamentals and Architecture
  • My LLM Journey as a Software Engineer Exploring a New Domain
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Set Up GitLab Notifications in Telegram: A Comprehensive Tutorial

How to Set Up GitLab Notifications in Telegram: A Comprehensive Tutorial

This tutorial provides a step-by-step guide on setting up GitLab notifications in Telegram. Ensuring you stay informed about your GitLab activities conveniently.

By 
Vasilii Kulazhenkov user avatar
Vasilii Kulazhenkov
·
Jul. 17, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will look at how to configure GitLab notifications in Telegram to receive information about successful deployment and failures during the development phase. This is especially useful for developers, DevOps engineers, and PMs, as it allows you to stay up to date on GitLab activity and respond immediately to crashes.

Let’s get started with what we want to do step-by-step:

  1. Create a Telegram bot using BotFather and obtain the API token for the bot.
  2. Add the bot to the Telegram group and find out Telegram group Id.
  3. Add variables for the Telegram bot in GitLab.
  4. Let's set up sending messages via GitLab Pipeline.

1. Create a Telegram Bot Using BotFather and Obtain the API Token for the Bot

Open the Telegram app and find @BotFather. Then follow the instructions to create a new bot and get an API token. Find instructions for this here. Create a bot, for example, with the name 'CicdBot.' After creating the bot, a token will arrive in the chat to work with the API, something like 123281243:AAHdqTcvCH1vGWJxfSeofSAjhs6PALDsaw.

In the bot settings, disable the privacy settings:

Privacy mode is disabled for Cicdbot.

2. Add the Bot to the Telegram Group and Find Out the Telegram Group ID

Go to the Telegram group for notification from GitLab and add the created bot as a participant (find the bot by name in BotFather chat). 

After that, you need to get the Telegram group ID. To do this, go to the URL.

Where  <YourBOTToken> — is the API Token received in BotFather 123281243:AAHdqTcvCH1vGWJxfSeofSAjhs6PALDsaw.

 And find the chat-id in the response: ... "chat": {"id": <YourGroupID>, ...

3. Add Variables for the Telegram Bot in GitLab

In the settings of the required Gitlab repository (Settings > CI/CD > Secret variables), add secret variables:

  • TELEGRAM_BOT_TOKEN — API Token received in @BotFather
  • TELEGRAM_CHAT_ID — ID of the chat to which the message will be sent. (It will be sent only if any message has already been sent to the bot from this chat. For a group, it is enough to add a bot to the group).

4. Let’s Set Up Sending Messages via GitLab Pipeline

To conveniently send notifications, we will create a script in notify.sh, in which we will access the Telegram API and send a message to the right user through the created bot:

#!/bin/bash

TIME="10"
URL="https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage"
TEXT="Deploy status: $1%0A%0AProject:+$CI_PROJECT_NAME%0AURL:+$CI_PROJECT_URL/pipelines/$CI_PIPELINE_ID/%0ABranch:+$CI_COMMIT_REF_SLUG%0AUser:+$GITLAB_USER_NAME"

curl -s --max-time $TIME -d "chat_id=$TELEGRAM_CHAT_ID&disable_web_page_preview=1&text=$TEXT" $URL > /dev/null


The deployment status should be passed as the first parameter for this script. Also transmitted are the Project name, URL pipeline, Branch, and User name. In .gitlab-ci.yml, we describe calling this script at the right time with the right parameters:

...
deploy:
    stage: deploy
    script:
        - sh notify.sh "success message ✅"

notify_error:
    stage: notify
    script:
        - sh notify.sh "fail message ❌"
    when: on_failure


I used Emojis to indicate the status of the deployment. If the deployment is successful ✅, the script with the desired parameter is simply called. In case of an unsuccessful deployment ❌, “management moves” to the next stage, in which notification of an unsuccessful deployment occurs.

This is how it looks in a telegram:

successful

unsuccessful

Conclusion

By configuring GitLab notifications in Telegram for successful deployment and failures at the development stage, company employees can be aware of GitLab activity in real time. This makes it easier to track pipeline statuses and respond immediately to problems that have arisen.

API GitLab Pipeline (software) Software deployment

Opinions expressed by DZone contributors are their own.

Related

  • Building Data Pipelines With Jira API
  • Building a Scalable ML Pipeline and API in AWS
  • CI/CD Pipelines for Kubernetes Using GitLab CI
  • Securing Secrets: A Guide To Implementing Secrets Management in DevSecOps Pipelines

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!