1 # TODO: 1) clean up inline todo's below :)
2 # TODO: 2) Use just a topic branch to create a distribution. see this email:
3 # https://lists.opendaylight.org/pipermail/discuss/2015-December/006040.html
4 # TODO: 3) Bubble up CSIT jobs that are triggered by the multipatch job to a jenkins
5 # parameter. the default can be distribution-test which calls all CSIT jobs
6 # but being able to easily override it to a smaller subset (or none) will be
9 # create a fresh empty place to build this custom distribution
10 BUILD_DIR=${WORKSPACE}/patch_tester
11 POM_FILE=${WORKSPACE}/patch_tester/pom.xml
12 DISTRIBUTION_BRANCH_TO_BUILD=$DISTROBRANCH #renaming variable for clarity
16 cd $BUILD_DIR || exit 1
18 # create a root pom that will contain a module for each project we have a patch for
19 echo "<project>" >> $POM_FILE
20 echo "<groupId>org.opendaylight.test</groupId>" >> $POM_FILE
21 echo "<artifactId>test</artifactId>" >> $POM_FILE
22 echo "<version>0.1</version>" >> $POM_FILE
23 echo "<modelVersion>4.0.0</modelVersion>" >> $POM_FILE
24 echo "<packaging>pom</packaging>" >> $POM_FILE
25 echo "<modules>" >> $POM_FILE
27 # Set up git committer name and email, needed for commit creation when cherry-picking.
28 export EMAIL="sandbox@jenkins.opendaylight.org"
29 # TODO: Is there a more appropriate e-mail?
30 export GIT_COMMITTER_NAME="Multipatch Job"
32 # TODO: Is "patches" still the correct word?
33 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
36 # * Clone the project.
37 # * Optionally, checkout a specific (typically unmerged) Gerrit patch. If none,
38 # default to Integration/Distribution branch via {branch} JJB param.
39 # * Also optionally, cherry-pick series of patchs on top of the checkout.
41 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
42 # list of project[=checkout][:cherry-pick]* values.
44 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
46 # PATCHES_TO_BUILD='odlparent=45/30045/2'
48 # Checkout patchs for both odlparent and yangtools.
50 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
52 # Checkout a patch for controller, cherry-pick another patch on top of it.
54 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
55 distribution_status="not_included"
56 for patch in "${PATCHES[@]}"
58 echo "working on ${patch}"
59 # For patch=controller=61/29761/5:45/29645/6, this gives controller
60 PROJECT=`echo ${patch} | cut -d\: -f 1 | cut -d\= -f 1`
61 if [ "${PROJECT}" == "integration/distribution" ]; then
62 distribution_status="included"
64 PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500
65 echo "cloning project ${PROJECT}"
66 git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
67 echo "<module>${PROJECT_SHORTNAME}</module>" >> ${POM_FILE}
68 cd ${PROJECT_SHORTNAME} || exit 1
69 # For patch=controller=61/29761/5:45/29645/6, this gives 61/29761/5
70 CHECKOUT=`echo ${patch} | cut -d\= -s -f 2 | cut -d\: -f 1`
71 if [ "x${CHECKOUT}" != "x" ]; then
72 echo "checking out ${CHECKOUT}"
73 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
74 git checkout FETCH_HEAD
76 echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
77 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
79 # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
80 PICK_SEGMENT=`echo "${patch}" | cut -d\: -s -f 2-`
81 IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
82 for pick in "${PICKS[@]}"
84 echo "cherry-picking ${pick}"
85 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
86 git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
88 cd "${BUILD_DIR}" || exit 1
91 if [ "${distribution_status}" == "not_included" ]; then
92 echo "adding integration/distribution"
93 # clone distribution and add it as a module in root pom
94 git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
95 cd distribution || exit 1
96 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
97 cd "${BUILD_DIR}" || exit 1
98 echo "<module>distribution</module>" >> ${POM_FILE}
102 echo "</modules>" >> "${POM_FILE}"
103 echo "</project>" >> "${POM_FILE}"