build works
authorHuaxu Wan <huaxu.wan@intel.com>
Mon, 28 Nov 2011 08:37:04 +0000 (16:37 +0800)
committerHuaxu Wan <huaxu.wan@intel.com>
Mon, 28 Nov 2011 08:37:04 +0000 (16:37 +0800)
data/build.sh

index 650feb8..4851432 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/sh
+#!/bin/bash
+
 
 die()
 {
@@ -7,7 +8,7 @@ die()
     exit 
 }
 
-git branch -a|sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'|grep "\-release" > /dev/null 2>&1 || die "Please run this command under release branch"
+git branch -a|sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'|grep "release" > /dev/null 2>&1 || die "Please run this command under release branch"
 
 git status|grep "modified">/dev/null 2>&1 &&die "Please save you local changes before this command, eg git commit"
 
@@ -18,9 +19,65 @@ prj_name=`basename $git_url`
 
 
 tar jcf package.tar.bz2 `git ls-files`
+user=`git config tizen.username`
+passwd=`git config tizen.password`
+HUDSON_SERVER=`git config tizen.hudson`
+
+if ! [[ $user && $passwd && $HUDSON_SERVER  ]]; then
+    echo "-------------------------------------"
+    echo "[tizen]"
+    echo "        username = USERNAME"
+    echo "        password = CLEAR PASSWORD"
+    echo "        hudson = HUDSON Server"
+    echo "-------------------------------------"
+    die "No tizen configuration found, please add the above section to your git config file (~/.gitconfig or .git/config)"
+fi
+
+echo "Submiting your changes to build server"
+
+curl -s -i -u$user:$passwd -Fname=package.tar.bz2 -Ffile0=@package.tar.bz2 -Fjson='{"parameter": [{"name": "package.tar.bz2", "file": "file0"},{"name":"pkg", "value":"'$prj_name'"},{"name":"obsproject","value":"'$t'"}]}' -FSubmit=Build "$HUDSON_SERVER/job/build/build" 
+
+sleep 0.5
+last_id=`curl -s -u$user:$passwd "$HUDSON_SERVER/job/build/lastBuild/buildNumber"`
+
+# In case the last commit is not made by the user, supposed the last job triggered by '$user' is the one. 
+while [ ture ]
+do
+    result_json=`curl -s -u$user:$passwd "$HUDSON_SERVER/job/build/$last_id/api/json"`
+    username=`echo $result_json|python -mjson.tool |grep "userName" |cut -d'"' -f4`
+    if [ x$username != x$user ]; then
+        last_id=`expr $last_id - 1`
+    else
+        build_id=$last_id
+        break
+    fi
+done
+
+    # Waiting until the job finished
+while [ Ture ]
+do
+    result_json=`curl -s -u$user:$passwd "$HUDSON_SERVER/job/build/$build_id/api/json"`
+    status=$(echo $result_json|python -mjson.tool |grep "building.*false")
+    if [ -n "$status" ]; then
+        break
+    fi
+    
+    length=`curl -s -u$user:$passwd "$HUDSON_SERVER/rest/projects/build/$build_id/console/" | cut -d ',' -f2|cut -d ':' -f2`
+    curl -s -u$user:$passwd "$HUDSON_SERVER/rest/projects/build/$build_id/console/content" -d 'length'=$length -d 'offset'=$offset -G
+    string=`curl -s -u$user:$passwd "$HUDSON_SERVER/rest/projects/build/$build_id/console/content" -d 'length'=$length -d 'offset'=$offset -G`
+    offset=$length
+done
+echo ""
 
-#json="{\"parameter\":[{\"name\":\"jobParameters\",\"value\":\"\"}]}"
-#curl -X POST "http://gerrit2.bj.intel.com:8082/job/submit_testing/buildWithParameters?pkg=curl&rev=$1" -v
+result=`echo $result_json|python -mjson.tool |grep result|cut -d '"' -f4`
 
-curl -i -Fname=package.tar.bz2 -Ffile0=@package.tar.bz2 -Fjson='{"parameter": [{"name": "package.tar.bz2", "file": "file0"},{"name":"pkg", "value":"'$prj_name'"}]}' -FSubmit=Build "http://gerrit2.bj.intel.com:8082/job/build/build" -v
+if [  x$result != xSUCCESS ]; then
+    echo -e "${ERR_COLOR}=====LOG FROM REMOTE SERVER=============${NO_COLOR}"
+    curl -s -u$user:$passwd "$HUDSON_SERVER/job/build/$build_id/consoleText"
+    echo -e "${ERR_COLOR}========================================${NO_COLOR}"
+    die 'Remote Server Exception'
+else
+    curl -s -u$user:$passwd "$HUDSON_SERVER/job/build/$build_id/consoleText"
+fi
 
+rm package.tar.bz2