161568ba551e097fd618369d79a706d26d43b16b
[git-central.git] / server / post-receive-hudson
1 #!/bin/sh
2
3 . $(dirname $0)/functions
4
5 while read oldrev newrev refname ; do
6         case "$refname" in
7                 refs/tags/*)
8                         exit 0
9                         ;;
10                 refs/heads/*)
11                         short_refname=${refname##refs/heads/}
12                         ;;
13                 *)
14                         echo >&2 "*** Unknown type of update to $refname"
15                         exit 1
16                         ;;
17         esac
18
19         branch_config=$(wget -O - http://cbas1:8080/hudson/job/${short_refname}/config.xml 2>/dev/null)
20         if [ $? -ne 0 ] ; then
21                 # Create the job
22                 stable_config=$(wget -O - http://cbas1:8080/hudson/job/stable/config.xml 2>/dev/null)
23                 if [ $? -ne 0 ] ; then
24                         display_error_message "Could not get existing Hudson config for ${short_refname}"
25                         exit 0
26                 fi
27
28                 branch_config="${stable_config/<branch>stable</<branch>$short_refname<}"
29
30                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
31                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
32                 fi
33
34                 echo "$branch_config" > branch_config.txt
35
36                 # wget "http://cbas1:8080/hudson/createItem?name=${short_refname}&mode=copyJob&from=stable" > wget.txt
37                 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "http://cbas1:8080/hudson/createItem?name=${short_refname}" >/dev/null 2>/dev/null
38                 if [ $? -ne 0 ] ; then
39                         display_error_message "Could not create new Hudson job for ${short_refname}"
40                         exit 0
41                 fi
42         else
43                 # Add email to recipients list
44                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
45                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
46
47                         wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "http://cbas1:8080/hudson/job/${short_refname}/config.xml" >/dev/null 2>/dev/null
48                         if [ $? -ne 0 ] ; then
49                                 display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"
50                                 exit 0
51                         fi
52                 fi
53         fi
54 done
55
56 exit 0
57