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 DISTRIBUTION_BRANCH_TO_BUILD=$DISTROBRANCH #renaming variable for clarity
12 MAVEN_OPTIONS="$(echo --show-version \
15 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
16 -Dmaven.repo.local=/tmp/r \
17 -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)"
21 cd $BUILD_DIR || exit 1
23 # Set up git committer name and email, needed for commit creation when cherry-picking.
24 export EMAIL="sandbox@jenkins.opendaylight.org"
25 export GIT_COMMITTER_NAME="Multipatch Job"
27 # Extract a list of patches per project from an comment trigger. An example is:
30 # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1
31 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
32 # Grep the multipatch-build: line and then strip from the beginning to the :
33 PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
34 PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:}
36 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
39 # * Clone the project.
40 # * Optionally, checkout a specific (typically unmerged) Gerrit patch. If none,
41 # default to Integration/Distribution branch via {branch} JJB param.
42 # * Also optionally, cherry-pick series of patches on top of the checkout.
43 # * Final option: perform a 'release' by removing "-SNAPSHOT" everywhere within the project.
45 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
46 # list of project[=checkout][:cherry-pick]* values.
48 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
50 # PATCHES_TO_BUILD='odlparent=45/30045/2'
52 # Checkout patches for both odlparent and yangtools:
54 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
56 # Checkout a patch for controller, cherry-pick another patch on top of it:
58 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
59 distribution_status="not_included"
60 for proto_patch in "${PATCHES[@]}"
62 echo "working on ${proto_patch}"
63 # For patch=controller=61/29761/5:45/29645/6, this gives controller
64 PROJECT="$(echo ${proto_patch} | cut -d\: -f 1 | cut -d\= -f 1)"
65 if [ "${PROJECT}" == "integration/distribution" ]; then
66 distribution_status="included"
68 PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500
69 echo "cloning project ${PROJECT}"
70 git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
71 cd ${PROJECT_SHORTNAME} || exit 1
72 if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
73 pure_patch="$(echo -n $proto_patch | head -c -1)"
75 pure_patch="$proto_patch"
77 # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5
78 CHECKOUT="$(echo ${pure_patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
79 if [ "x${CHECKOUT}" != "x" ]; then
80 echo "checking out ${CHECKOUT}"
81 # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
82 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
83 git checkout FETCH_HEAD
85 echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
86 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
88 # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
89 PICK_SEGMENT="$(echo "${pure_patch}" | cut -d\: -s -f 2-)"
90 IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
91 for pick in "${PICKS[@]}"
93 echo "cherry-picking ${pick}"
94 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
95 git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
97 if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
98 # Here 'r' means release. Useful for testing Nitrogen Odlparent changes.
99 find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
102 "$MVN" clean install \
106 -Dmaven.gitcommitid.skip=false \
107 --global-settings "$GLOBAL_SETTINGS_FILE" \
108 --settings "$SETTINGS_FILE" \
110 cd "${BUILD_DIR}" || exit 1
113 if [ "${distribution_status}" == "not_included" ]; then
114 echo "adding integration/distribution"
115 # clone distribution and add it as a module in root pom
116 git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
117 cd distribution || exit 1
118 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
120 "$MVN" clean install \
122 -Dstream="$DISTROSTREAM" \
123 --global-settings "$GLOBAL_SETTINGS_FILE" \
124 --settings "$SETTINGS_FILE" \
126 cd "${BUILD_DIR}" || exit 1