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="$(echo --show-version \
11 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
12 -Dmaven.repo.local=/tmp/r \
13 -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)"
19 # Set up git committer name and email, needed for commit creation when cherry-picking.
20 export EMAIL="sandbox@jenkins.opendaylight.org"
21 export GIT_COMMITTER_NAME="Multipatch Job"
23 # Extract a list of patches per project from an comment trigger. An example is:
24 # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1
25 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
26 if [[ "$GERRIT_EVENT_COMMENT_TEXT" == *fast* ]]; then
28 PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build-fast:')
31 PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
33 PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:}
35 if ${BUILD_FAST}; then
40 # check if topic exists, e.g. topic=binding-tlc-rpc
41 if [[ "${PATCHES_TO_BUILD}" == *topic* ]]; then
42 TOPIC="${PATCHES_TO_BUILD#*=}"
43 echo "Create topic ${TOPIC} patch list"
45 read -ra PROJECT_LIST <<< "${BUILD_ORDER}"
46 echo "List of projects to check patch in topic: ${PROJECT_LIST[*]}"
47 for PROJECT in "${PROJECT_LIST[@]}"; do
48 # get all patches number for a topic for a given project
49 IFS=$'\n' read -rd '' -a GERRIT_PATCH_LIST <<< "$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query status:open topic:${TOPIC} project:${PROJECT} \
50 | grep 'number:' | awk '{{ print $2 }}')" || true
51 # add project if it is the first with patches or it is not the first
52 if [[ -z "${PATCHES_TO_BUILD}" && ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
53 PATCHES_TO_BUILD="${PROJECT}"
54 elif [[ ! -z "${PATCHES_TO_BUILD}" ]]; then
55 if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
56 echo "Add ${PROJECT}:${DISTRIBUTION_BRANCH_TO_BUILD}"
58 PATCHES_TO_BUILD="${PATCHES_TO_BUILD},${PROJECT}"
60 # sort project patches
61 if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
62 echo "Add ${PROJECT}:${GERRIT_PATCH_LIST[*]}"
64 # create reference list with patch number-refspec
65 for PATCH in "${GERRIT_PATCH_LIST[@]}"; do
66 REFSPEC=$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query change:${PATCH} --current-patch-set \
67 | grep 'ref:' | awk '{{ print $2 }}')
68 REF_LIST+=("${PATCH}-${REFSPEC/refs\/changes\/}")
70 # sort reference list by patch number
71 IFS=$'\n' SORT_REF=$(sort <<<"${REF_LIST[*]}") && unset IFS
72 read -rd '' -a SORT_REF_LIST <<< "${SORT_REF[*]}" || true
73 # add refspec to patches to build list
74 for PATCH in "${SORT_REF_LIST[@]}"; do
75 # if project is odlparent or yangtools, do not cherry-pick
76 if [[ "${PROJECT}" == "odlparent" || "${PROJECT}" == "yangtools" ]]; then
77 PATCHES_TO_BUILD="${PATCHES_TO_BUILD}=${PATCH/*-/}"
79 PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}"
85 echo "Patches to build: ${PATCHES_TO_BUILD}"
86 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
88 # First phase: clone the necessary repos and set the patches up
93 # 1. Clone the project.
94 # 2. Optionally, checkout a specific (typically unmerged) Gerrit patch. If none,
95 # default to Integration/Distribution branch via {branch} JJB param.
96 # 3. Also optionally, cherry-pick series of patches on top of the checkout.
98 # Each patch is found in the ${PATCHES_TO_BUILD} variable as a comma separated
99 # list of project[=checkout][:cherry-pick]* values. Examples:
101 # Checkout a (typically unmerged) Gerrit patch on top of odlparent's git clone:
102 # PATCHES_TO_BUILD='odlparent=45/30045/2'
104 # Checkout patches for both odlparent and yangtools:
105 # PATCHES_TO_BUILD='odlparent=45/30045/2,yangtools:53/26853/25'
107 # Checkout a patch for controller, cherry-pick another patch on top of it:
108 # PATCHES_TO_BUILD='controller=61/29761/5:45/29645/6'
109 distribution_status="not_included"
110 for patch in "${PATCHES[@]}"
112 echo "working on ${patch}"
113 # For patch=controller=61/29761/5:45/29645/6, this gives controller
114 PROJECT="$(echo ${patch} | cut -d\: -f 1 | cut -d\= -f 1)"
115 if [ "${PROJECT}" == "integration/distribution" ]; then
116 distribution_status="included"
118 PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500
119 PROJECTS+=("${PROJECT_SHORTNAME}")
120 echo "cloning project ${PROJECT}"
121 git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}"
122 cd ${PROJECT_SHORTNAME}
123 # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5
124 CHECKOUT="$(echo ${patch} | cut -d\= -s -f 2 | cut -d\: -f 1)"
125 # If project has a patch, checkout patch, otherwise use distribution branch
126 if [ "x${CHECKOUT}" != "x" ]; then
127 echo "checking out ${CHECKOUT}"
128 # TODO: Make this script accept "29645/6" as a shorthand for "45/29645/6".
129 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT"
130 git checkout FETCH_HEAD
133 # If project with no patch = yangtools, download master branch
134 if [ "${PROJECT}" == "yangtools" ]; then
135 echo "checking out master"
138 echo "checking out ${DISTRIBUTION_BRANCH_TO_BUILD}"
139 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
142 # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6
143 PICK_SEGMENT="$(echo "${patch}" | cut -d\: -s -f 2-)"
144 IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}"
145 for pick in "${PICKS[@]}"
147 echo "cherry-picking ${pick}"
148 git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/${pick}"
149 git cherry-pick --ff --keep-redundant-commits FETCH_HEAD
154 # Finally add distribution if there is no int/dist patch
155 if [ "${distribution_status}" == "not_included" ]; then
156 echo "adding integration/distribution"
157 PROJECTS+=(distribution)
158 # clone distribution and add it as a module in root pom
159 git clone "https://git.opendaylight.org/gerrit/p/integration/distribution"
161 git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}"
165 # If there is a patch for odlparent or yangtools (MRI projects), adjust version to mdsal project:
166 # 1. Extract project version in patch
167 # 2. Extract project MSI version from mdsal project
168 # 3. Replace version in patch by MSI version
169 # Otherwise release the MRI project
170 if [[ -d "odlparent" ]]; then
171 if [[ -d "mdsal" ]]; then
172 # Extract patch and MSI used version
173 patch_version="$(xpath ./odlparent/odlparent-lite/pom.xml '/project/version/text()' 2> /dev/null)"
174 msi_version="$(xpath ./mdsal/pom.xml '/project/parent/version/text()' 2> /dev/null)"
176 find ./odlparent -name "*.xml" -print0 | xargs -0 sed -i "s/${patch_version}/${msi_version}/g"
179 find ./odlparent -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
182 if [[ -d "yangtools" ]]; then
183 if [[ -d "mdsal" ]]; then
184 # Extract patch and MSI used version
185 patch_version="$(xpath ./yangtools/pom.xml '/project/version/text()' 2> /dev/null)"
186 msi_version="$(xpath ./mdsal/binding/yang-binding/pom.xml '/project/dependencyManagement/dependencies/dependency/version/text()' 2> /dev/null)"
188 find ./yangtools -name "*.xml" -print0 | xargs -0 sed -i "s/${patch_version}/${msi_version}/g"
191 find ./yangtools -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
195 # Second phase: build everything
197 for PROJECT_SHORTNAME in "${PROJECTS[@]}"; do
198 pushd "${PROJECT_SHORTNAME}"
200 "$MVN" clean install \
202 -Dstream="$DISTROSTREAM" \
204 -Dmaven.gitcommitid.skip=false \
205 --global-settings "$GLOBAL_SETTINGS_FILE" \
206 --settings "$SETTINGS_FILE" \
208 # Since we've installed the artifacts, we can clean the build and save
212 -Dstream="$DISTROSTREAM" \
214 -Dmaven.gitcommitid.skip=false \
215 --global-settings "$GLOBAL_SETTINGS_FILE" \
216 --settings "$SETTINGS_FILE" \