Fix genius CSIT jobs
[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 # TODO: Is there a more appropriate e-mail?
26 export GIT_COMMITTER_NAME="Multipatch Job"
27
28 # TODO: Is "patches" still the correct word?
29 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
30     PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" \
31         | grep 'multipatch-build:' | awk -F: '{print $2}')
32 fi
33 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
34
35 # For each patch:
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.
40 # * Final option: perform a 'release' by removing "-SNAPSHOT" everywhere within the project.
41 #
42 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
43 # list of project[=checkout][:cherry-pick]* values.
44 #
45 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
46 #
47 # PATCHES_TO_BUILD='odlparent=45/30045/2'
48 #
49 # Checkout patchs for both odlparent and yangtools.
50 #
51 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
52 #
53 # Checkout a patch for controller, cherry-pick another patch on top of it.
54 #
55 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
56 distribution_status="not_included"
57 for proto_patch in "${PATCHES[@]}"
58 do
59     echo "working on ${proto_patch}"
60     # For patch=controller=61/29761/5:45/29645/6, this gives controller
61     PROJECT="$(echo ${proto_patch} | cut -d\: -f 1 | cut -d\= -f 1)"
62     if [ "${PROJECT}" == "integration/distribution" ]; then
63         distribution_status="included"
64     fi
65     PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
66     echo "cloning project ${PROJECT}"
67     git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
68     cd ${PROJECT_SHORTNAME} || exit 1
69     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
70         pure_patch="$(echo -n $proto_patch | head -c -1)"
71     else
72         pure_patch="$proto_patch"
73     fi
74     # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5
75     CHECKOUT="$(echo ${pure_patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
76     if [ "x${CHECKOUT}" != "x" ]; then
77         echo "checking out ${CHECKOUT}"
78         # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
79         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
80         git checkout FETCH_HEAD
81     else
82         echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
83         git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
84     fi
85     # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
86     PICK_SEGMENT="$(echo "${pure_patch}" | cut -d\: -s -f 2-)"
87     IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
88     for pick in "${PICKS[@]}"
89     do
90         echo "cherry-picking ${pick}"
91         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
92         git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
93     done
94     if [ "$(echo -n ${proto_patch} | tail -c 1)" == 'r' ]; then
95         # Here 'r' means release. Useful for testing Nitrogen Odlparent changes.
96         find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
97     fi
98     # Build project
99     "$MVN" clean install \
100     -e -Pq \
101     -Dstream=oxygen \
102     -DskipTests=true \
103     --global-settings "$GLOBAL_SETTINGS_FILE" \
104     --settings "$SETTINGS_FILE" \
105     $MAVEN_OPTIONS
106     cd "${BUILD_DIR}" || exit 1
107 done
108
109 if [ "${distribution_status}" == "not_included" ]; then
110     echo "adding integration/distribution"
111     # clone distribution and add it as a module in root pom
112     git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
113     cd distribution || exit 1
114     git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
115     # Build project
116     "$MVN" clean install \
117     -e -Pq \
118     -Dstream="$DISTROSTREAM" \
119     -DskipTests=true \
120     --global-settings "$GLOBAL_SETTINGS_FILE" \
121     --settings "$SETTINGS_FILE" \
122     $MAVEN_OPTIONS
123     cd "${BUILD_DIR}" || exit 1
124 fi
125