Make integration-multipatch-test deploy to Nexus
[releng/builder.git] / jjb / integration / include-raw-integration-multipatch-distribution-test.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 POM_FILE=${WORKSPACE}/patch_tester/pom.xml
12 DISTRIBUTION_BRANCH_TO_BUILD=$DISTROBRANCH  #renaming variable for clarity
13
14 rm -rf $BUILD_DIR
15 mkdir -p $BUILD_DIR
16 cd $BUILD_DIR
17
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
26
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"
31
32 # TODO: Is "patches" still the correct word?
33 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
34
35 # For each patch, clone the project.
36 # Optionally checkout a specific patch set.
37 # Also optionally, cherry-pick series of patch sets.
38 # Each patch is found in the ${PATCHES_TO_BUILD} variable
39 # as a comma separated list of project[=checkout][:cherry-pick]* values
40 #
41 # Example:  PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25,mdsal,controller=61/29761/5:45/29645/6,bgpcep:39/30239/1:59/30059/2'
42 #
43 distribution_status="not_included"
44 for patch_code in "${PATCHES[@]}"
45 do
46     echo "working on ${patch_code}"
47     PROJECT=`echo ${patch_code} | cut -d\: -f 1 | cut -d\= -f 1`
48     if [ "${PROJECT}" == "integration/distribution" ]; then
49         distribution_status="included"
50     fi
51     PROJECT_SHORTNAME="${PROJECT##*/}"  # http://stackoverflow.com/a/3162500
52     echo "cloning project ${PROJECT}"
53     git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
54     echo "<module>${PROJECT_SHORTNAME}</module>" >> ${POM_FILE}
55     cd ${PROJECT_SHORTNAME}
56     CHECKOUT=`echo ${patch_code} | cut -d\= -s -f 2 | cut -d\: -f 1`
57     if [ "x${CHECKOUT}" != "x" ]; then
58         echo "checking out ${CHECKOUT}"
59         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
60         git checkout FETCH_HEAD
61     else
62         echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
63         git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
64     fi
65     PICK_SEGMENT=`echo "${patch_code}" | cut -d\: -s -f 2-`
66     IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
67     for pick in "${PICKS[@]}"
68     do
69         echo "cherry-picking ${pick}"
70         git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
71         git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
72     done
73     cd "${BUILD_DIR}"
74 done
75
76 if [ "${distribution_status}" == "not_included" ]; then
77     echo "adding integration/distribution"
78     # clone distribution and add it as a module in root pom
79     git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
80     cd distribution
81     git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
82     cd "${BUILD_DIR}"
83     echo "<module>distribution</module>" >> ${POM_FILE}
84 fi
85
86 # finish pom file
87 echo "</modules>" >> ${POM_FILE}
88 echo "</project>" >> ${POM_FILE}