3 # Copyright (c) 2008 Stephen Haberman
5 # This hook creates new jobs for each branch in the Hudson continuous
6 # integration tool. Besides creating the job if needed, the user who pushed is
7 # added to the job's email list if they were not already there.
11 # hooks.post-receive-hudson.url
12 # The url to hudson, e.g. http://internalbox/hudson
13 # hooks.post-receive-hudson.ignored
14 # Whitespace separated list of branches to not make jobs for.
16 # Environment variable that should be set by your repository-specific
17 # post-receive hook. E.g. export USER_EMAIL=${USER}@example.com
20 . $(dirname $0)/functions
22 while read oldrev newrev refname ; do
28 short_refname=${refname##refs/heads/}
31 echo >&2 "*** Unknown type of update to $refname"
36 ignored=" $(git config hooks.post-receive-hudson.ignored) "
37 hudson_url=$(git config hooks.post-receive-hudson.url)
38 if [[ $ignored =~ " $short_refname " ]] ; then
42 branch_config=$(wget -O - $hudson_url/job/${short_refname}/config.xml 2>/dev/null)
43 if [ $? -ne 0 ] ; then
45 stable_config=$(wget -O - $hudson_url/job/stable/config.xml 2>/dev/null)
46 if [ $? -ne 0 ] ; then
47 display_error_message "Could not get existing Hudson config for ${short_refname}"
51 # Replace stable with our branch
52 branch_config="${stable_config/<branch>stable</<branch>$short_refname<}"
54 # Add email to recipients list
55 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
56 branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
60 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$hudson_url/createItem?name=${short_refname}" >/dev/null 2>/dev/null
61 if [ $? -ne 0 ] ; then
62 display_error_message "Could not create new Hudson job for ${short_refname}"
66 # Add email to recipients list
67 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
68 branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
71 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$hudson_url/job/${short_refname}/config.xml" >/dev/null 2>/dev/null
72 if [ $? -ne 0 ] ; then
73 display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"