This article is a quick HOW-TO after struggling with Build about how to send notifications when a build has failed or is successful. Since I did not want to use Slack and the heavy client, I give a try in this post with and discover the magical chatbot world.

Google Cloud Build

Cloud Build is a service that executes your builds on Google Cloud Platform infrastructure. Cloud Build can import source code from Google Cloud Storage, Cloud Source Repositories, GitHub, or Bitbucket, execute a build to your specifications, and produce artifacts.

Google Cloud Build is rather a cheap alternative to Jenkins, Travis- and Circle CI if you have private projects. While the other solutions requires a quite expensive subscription, you pay GCB according the used build time. If you do not commit frequently or the build is a short task, it is a really fair solution. And extra bonus, the first 120 build minutes are free.

Google Cloud Build
Google Cloud Build

As you see, the Google Cloud Build interface is not as attractive as the other competitors. ThatÙs why I wanted at the bare minimum to receive some notifications.

There is no built-in process therefore I had to build my own. GCB recommends Slack however my choice is in favor of mobile push messages with Telegram.

Next to read  How to tune your JVM memory and track your GC Usage ?


Telegram is a cloud-based instant messaging and voice over IP service. Users can send messages and exchange photos, videos, stickers, audio and files of any type. Default Messages and media in Telegram are encrypted when stored on its servers.

Telegram running on an iPhone X (wikipedia)
Telegram running on an iPhone X (wikipedia)

Telegram Bots

Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You your bots using HTTPS requests to our bot API.

What can do a BOT ( extracted from Telegram website) :


  • Get customized notifications and news.

  • Integrate with other services.

  • Accept payments from Telegram users.

  • Create custom tools.

  • Build single- and multiplayer games.

  • Build social services.

How to send notifications with GCB

Here is a diagram to explain how to implement such notification bot.

Google Cloud Telegram implementation diagram
Google Cloud Telegram implementation diagram

The diagram does not reveal the implementation order. Here is the order that I followed.

Create a Job with GCB

The first step is to identify your GIT repository that you want to use as demo project.

Then go into the Google Cloud Build section :

Google Cloud Build access
Google Cloud Build access

You have two available actions, Connect to repository and Create a Trigger once your GitHub repository has been connected.

GCB Connect Repository
GCB Connect Repository

Check the presence of the subject

You should have a topic created by GCB indicating that the build messages are sent into a dedicated queue.

Create the Telegram BOT

Now it is time for the fun part of the tutorial.

You will have to install first the Telegram application on your mobile phone and to follow this tutorial to create your BOT. Just talk to BotFather


After the creation of the BOT, store in your password manager, the Telegram TOKEN.

Next to read  Stop/Remove All Docker containers

Create the Cloud Function

In this step, we will finally create our Telegram notification chatbot. The program will be coded in Node.js and deployed as a Cloud Function in Google Cloud.

Why a Cloud Function ? Because we do not want to allocate a full-time virtual machine to process only during a few seconds the Google Build messages.

The code is available there and the explanation is pretty straightforward :

Deploying the Cloud Function

To deploy the Cloud function, you need to use gcloud.

The cloud function is only publishing in a  single GROUP_ID.

To obtain a Telegram GROUP Id, you need to add the Telegram bot by inviting into a group. Then you need to query a special endpoint to get the list of all subscriptions for this bot.

Here is the Q/A about it :

The instruction to push the cloud function. If everything is OK, the cloud function will be deployed.

gcloud functions deploy subscribeTelegram --trigger-topic cloud-builds --runtime nodejs10 --set-env-vars "TELEGRAM_TOKEN=token1,GROUP_ID=groupID"


What you should obtain, is an output similar to that :

Deploying function (may take a while - up to 2 minutes)...done. 
availableMemoryMb: 256
entryPoint: subscribeTelegram
GROUP_ID: 'xxxxxxxxxx'
TELEGRAM_TOKEN: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
eventType: google.pubsub.topic.publish
failurePolicy: {}
resource: projects/xxxxxxxx/topics/cloud-builds
deployment-: cli-gcloud
name: projects/xxxxxxxxx/locations/us-central1/functions/subscribeTelegram
runtime: nodejs10
status: ACTIVE
timeout: 60s
updateTime: '2019-12-10T21:44:59Z'
versionId: '14'

The Telegram notification program

Conclusion and further improvements

This bot is really simple and easy to do but it lacks of the main feature, to answer to commands. Here is a list of interesting commands I would like to add :

  • get the list of nth last commits
  • trigger a build
  • display the build logs (or the last nth lines)
Next to read  Quest for a CMS in 2018 : KeystoneJS Feedback

For this, you need to implement a bot server (in node.js for example). There are plenty of examples on internet and it will be probably the subject of another article.





By Sylvain Leroy

Senior Software Quality Manager and Solution Architect in Switzerland, I have previously created my own company, Tocea, in Software Quality Assurance. Now I am offering my knowledges and services in a small IT Consulting company : Byoskill and a website Currently living in Lausanne (CH)

Do NOT follow this link or you will be banned from the site!