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
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'
module.exports = (robot) ->
robot.router.post "/your/path/for/jenkins/callbacks", (req, res) ->
jenkinsCallback(req, res, robot)
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.