From: Stephen Haberman Date: Tue, 21 Oct 2008 21:16:04 +0000 (-0500) Subject: First crack at a hudson project creation script. X-Git-Url: http://git.droids-corp.org/?p=git-central.git;a=commitdiff_plain;h=8b13ba49a056a922b349a3530b4d0499257552dd First crack at a hudson project creation script. --- diff --git a/server/post-receive-hudson b/server/post-receive-hudson new file mode 100644 index 0000000..23ccfba --- /dev/null +++ b/server/post-receive-hudson @@ -0,0 +1,59 @@ +#!/bin/sh + +. $(dirname $0)/functions + +email="$USER@payflex.com" + +while read oldrev newrev refname ; do + case "$refname" in + refs/tags/*) + exit 0 + ;; + refs/heads/*) + short_refname=${refname##refs/heads/} + ;; + *) + echo >&2 "*** Unknown type of update to $refname" + exit 1 + ;; + esac + + branch_config=$(wget -O - http://cbas1:8080/hudson/job/${short_refname}/config.xml 2>/dev/null) + if [ $? -ne 0 ] ; then + # Create the job + stable_config=$(wget -O - http://cbas1:8080/hudson/job/stable/config.xml 2>/dev/null) + if [ $? -ne 0 ] ; then + display_error_message "Could not get existing Hudson config for ${short_refname}" + exit 0 + fi + + branch_config="${stable_config/stable$short_refname<}" + + if [ "${branch_config/$email/}" == "$branch_config" ] ; then + branch_config="${branch_config//$email }" + fi + + echo "$branch_config" > branch_config.txt + + # wget "http://cbas1:8080/hudson/createItem?name=${short_refname}&mode=copyJob&from=stable" > wget.txt + wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "http://cbas1:8080/hudson/createItem?name=${short_refname}" >/dev/null 2>/dev/null + if [ $? -ne 0 ] ; then + display_error_message "Could not create new Hudson job for ${short_refname}" + exit 0 + fi + else + # Add email to recipients list + if [ "${branch_config/$email/}" == "$branch_config" ] ; then + branch_config="${branch_config//$email }" + + 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 + if [ $? -ne 0 ] ; then + display_error_message "Could not add $email to Hudson job ${short_refname}" + exit 0 + fi + fi + fi +done + +exit 0 +