Merge "Revert "Genius CSIT verify jobs broken""
[releng/builder.git] / jjb / integration / multipatch-distribution.sh
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
7 #          helpful
8
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 \
13     --batch-mode \
14     -Djenkins \
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)"
18
19 rm -rf $BUILD_DIR
20 mkdir -p $BUILD_DIR
21 cd $BUILD_DIR || exit 1
22
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"
26
27 # Extract a list of patches per project from an comment trigger. An example is:
28 # Patch Set 1:
29 #
30 # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1
31 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
32     if [[ "$GERRIT_EVENT_COMMENT_TEXT" == *fast* ]]; then
33         BUILD_FAST="true"
34         PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build-fast:')
35     else
36         BUILD_FAST="false"
37         PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
38     fi
39     PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:}
40 fi
41 if ${BUILD_FAST}; then
42     fast_option="-Pq"
43 else
44     fast_option=""
45 fi
46 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
47
48 # For each patch:
49 # * Clone the project.
50 # * Optionally, checkout a specific (typically unmerged) Gerrit patch. If none,
51 #   default to Integration/Distribution branch via {branch} JJB param.
52 # * Also optionally, cherry-pick series of patches on top of the checkout.
53 # * Final option: perform a 'release' by removing "-SNAPSHOT" everywhere within the project.
54 #
55 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
56 # list of project[=checkout][:cherry-pick]* values.
57 #
58 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
59 #
60 # PATCHES_TO_BUILD='odlparent=45/30045/2'
61 #
62 # Checkout patches for both odlparent and yangtools:
63 #
64 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
65 #
66 # Checkout a patch for controller, cherry-pick another patch on top of it:
67 #
68 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
69 distribution_status="not_included"
70 for proto_patch in "${PATCHES[@]}"
71 do
72     echo "working on ${proto_patch}"
73     # For patch=controller=61/29761/5:45/29645/6, this gives controller
74     PROJECT="$(echo ${proto_patch} | cut -d\: -f 1 | cut -d\= -f 1)"
75     if [ "${PROJECT}" == "integration/distribution" ]; then
76         distribution_status="included"
77     fi
78     PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
79     echo "cloning project ${PROJECT}"
80     git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
81     cd ${PROJECT_SHORTNAME} || exit 1
82     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
83         pure_patch="$(echo -n $proto_patch | head -c -1)"
84     else
85         pure_patch="$proto_patch"
86     fi
87     # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5
88     CHECKOUT="$(echo ${pure_patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
89     if [ "x${CHECKOUT}" != "x" ]; then
90         echo "checking out ${CHECKOUT}"
91         # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
92         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
93         git checkout FETCH_HEAD
94     else
95         echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
96         git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
97     fi
98     # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
99     PICK_SEGMENT="$(echo "${pure_patch}" | cut -d\: -s -f 2-)"
100     IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
101     for pick in "${PICKS[@]}"
102     do
103         echo "cherry-picking ${pick}"
104         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
105         git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
106     done
107     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
108         # Here 'r' means release. Useful for testing Nitrogen Odlparent changes.
109         find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
110     fi
111     # Build project
112     "$MVN" clean install \
113     -e ${fast_option} \
114     -Dstream=oxygen \
115     -Dgitid.skip=false \
116     -Dmaven.gitcommitid.skip=false \
117     --global-settings "$GLOBAL_SETTINGS_FILE" \
118     --settings "$SETTINGS_FILE" \
119     $MAVEN_OPTIONS
120     cd "${BUILD_DIR}" || exit 1
121     # Since we've installed the artifacts, we can delete the build and save
122     # disk space
123     rm -rf "${PROJECT_SHORTNAME}"
124 done
125
126 if [ "${distribution_status}" == "not_included" ]; then
127     echo "adding integration/distribution"
128     # clone distribution and add it as a module in root pom
129     git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
130     cd distribution || exit 1
131     git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
132     # Build project
133     "$MVN" clean install \
134     -e -Pq \
135     -Dstream="$DISTROSTREAM" \
136     --global-settings "$GLOBAL_SETTINGS_FILE" \
137     --settings "$SETTINGS_FILE" \
138     $MAVEN_OPTIONS
139     cd "${BUILD_DIR}" || exit 1
140 fi
141