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 # check if topic exists:
41 # if topic=binding-rpc, then checkout first patch in binding-rpc topic (if it exists)
42 # if topic:binding-rpc, then cherry-pick first patch in binding-rpc topic (if it exists)
43 if [[ "${PATCHES_TO_BUILD}" == *"topic"* ]]; then
44 if [[ "${PATCHES_TO_BUILD}" == *"topic="* ]]; then
46 TOPIC="${PATCHES_TO_BUILD#*=}"
47 elif [[ "${PATCHES_TO_BUILD}" == *"topic:"* ]]; then
49 TOPIC="${PATCHES_TO_BUILD#*:}"
51 echo "ERROR: Topic has wrong format" && exit 1
53 echo "Create topic ${TOPIC} patch list"
55 read -ra PROJECT_LIST <<< "${BUILD_ORDER}"
56 echo "List of projects to check patch in topic: ${PROJECT_LIST[*]}"
57 for PROJECT in "${PROJECT_LIST[@]}"; do
58 # get all patches number for a topic for a given project
59 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 \
60 | grep 'number:' | awk '{{ print $2 }}')" || true
61 # add project if it is the first with patches or it is not the first
62 if [[ -z "${PATCHES_TO_BUILD}" && -n "${GERRIT_PATCH_LIST[*]}" ]]; then
63 PATCHES_TO_BUILD="${PROJECT}"
64 elif [[ -n "${PATCHES_TO_BUILD}" ]]; then
65 if [[ -n "${GERRIT_PATCH_LIST[*]}" ]]; then
66 echo "Add ${PROJECT}:${DISTRIBUTION_BRANCH_TO_BUILD}"
68 PATCHES_TO_BUILD="${PATCHES_TO_BUILD},${PROJECT}"
70 # sort project patches
71 if [[ -n "${GERRIT_PATCH_LIST[*]}" ]]; then
72 echo "Add ${PROJECT}:${GERRIT_PATCH_LIST[*]}"
74 # create reference list with patch number-refspec
75 for PATCH in "${GERRIT_PATCH_LIST[@]}"; do
76 REFSPEC=$(ssh -p 29418 "jenkins-$SILO@git.opendaylight.org" gerrit query "change:${PATCH}" --current-patch-set \
77 | grep 'ref:' | awk '{{ print $2 }}')
78 REF_LIST+=("${PATCH}-${REFSPEC/refs\/changes\/}")
80 # sort reference list by patch number
81 IFS=$'\n' SORT_REF=$(sort <<<"${REF_LIST[*]}") && unset IFS
82 read -rd '' -a SORT_REF_LIST <<< "${SORT_REF[*]}" || true
83 # add refspec to patches to build list
85 for PATCH in "${SORT_REF_LIST[@]}"; do
87 if [ "${COUNT}" == "1" ] && [ "${CHERRY_PICK}" == "false" ]; then
89 PATCHES_TO_BUILD="${PATCHES_TO_BUILD}=${PATCH/*-/}"
91 # cherry-pick is better than checkout patch
92 PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}"
98 echo "Patches to build: ${PATCHES_TO_BUILD}"
99 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
101 # First phase: clone the necessary repos and set the patches up
106 # 1. Clone the project.
107 # 2. Checkout an specific (typically unmerged) Gerrit patch. If none,
108 # use distribution pom.xml file to figure out right branch or tag to checkout.
109 # In case of Gerrit patch in MRI project, adjust version for the stream.
110 # 3. Optionally, cherry-pick series of patches on top of the checkout.
112 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
113 # list of project[=checkout][:cherry-pick]* values. Examples:
115 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
116 # PATCHES_TO_BUILD='odlparent=45/30045/2'
118 # Checkout patches for both odlparent and yangtools:
119 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
121 # Checkout a patch for controller, cherry-pick another patch on top of it:
122 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
123 distribution_status="not_included"
124 for patch in "${PATCHES[@]}"
126 echo "-- working on ${patch} --"
127 # For patch=controller=61/29761/5:45/29645/6, this gives controller.
128 PROJECT="$(echo "${patch}" | cut -d':' -f 1 | cut -d'=' -f 1)"
129 if [ "${PROJECT}" == "integration/distribution" ]; then
130 distribution_status="included"
132 PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500
133 PROJECTS+=("${PROJECT_SHORTNAME}")
134 echo "1. cloning project ${PROJECT}"
135 git clone "https://git.opendaylight.org/gerrit/${PROJECT}"
136 cd "${PROJECT_SHORTNAME}"
137 # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5.
138 CHECKOUT="$(echo "${patch}" | cut -d'=' -s -f 2 | cut -d':' -f 1)"
139 # If there is a base patch for this project, checkout patch, otherwise use
140 # distribution pom.xml file to figure out right branch or tag to checkout.
141 if [ "x${CHECKOUT}" != "x" ]; then
142 echo "2. checking out patch ${CHECKOUT}"
143 # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
144 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
145 git checkout FETCH_HEAD
146 # If the patch is for MRI project, adjust the MRI versions
147 # shellcheck disable=SC2235
148 if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
149 ODLPARENT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:odlparent.version ../pom.xml)"
150 echo "change odlparent version to ${ODLPARENT_VERSION}"
151 find . -name "pom.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:parent/x:groupId=\"org.opendaylight.odlparent\"\] -v "${ODLPARENT_VERSION}"
152 find . -name "pom.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}"
154 # shellcheck disable=SC2235
155 if [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
156 YANGTOOLS_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:yangtools.version ../pom.xml)"
157 echo "change yangtools version to ${YANGTOOLS_VERSION}"
158 find . -name "pom.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:parent/x:groupId=\"org.opendaylight.yangtools\"\] -v "${YANGTOOLS_VERSION}"
159 find . -name "pom.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}"
161 if [ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]; then
162 MDSAL_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:mdsal.version ../pom.xml)"
163 echo "change mdsal version to ${MDSAL_VERSION}"
164 find . -name "pom.xml" -print0 | xargs -0 xmlstarlet ed --inplace -P -N x=http://maven.apache.org/POM/4.0.0 -u //x:version\[../x:parent/x:groupId=\"org.opendaylight.mdsal\"\] -v "${MDSAL_VERSION}"
165 find . -name "pom.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}"
168 # If project with no patch is MRI, download release tag:
169 # shellcheck disable=SC2235
170 if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then
171 # shellcheck disable=SC2086
172 PROJECT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:${PROJECT_SHORTNAME}.version ../pom.xml)"
173 echo "2. checking out tag v${PROJECT_VERSION}"
174 git checkout "tags/v${PROJECT_VERSION}"
175 # Otherwise download distribution branch:
177 echo "2. checking out branch ${DISTRIBUTION_BRANCH_TO_BUILD}"
178 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
181 # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
182 PICK_SEGMENT="$(echo "${patch}" | cut -d: -s -f 2-)"
183 IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
184 for pick in "${PICKS[@]}"
186 echo "3. cherry-picking ${pick}"
187 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
188 git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
193 # Finally add distribution if there is no int/dist patch
194 if [ "${distribution_status}" == "not_included" ]; then
195 echo "adding integration/distribution"
196 PROJECTS+=(distribution)
197 # clone distribution and add it as a module in root pom
198 git clone "https://git.opendaylight.org/gerrit/integration/distribution"
200 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
204 # Second phase: build everything
206 for PROJECT_SHORTNAME in "${PROJECTS[@]}"; do
207 # Set Fast build if project is not in BUILD_NORMAL and BUILD_FAST is true
208 if [[ "${BUILD_NORMAL}" != *"${PROJECT_SHORTNAME}"* ]] && ${BUILD_FAST}; then
213 pushd "${PROJECT_SHORTNAME}"
215 # shellcheck disable=SC2086
216 "$MVN" clean install \
218 -Dstream="$DISTROSTREAM" \
220 -Dmaven.gitcommitid.skip=false \
221 --global-settings "$GLOBAL_SETTINGS_FILE" \
222 --settings "$SETTINGS_FILE" \
224 # Since we've installed the artifacts, we can clean the build and save disk space
225 # shellcheck disable=SC2086
228 -Dstream="$DISTROSTREAM" \
230 -Dmaven.gitcommitid.skip=false \
231 --global-settings "$GLOBAL_SETTINGS_FILE" \
232 --settings "$SETTINGS_FILE" \