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