From 53e805632ef0b8d659d6702f0066e83e99042aea Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 17 Aug 2012 22:18:48 +0100 Subject: EXAMPLE: Jenkins-notify global post-receive hook example --- .../global-hooks/jenkins-notify.post-receive.lua | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 example/global-hooks/jenkins-notify.post-receive.lua (limited to 'example') diff --git a/example/global-hooks/jenkins-notify.post-receive.lua b/example/global-hooks/jenkins-notify.post-receive.lua new file mode 100644 index 0000000..e2f2d31 --- /dev/null +++ b/example/global-hooks/jenkins-notify.post-receive.lua @@ -0,0 +1,40 @@ +-- jenkins-notify.post-receive.lua +-- +-- Example post-receive global hook which notifies a Jenkins instance on +-- any and all refs updates (except refs/gitano/*) which happen. +-- +-- It notifies Jenkins *before* passing the updates on to the project hook. +-- +-- Copyright 2012 Daniel Silverstone +-- +-- This is an example which is part of Gitano. +-- + +local project_hook, repo, updates = ... + +local jenkinshost = "ci.gitano.org.uk" +local basepath = "/jenkins/git/notifyCommit?url=" +local urlbase = "git://git.gitano.org.uk/" + +local notify_jenkins = false + +for ref in pairs(updates) do + if not ref:match("^refs/gitano/") then + notify_jenkins = true + end +end + +if notify_jenkins then + log.state("Notifying Jenkins...") + local code, msg, headers, content = + http_get(jenkinshost, basepath .. urlbase .. repo.name .. ".git") + if code ~= "200" then + log.state("Notification failed somehow") + end + for line in content:gmatch("([^\r\n]*)\r?\n") do + log.state("jenkins: " .. line) + end +end + +-- Finally, chain to the project hook +return project_hook(repo, updates) -- cgit v1.2.1