5 # create a fresh empty place to build this custom distribution
6 BUILD_DIR=${WORKSPACE}/patch_tester
7 DISTRIBUTION_BRANCH_TO_BUILD=$DISTROBRANCH #renaming variable for clarity
8 MAVEN_OPTIONS="${MAVEN_PARAMS} \
12 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
13 -Dmaven.repo.local=/tmp/r \
14 -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r"
20 # Download distribution pom.xml
21 wget "http://git.opendaylight.org/gerrit/gitweb?p=integration/distribution.git;a=blob_plain;f=artifacts/upstream/properties/pom.xml;hb=refs/heads/$DISTROBRANCH" -O "pom.xml"
24 # Set up git committer name and email, needed for commit creation when cherry-picking.
25 export EMAIL="sandbox@jenkins.opendaylight.org"
26 export GIT_COMMITTER_NAME="Multipatch Job"
28 # Extract a list of patches per project from an comment trigger. An example is:
29 # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1
30 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
31 if [[ "$GERRIT_EVENT_COMMENT_TEXT" == *fast* ]]; then
33 PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build-fast:')
36 PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
38 PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:}
40 if ${BUILD_FAST}; then
45 # check if topic exists, e.g. topic=binding-tlc-rpc
46 if [[ "${PATCHES_TO_BUILD}" == *topic* ]]; then
47 TOPIC="${PATCHES_TO_BUILD#*=}"
48 echo "Create topic ${TOPIC} patch list"
50 read -ra PROJECT_LIST <<< "${BUILD_ORDER}"
51 echo "List of projects to check patch in topic: ${PROJECT_LIST[*]}"
52 for PROJECT in "${PROJECT_LIST[@]}"; do
53 # get all patches number for a topic for a given project
54 IFS=$'\n' read -rd '' -a GERRIT_PATCH_LIST <<< "$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query status:open topic:${TOPIC} project:${PROJECT} 2> /dev/null \
55 | grep 'number:' | awk '{{ print $2 }}')" || true
56 # add project if it is the first with patches or it is not the first
57 if [[ -z "${PATCHES_TO_BUILD}" && ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
58 PATCHES_TO_BUILD="${PROJECT}"
59 elif [[ ! -z "${PATCHES_TO_BUILD}" ]]; then
60 if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
61 echo "Add ${PROJECT}:${DISTRIBUTION_BRANCH_TO_BUILD}"
63 PATCHES_TO_BUILD="${PATCHES_TO_BUILD},${PROJECT}"
65 # sort project patches
66 if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
67 echo "Add ${PROJECT}:${GERRIT_PATCH_LIST[*]}"
69 # create reference list with patch number-refspec
70 for PATCH in "${GERRIT_PATCH_LIST[@]}"; do
71 REFSPEC=$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query change:${PATCH} --current-patch-set \
72 | grep 'ref:' | awk '{{ print $2 }}')
73 REF_LIST+=("${PATCH}-${REFSPEC/refs\/changes\/}")
75 # sort reference list by patch number
76 IFS=$'\n' SORT_REF=$(sort <<<"${REF_LIST[*]}") && unset IFS
77 read -rd '' -a SORT_REF_LIST <<< "${SORT_REF[*]}" || true
78 # add refspec to patches to build list
79 for PATCH in "${SORT_REF_LIST[@]}"; do
80 # cherry-pick is better than checkout patch
81 PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}"
86 echo "Patches to build: ${PATCHES_TO_BUILD}"
87 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
89 # First phase: clone the necessary repos and set the patches up
94 # 1. Clone the project.
95 # 2. Checkout an specific (typically unmerged) Gerrit patch. If none,
96 # use distribution pom.xml file to figure out right branch or tag to checkout.
97 # In case of Gerrit patch in MRI project, adjust version for the stream.
98 # 3. Optionally, cherry-pick series of patches on top of the checkout.
100 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
101 # list of project[=checkout][:cherry-pick]* values. Examples:
103 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
104 # PATCHES_TO_BUILD='odlparent=45/30045/2'
106 # Checkout patches for both odlparent and yangtools:
107 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
109 # Checkout a patch for controller, cherry-pick another patch on top of it:
110 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
111 distribution_status="not_included"
112 for patch in "${PATCHES[@]}"
114 echo "-- working on ${patch} --"
115 # For patch=controller=61/29761/5:45/29645/6, this gives controller.
116 PROJECT="$(echo ${patch} | cut -d\: -f 1 | cut -d\= -f 1)"
117 if [ "${PROJECT}" == "integration/distribution" ]; then
118 distribution_status="included"
120 PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500
121 PROJECTS+=("${PROJECT_SHORTNAME}")
122 echo "1. cloning project ${PROJECT}"
123 git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
124 cd ${PROJECT_SHORTNAME}
125 # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5.
126 CHECKOUT="$(echo ${patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
127 # If there is a base patch for this project, checkout patch, otherwise use
128 # distribution pom.xml file to figure out right branch or tag to checkout.
129 if [ "x${CHECKOUT}" != "x" ]; then
130 echo "2. checking out patch ${CHECKOUT}"
131 # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
132 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
133 git checkout FETCH_HEAD
134 # If the patch is for MRI project, adjust the MRI versions
135 if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
136 ODLPARENT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:odlparent.version ../pom.xml)"
137 echo "change odlparent version to ${ODLPARENT_VERSION}"
138 find . -name "*.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:groupId=\"org.opendaylight.odlparent\"\] -v "${ODLPARENT_VERSION}" 2> /dev/null
140 if [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
141 YANGTOOLS_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:yangtools.version ../pom.xml)"
142 echo "change yangtools version to ${YANGTOOLS_VERSION}"
143 find -name "*.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:groupId=\"org.opendaylight.yangtools\"\] -v "${YANGTOOLS_VERSION}" 2> /dev/null
145 if [ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]; then
146 MDSAL_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:mdsal.version ../pom.xml)"
147 echo "change mdsal version to ${MDSAL_VERSION}"
148 find -name "*.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:groupId=\"org.opendaylight.mdsal\"\] -v "${MDSAL_VERSION}" 2> /dev/null
151 # If project with no patch is MRI, download release tag:
152 if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
153 PROJECT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:${PROJECT_SHORTNAME}.version ../pom.xml)"
154 echo "2. checking out tag v${PROJECT_VERSION}"
155 git checkout tags/v${PROJECT_VERSION}
156 # Otherwise download distribution branch:
158 echo "2. checking out branch ${DISTRIBUTION_BRANCH_TO_BUILD}"
159 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
162 # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
163 PICK_SEGMENT="$(echo "${patch}" | cut -d\: -s -f 2-)"
164 IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
165 for pick in "${PICKS[@]}"
167 echo "3. cherry-picking ${pick}"
168 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
169 git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
174 # Finally add distribution if there is no int/dist patch
175 if [ "${distribution_status}" == "not_included" ]; then
176 echo "adding integration/distribution"
177 PROJECTS+=(distribution)
178 # clone distribution and add it as a module in root pom
179 git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
181 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
185 # Second phase: build everything
187 for PROJECT_SHORTNAME in "${PROJECTS[@]}"; do
188 pushd "${PROJECT_SHORTNAME}"
190 "$MVN" clean install \
192 -Dstream="$DISTROSTREAM" \
194 -Dmaven.gitcommitid.skip=false \
195 --global-settings "$GLOBAL_SETTINGS_FILE" \
196 --settings "$SETTINGS_FILE" \
198 # Since we've installed the artifacts, we can clean the build and save
202 -Dstream="$DISTROSTREAM" \
204 -Dmaven.gitcommitid.skip=false \
205 --global-settings "$GLOBAL_SETTINGS_FILE" \
206 --settings "$SETTINGS_FILE" \