Permalink
Browse files

got the post receive hudson working: needed to support both calling f…

…rom command line and calling from another script
  • Loading branch information...
1 parent 0c1a0b5 commit 11d669e80eb05008f03889d4edd2bf358ab1c90e Aaron Boxer committed Apr 21, 2011
Showing with 32 additions and 15 deletions.
  1. +31 −13 server/post-receive-hudson
  2. +1 −2 server/post-receive.hudson.sample
View
@@ -10,43 +10,51 @@
# ------
# hooks.post-receive-hudson.url
# The url to hudson, e.g. http://internalbox/hudson
+# hooks.post-receive-hudson.user
+# Hudson user name
+# hooks.post-receive-hudson.password
+# Hudson password
# hooks.post-receive-hudson.ignored
# Whitespace separated list of branches to not make jobs for.
# USER_EMAIL
# Environment variable that should be set by your repository-specific
-# post-receive hook. E.g. export USER_EMAIL=${USER}@example.com. If
-# unset, defaults to the email by of the pushed commit.
+# post-receive hook. E.g. export USER_EMAIL=${USER}@example.com
#
. $(dirname $0)/functions
-# get committer's email address
-USER_EMAIL=$(git log -1 --pretty=format:'%ce')
-while read oldrev newrev refname ; do
- case "$refname" in
+hudson()
+{
+
+ case "$1" in
refs/tags/*)
exit 0
;;
refs/heads/*)
- short_refname=${refname##refs/heads/}
+ short_refname=${1##refs/heads/}
;;
*)
- echo >&2 "*** Unknown type of update to $refname"
+ display_error_message "*** Unknown type of update to $1"
exit 1
;;
esac
+ echo "Check ignore list"
ignored=" $(git config hooks.post-receive-hudson.ignored) "
hudson_url=$(git config hooks.post-receive-hudson.url)
if [[ $ignored =~ " $short_refname " ]] ; then
+
exit 0
fi
- if [ -z "$USER_EMAIL" ] ; then
+ # parse USER_EMAIL from git log if not set
+ if [ -z "$USER_EMAIL" ] ; then
USER_EMAIL=$(git log -1 --pretty=format:'%ce' $newrev)
fi
+
+
jobName=$REPOSITORY_BASE_NAME$short_refname
jobUrl=$hudson_url"/job/"${jobName}
jobNameMaster=$REPOSITORY_BASE_NAME"master"
@@ -88,12 +96,22 @@ while read oldrev newrev refname ; do
fi
-#Trigger Build
+echo "Trigger Build for job $jobUrl"
buildUrl=$jobUrl"/build"
-curl -X POST $buildUrl -u git:banana -d token=$TOKEN --data-urlencode json="$JSON
+hudson_user=$(git config hooks.post-receive-hudson.user)
+hudson_password=$(git config hooks.post-receive-hudson.password)
+curl -X POST $buildUrl -u $hudson_user:$hudson_password -d token=$TOKEN --data-urlencode json="$JSON
"
-done
+}
-exit 0
+# Main()
+if [ -n "$1" ]; then
+ hudson $1
+else
+ while read oldrev newrev refname
+ do
+ hudson $refname
+ done
+fi
@@ -12,7 +12,6 @@
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".
-
# get base repository name
if [ $(git rev-parse --is-bare-repository) = true ]
then
@@ -28,6 +27,6 @@ export JSON="{\"parameter\": [{\"name\": \"Configuration\", \"value\": \"Release
{\"name\": \"DistributionBuild\", \"value\": \"FALSE\"}], \"\": \"\"}"
export TOKEN="EGGPLANT"
-/usr/share/doc/git-core/contrib/hooks/post-receive-hudson
+/usr/share/doc/git-core/contrib/hooks/post-receive-hudson

0 comments on commit 11d669e

Please sign in to comment.