The Artima Developer Community
Sponsored Link

Web Buzz Forum
Telegram notifications for Jenkins builds

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stuart Langridge

Posts: 2006
Nickname: aquarius
Registered: Sep, 2003

Stuart Langridge is a web, JavaScript, and Python hacker, and sometimes all three at once.
Telegram notifications for Jenkins builds Posted: Oct 27, 2017 6:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Stuart Langridge.
Original Post: Telegram notifications for Jenkins builds
Feed Title: as days pass by
Feed URL: http://feeds.feedburner.com/kryogenix
Feed Description: scratched tallies on the prison wall
Latest Web Buzz Posts
Latest Web Buzz Posts by Stuart Langridge
Latest Posts From as days pass by

Advertisement

It’s nice to get updates from your CI system when things build. It’s even nicer to do it without having to run any servers to do it. Here’s how I send build notifications to a Telegram bot from Jenkins.

Basically, Jenkins knows how to hit a webhook for every stage of the build, and Integram run a Telegram bot which knows how to respond to webhooks. All you need is a little bit of glue code to convert stuff Jenkins sends into stuff Integram receives, and you can put that glue code on any one of fifteen serverless systems. I used webtask.io.

The Webtask.io editor

Deploy the following code there, being sure to update the Integram URL in it to be yours:

var express = require('express')
var bodyParser = require('body-parser')
var request = require('request')
var Webtask;
try {
    Webtask = require('webtask-tools');
} catch(e) {}
var app = express()
app.use(bodyParser.json())
app.post('*', function (req, res) {
    if (req.body && req.body.name && req.body.build && req.body.build.url) {
        var status = req.body.build.status;
        if (req.body.build.phase == "STARTED") { status = "STARTED"; }
        if (req.body.build.phase == "FINALIZED") {
            // don't care about FINALIZED because we get COMPLETED and that's enough
            res.send("ok");
            return;
        }
        console.log("Received correct-looking JSON to webhook");
        var output = {"text": "Jenkins\nBuild of _" + req.body.name +
            "_ status *" + status + "* " +
            "at http://YOUR-JENKINS-URL/" + req.body.build.url};
        request({
            uri: "https://integram.org/YOUR-INTEGRAM-URL",
            method: "POST",
            json: output
        }, function(err) {
            if (err) {
                console.log("Messaging Telegram bot failed", err);
                res.send("failed");
            } else {
                console.log("Messaging Telegram bot succeeded");
                res.send("ok");
            }
        })
    } else {
        console.log("Input to webhook was invalid", req.body);
        res.send("Input was invalid: " + req.body.toString());
    }
})
if (Webtask) {
    module.exports = Webtask.fromExpress(app);
} else {
    app.listen(4569);
    console.log("Listening on port 4569");
}

Then, put the webtask URL into Jenkins as a webhook:

Add a notifications endpoint in the configure section of your build job

And invite the Integram bot to your Telegram channel (instructions at integram.org).

And you’re done. Every time Jenkins does anything, it sends a web request to your webtask, the webtask sends a message to the Integram bot, the Integram bot repeats it to you, and you get a notification. No extra servers required. I love the internet.

The Telegram bot speaks the message it's given, and so Telegram notifies you

Read: Telegram notifications for Jenkins builds

Topic: I wrote a Web Component Previous Topic   Next Topic Topic: Charles Paget Wade and the Underthing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use