Adding ability to build from different distribution branches
[releng/builder.git] / jjb / integration / include-raw-integration-multipatch-distribution-test.sh
old mode 100755 (executable)
new mode 100644 (file)
index 127fc43..b84122c
@@ -1,6 +1,7 @@
 # create a fresh empty place to build this custom distribution
 BUILD_DIR=${WORKSPACE}/patch_tester
 POM_FILE=${WORKSPACE}/patch_tester/pom.xml
+DISTRIBUTION_BRANCH_TO_BUILD=$BRANCH  #renaming variable for clarity
 
 rm -rf $BUILD_DIR
 mkdir -p $BUILD_DIR
@@ -24,30 +25,43 @@ IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
 #
 # TODO: this version will not handle multiple patches from the same project and will be
 #       done at a later time.  cherry-picking will be needed, with more complex logic
-# TODO: Another enchancement will be to allow distribution patches.
 #
+distribution_status="not_patched"
 for i in "${PATCHES[@]}"
 do
     echo "working on ${i}"
     PROJECT=`echo ${i} | cut -d\: -f 1`
+    if [ "${PROJECT}" == "integration/distribution" ]; then
+        distribution_status="patched"
+    fi
+    PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
     PATCH=`echo ${i} | cut -d\: -f 2`
-    echo "<module>${PROJECT}</module>" >> $POM_FILE
+    echo "<module>${PROJECT_SHORTNAME}</module>" >> $POM_FILE
     echo "cloning ${PROJECT} and checking out ${PATCH}"
     git clone https://git.opendaylight.org/gerrit/p/${PROJECT}
-    cd ${PROJECT}
+    cd ${PROJECT_SHORTNAME}
     git fetch https://git.opendaylight.org/gerrit/${PROJECT} refs/changes/${PATCH}
     git checkout FETCH_HEAD
     cd $BUILD_DIR
-
 done
 
-# clone distribution and add it as a module in root pom
-git clone https://git.opendaylight.org/gerrit/p/integration/distribution
+# if distribution was not cloned above, we still need to get it
+if [ "${distribution_status}" == "not_patched" ]; then
+    git clone https://git.opendaylight.org/gerrit/p/integration/distribution
+    echo "<module>distribution</module>" >> $POM_FILE
+fi
 
-echo "<module>distribution</module>" >> $POM_FILE
+# finish pom file
 echo "</modules>" >> $POM_FILE
 echo "</project>" >> $POM_FILE
 
+# by default we can stay in master branch or checkout something else here
+if [ "${DISTRIBUTION_BRANCH_TO_BUILD}" != "master" ]; then
+    cd distribution
+    git checkout ${DISTRIBUTION_BRANCH_TO_BUILD}
+fi
+
+
 # Extract the BUNDLEVERSION from the distribution pom.xml
 BUNDLEVERSION=`xpath $BUILD_DIR/distribution/pom.xml '/project/version/text()' 2> /dev/null`
 echo "Bundle version is ${BUNDLEVERSION}"
@@ -57,4 +71,4 @@ echo "Bundle url is ${BUNDLEURL}"
 
 # Set BUNDLEVERSION & BUNDLEURL
 echo BUNDLEVERSION=${BUNDLEVERSION} > ${WORKSPACE}/bundle.txt
-echo BUNDLEURL=${BUNDLEURL} >> ${WORKSPACE}/bundle.txt
\ No newline at end of file
+echo BUNDLEURL=${BUNDLEURL} >> ${WORKSPACE}/bundle.txt