Remove debug output.
[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         ignored=" $(git config hooks.post-receive-hudson.ignored) "
20         if [[ $ignored =~ " $short_refname " ]] ; then
21                 exit 0
22         fi
23
24         branch_config=$(wget -O - http://cbas1:8080/hudson/job/${short_refname}/config.xml 2>/dev/null)
25         if [ $? -ne 0 ] ; then
26                 # Create the job
27                 stable_config=$(wget -O - http://cbas1:8080/hudson/job/stable/config.xml 2>/dev/null)
28                 if [ $? -ne 0 ] ; then
29                         display_error_message "Could not get existing Hudson config for ${short_refname}"
30                         exit 0
31                 fi
32
33                 branch_config="${stable_config/<branch>stable</<branch>$short_refname<}"
34
35                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
36                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
37                 fi
38
39                 # wget "http://cbas1:8080/hudson/createItem?name=${short_refname}&mode=copyJob&from=stable" > wget.txt
40                 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "http://cbas1:8080/hudson/createItem?name=${short_refname}" >/dev/null 2>/dev/null
41                 if [ $? -ne 0 ] ; then
42                         display_error_message "Could not create new Hudson job for ${short_refname}"
43                         exit 0
44                 fi
45         else
46                 # Add email to recipients list
47                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
48                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
49
50                         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
51                         if [ $? -ne 0 ] ; then
52                                 display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"
53                                 exit 0
54                         fi
55                 fi
56         fi
57 done
58
59 exit 0
60