Fortytools-Blog mit News zu Gebäudereinigung, Betreuungsdiensten, Alltagshilfe und andere Dienstleistern

Hier finden Sie aktuelle Informationen, Tipps und Tricks rund um Büro, Verwaltung, Einsatzplanung und mehr!

How to let Hubot send status messages to your Jabber conference after a Jenkins build was finished

Wouldn’t it be nice if Hubot would tell you if a jenkins build was successful or not? Here is how we did it by extending the jenkins script at https://github.com/github/hubot-scripts/blob/master/src/scripts/jenkins.coffee

Add a callback-method so jenkins can trigger an action

jenkinsCallback = (req, res, robot) ->
   room = "room@your.jabber.server"
   job = req.body.job
   user = robot.userForId 'broadcast'
   user.room = room
   user.type = 'groupchat'

   url = process.env.HUBOT_JENKINS_URL
   getreq = robot.http("#{url}/job/#{job}/api/json")

   if process.env.HUBOT_JENKINS_AUTH
     auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
     getreq.headers Authorization: "Basic #{auth}"

   getreq.get() (err, res, body) ->
       if err
         robot.send user, "Jenkins callback failed: #{err}"
       else
         try
           message = "Jenkins: #{job} "
           content = JSON.parse(body)
           message+= if content.color == "red" then "FAILED" else "PASSED"
           robot.send user, message
         catch error
           robot.send user, error

   res.writeHead 200, {'Content-Type': 'text/plain'}
   res.end 'Ok'

Add a route to receive callbacks

module.exports = (robot) ->
 robot.router.post "/your/path/for/jenkins/callbacks", (req, res) ->
   jenkinsCallback(req, res, robot)

Make Jenkins send callbacks

We use the PostBuildScript-Plugin to trigger the callbacks:

curl -d job=$JOB_NAME http://example.com/your/path/for/jenkins/callbacks

This assumes that Hubot is listening on port 80 of example.com, so adjust it to your needs.

We are using jabber to communicate with our team members, and as this was just a quick hack, we only implemented sending xmpp messages. Feel free to write a comment how to use a general messaging approach, then this might be worth a github pull request.

Über den Autor

Bewertet mit durchschnittlich
4.5
Sternen von
52
Lesern.

Fortytools für Ihre Branche

No items found.

Testen Sie 30 Tage kostenlos und unverbindlich die smarte Online-Software für Betreuungsdienste und Gebäudereiniger!

Sie können Fortytools 30 Tage kostenlos und unverbindlich testen. Dabei stehen Ihnen alle Funktionen uneingeschränkt zur Verfügung.
Heute kostenlos testen!
Nutzerbewertung: 4,8 von 5 Sternen

Fortytools läuft komplett im Internet-Browser: Keine Software-Installation, keine Probleme mit Updates. Einfach Einloggen und fertig. Von jedem internetfähigen Gerät.

Kostenlos und unverbindlich testen
Professionelle Rechnungen schreiben
Kunden-Daten verwalten
Mitarbeiter-Daten verwalten
Aufgaben- und Terminplanung
Professionelle Angebote schreiben
Einsätze planen und Zeiten erfassen