Allow integration/distribution patches in multipatch job
[releng/builder.git] / jjb / integration / include-raw-integration-multipatch-distribution-test.sh
1 # create a fresh empty place to build this custom distribution
2 BUILD_DIR=${WORKSPACE}/patch_tester
3 POM_FILE=${WORKSPACE}/patch_tester/pom.xml
4
5 rm -rf $BUILD_DIR
6 mkdir -p $BUILD_DIR
7 cd $BUILD_DIR
8
9 # create a root pom that will contain a module for each project we have a patch for
10 echo "<project>" >> $POM_FILE
11 echo "<groupId>org.opendaylight.test</groupId>" >> $POM_FILE
12 echo "<artifactId>test</artifactId>" >> $POM_FILE
13 echo "<version>0.1</version>" >> $POM_FILE
14 echo "<modelVersion>4.0.0</modelVersion>" >> $POM_FILE
15 echo "<packaging>pom</packaging>" >> $POM_FILE
16 echo "<modules>" >> $POM_FILE
17
18 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
19
20 # for each patch, clone the project, and fetch/checkout the patch set.
21 # each patch is found in the ${PATCHES_TO_BUILD} variable as a comma
22 # separated list of project:changeset values
23 # Example:  PATCHES_TO_BUILD=snmp:97/27997/1,tcpmd5:91/26391/3
24 #
25 # TODO: this version will not handle multiple patches from the same project and will be
26 #       done at a later time.  cherry-picking will be needed, with more complex logic
27 #
28 distribution_status="not_patched"
29 for i in "${PATCHES[@]}"
30 do
31     echo "working on ${i}"
32     PROJECT=`echo ${i} | cut -d\: -f 1`
33     if [ "${PROJECT}" == "integration/distribution" ]; then
34         distribution_status="patched"
35     fi
36     PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
37     PATCH=`echo ${i} | cut -d\: -f 2`
38     echo "<module>${PROJECT_SHORTNAME}</module>" >> $POM_FILE
39     echo "cloning ${PROJECT} and checking out ${PATCH}"
40     git clone https://git.opendaylight.org/gerrit/p/${PROJECT}
41     cd ${PROJECT_SHORTNAME}
42     git fetch https://git.opendaylight.org/gerrit/${PROJECT} refs/changes/${PATCH}
43     git checkout FETCH_HEAD
44     cd $BUILD_DIR
45
46 done
47
48 if [ "${distribution_status}" == "not_patched" ]; then
49     # clone distribution and add it as a module in root pom
50     git clone https://git.opendaylight.org/gerrit/p/integration/distribution
51     # TODO: Should we add support for non-master distribution branches?
52     echo "<module>distribution</module>" >> $POM_FILE
53 fi
54
55 # finish pom file
56 echo "</modules>" >> $POM_FILE
57 echo "</project>" >> $POM_FILE
58
59 # Extract the BUNDLEVERSION from the distribution pom.xml
60 BUNDLEVERSION=`xpath $BUILD_DIR/distribution/pom.xml '/project/version/text()' 2> /dev/null`
61 echo "Bundle version is ${BUNDLEVERSION}"
62
63 BUNDLEURL=${BUILD_URL}org.opendaylight.integration\$distribution-karaf/artifact/org.opendaylight.integration/distribution-karaf/${BUNDLEVERSION}/distribution-karaf-${BUNDLEVERSION}.zip
64 echo "Bundle url is ${BUNDLEURL}"
65
66 # Set BUNDLEVERSION & BUNDLEURL
67 echo BUNDLEVERSION=${BUNDLEVERSION} > ${WORKSPACE}/bundle.txt
68 echo BUNDLEURL=${BUNDLEURL} >> ${WORKSPACE}/bundle.txt