Add hooks.post-receive-hudson.ignored to skip making Hudson projects.
[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                 echo "$branch_config" > branch_config.txt
40
41                 # wget "http://cbas1:8080/hudson/createItem?name=${short_refname}&mode=copyJob&from=stable" > wget.txt
42                 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "http://cbas1:8080/hudson/createItem?name=${short_refname}" >/dev/null 2>/dev/null
43                 if [ $? -ne 0 ] ; then
44                         display_error_message "Could not create new Hudson job for ${short_refname}"
45                         exit 0
46                 fi
47         else
48                 # Add email to recipients list
49                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
50                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
51
52                         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
53                         if [ $? -ne 0 ] ; then
54                                 display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"
55                                 exit 0
56                         fi
57                 fi
58         fi
59 done
60
61 exit 0
62