From 9713ede3423f7f53bc52cc8b8c7f6eb601b6d30b Mon Sep 17 00:00:00 2001
From: Jeremy Mordkoff <jeremy.mordkoff@riftio.com>
Date: Thu, 8 Sep 2016 14:24:27 -0400
Subject: [PATCH] update SO, UI and template to accept the parameters passed by
 Gerrit to trigger a pre-merge test compile

Signed-off-by: Jeremy Mordkoff <jeremy.mordkoff@riftio.com>
---
 jenkins/SO/start_build       | 26 ++++++++++++++++----------
 jenkins/UI/start_build       | 12 +++++++++++-
 jenkins/template/start_build | 16 +++++++++++++++-
 3 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/jenkins/SO/start_build b/jenkins/SO/start_build
index 85d2ca7c..ac07fc7f 100755
--- a/jenkins/SO/start_build
+++ b/jenkins/SO/start_build
@@ -29,20 +29,26 @@ OSM_load_config
 
 # Here is an example for how to handle an incremental build
 if [ -d $OSM_MDG ]; then
-	INFO "reusing existing workspace"
-	cd $OSM_MDG
-	git pull 
+    INFO "reusing existing workspace"
+    cd $OSM_MDG
+    git pull 
 else
-	INFO "cloning MDG $OSM_MDG from $OSM_GIT_URL/$OSM_MDG"
-	git clone $OSM_GIT_URL/$OSM_MDG
-	cd $OSM_MDG
+    INFO "cloning MDG $OSM_MDG from $OSM_GIT_URL/$OSM_MDG"
+    git clone $OSM_GIT_URL/$OSM_MDG
+    cd $OSM_MDG
 fi
-INFO "starting build"
 
-### for start_build
-### put your commands here to 
-### build, test and produce coverage reports
+if [ $# -gt 0 ]; then
+    INFO "Code to compile: gerrit refspec '$1', commit-id: '$2'"
+    git fetch origin $1 || FATAL "git fetch origin '$1' didn't work"
+    git checkout -f $2 || FATAL "git checkout -f '$2' didn't work"
+else
+    INFO "Code to compile: master"
+    git checkout master
+fi
 
+INFO "starting build"
+make clean || FATAL "make clean failed"
 ./BUILD.sh
 
 RC=$?
diff --git a/jenkins/UI/start_build b/jenkins/UI/start_build
index 772a3c2e..b05a7e26 100755
--- a/jenkins/UI/start_build
+++ b/jenkins/UI/start_build
@@ -37,8 +37,18 @@ else
 	git clone $OSM_GIT_URL/$OSM_MDG
 	cd $OSM_MDG
 fi
-INFO "starting build"
 
+if [ $# -gt 0 ]; then
+    INFO "Code to compile: gerrit refspec '$1', commit-id: '$2'"
+    git fetch origin $1 || FATAL "git fetch origin '$1' didn't work"
+    git checkout -f $2 || FATAL "git checkout -f '$2' didn't work"
+else
+    INFO "Code to compile: master"
+    git checkout master
+fi
+
+INFO "starting build"
+make clean || FATAL "Make clean failed"
 make -j16 || FATAL "Make failed"
 sudo make install || FATAL "Make install Failed"
 
diff --git a/jenkins/template/start_build b/jenkins/template/start_build
index 38f35b5b..2bd9074b 100755
--- a/jenkins/template/start_build
+++ b/jenkins/template/start_build
@@ -37,11 +37,25 @@ else
 	git clone $OSM_GIT_URL/$OSM_MDG
 	cd $OSM_MDG
 fi
-INFO "starting build"
 
+# Gerrit arranges to call this script with two parameters -- the refspec and commit ID that needs to be built
+if [ $# -gt 0 ]; then
+    INFO "Code to compile: gerrit refspec '$1', commit-id: '$2'"
+    git fetch origin $1 || FATAL "git fetch origin '$1' didn't work"
+    git checkout -f $2 || FATAL "git checkout -f '$2' didn't work"
+else
+    INFO "Code to compile: master"
+    git checkout master
+fi
+
+INFO "starting build"
 ### for start_build
 ### put your commands here to 
 ### build, test and produce coverage reports
+# E.G.
+#make clean || FATAL "make clean failed"
+#make || FATAL "make failed"
+#sudo make install || FATAL "make install failed"
 
 RC=0
 
-- 
GitLab