public
Description: scripts and hooks for use with a centralized git repo
Homepage:
Clone URL: git://github.com/stephenh/git-central.git
git-central / server / post-receive-hudson
100644 82 lines (71 sloc) 2.471 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
#
# Copyright (c) 2008 Stephen Haberman
#
# This hook creates new jobs for each branch in the Hudson continuous
# integration tool. Besides creating the job if needed, the user who pushed is
# added to the job's email list if they were not already there.
#
# Config
# ------
# hooks.post-receive-hudson.url
# The url to hudson, e.g. http://internalbox/hudson
# hooks.post-receive-hudson.ignored
# Whitespace separated list of branches to not make jobs for.
# USER_EMAIL
# Environment variable that should be set by your repository-specific
# post-receive hook. E.g. export USER_EMAIL=${USER}@example.com
#
 
. $(dirname $0)/functions
 
while read oldrev newrev refname ; do
case "$refname" in
refs/tags/*)
exit 0
;;
refs/heads/*)
short_refname=${refname##refs/heads/}
;;
*)
echo >&2 "*** Unknown type of update to $refname"
exit 1
;;
esac
 
ignored=" $(git config hooks.post-receive-hudson.ignored) "
hudson_url=$(git config hooks.post-receive-hudson.url)
if [[ $ignored =~ " $short_refname " ]] ; then
exit 0
fi
 
branch_config=$(wget -O - $hudson_url/job/${short_refname}/config.xml 2>/dev/null)
if [ $? -ne 0 ] ; then
# Create the job
stable_config=$(wget -O - $hudson_url/job/stable/config.xml 2>/dev/null)
if [ $? -ne 0 ] ; then
display_error_message "Could not get existing Hudson config for ${short_refname}"
exit 0
fi
 
# Replace stable with our branch
branch_config="${stable_config/<branch>stable</<branch>$short_refname<}"
 
# Add email to recipients list
if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
fi
 
# Make the new job
wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$hudson_url/createItem?name=${short_refname}" >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
display_error_message "Could not create new Hudson job for ${short_refname}"
exit 0
fi
else
# Add email to recipients list
if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
 
# Update the config
wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$hudson_url/job/${short_refname}/config.xml" >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"
exit 0
fi
fi
fi
done
 
exit 0