X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=jjb%2Fintegration%2Fmultipatch-distribution.sh;h=eac630698ebbee1b5c047085159e3a2489e55868;hb=HEAD;hp=682d0e301cc15eef286545a61ed287748ca9889b;hpb=807fca79b9cbd070495690797e1b0cc019caf5f9;p=releng%2Fbuilder.git diff --git a/jjb/integration/multipatch-distribution.sh b/jjb/integration/multipatch-distribution.sh index 682d0e301..92cc1e1c3 100755 --- a/jjb/integration/multipatch-distribution.sh +++ b/jjb/integration/multipatch-distribution.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex # create a fresh empty place to build this custom distribution BUILD_DIR=${WORKSPACE}/patch_tester @@ -13,21 +13,24 @@ MAVEN_OPTIONS="${MAVEN_PARAMS} \ -Dmaven.repo.local=/tmp/r \ -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r" -rm -rf $BUILD_DIR -mkdir -p $BUILD_DIR -cd $BUILD_DIR +rm -rf "$BUILD_DIR" +mkdir -p "$BUILD_DIR" +cd "$BUILD_DIR" # Download distribution pom.xml -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" +wget "https://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" cat pom.xml # Set up git committer name and email, needed for commit creation when cherry-picking. -export EMAIL="sandbox@jenkins.opendaylight.org" +export EMAIL="jenkins-$SILO@opendaylight.org" export GIT_COMMITTER_NAME="Multipatch Job" # Extract a list of patches per project from an comment trigger. An example is: # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then + # Decode Base64 before parsing text. + GERRIT_EVENT_COMMENT_TEXT=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | base64 -d) + if [[ "$GERRIT_EVENT_COMMENT_TEXT" == *fast* ]]; then BUILD_FAST="true" PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build-fast:') @@ -37,38 +40,43 @@ if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then fi PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:} fi -if ${BUILD_FAST}; then - fast_option="-Pq" -else - fast_option="" -fi -# check if topic exists, e.g. topic=binding-tlc-rpc -if [[ "${PATCHES_TO_BUILD}" == *topic* ]]; then - TOPIC="${PATCHES_TO_BUILD#*=}" +# check if topic exists: +# if topic=binding-rpc, then checkout first patch in binding-rpc topic (if it exists) +# if topic:binding-rpc, then cherry-pick first patch in binding-rpc topic (if it exists) +if [[ "${PATCHES_TO_BUILD}" == *"topic"* ]]; then + if [[ "${PATCHES_TO_BUILD}" == *"topic="* ]]; then + CHERRY_PICK="false" + TOPIC="${PATCHES_TO_BUILD#*=}" + elif [[ "${PATCHES_TO_BUILD}" == *"topic:"* ]]; then + CHERRY_PICK="true" + TOPIC="${PATCHES_TO_BUILD#*:}" + else + echo "ERROR: Topic has wrong format" && exit 1 + fi echo "Create topic ${TOPIC} patch list" PATCHES_TO_BUILD="" read -ra PROJECT_LIST <<< "${BUILD_ORDER}" echo "List of projects to check patch in topic: ${PROJECT_LIST[*]}" for PROJECT in "${PROJECT_LIST[@]}"; do # get all patches number for a topic for a given project - 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 \ + 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 \ | grep 'number:' | awk '{{ print $2 }}')" || true # add project if it is the first with patches or it is not the first - if [[ -z "${PATCHES_TO_BUILD}" && ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then + if [[ -z "${PATCHES_TO_BUILD}" && -n "${GERRIT_PATCH_LIST[*]}" ]]; then PATCHES_TO_BUILD="${PROJECT}" - elif [[ ! -z "${PATCHES_TO_BUILD}" ]]; then - if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then + elif [[ -n "${PATCHES_TO_BUILD}" ]]; then + if [[ -n "${GERRIT_PATCH_LIST[*]}" ]]; then echo "Add ${PROJECT}:${DISTRIBUTION_BRANCH_TO_BUILD}" fi PATCHES_TO_BUILD="${PATCHES_TO_BUILD},${PROJECT}" fi # sort project patches - if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then + if [[ -n "${GERRIT_PATCH_LIST[*]}" ]]; then echo "Add ${PROJECT}:${GERRIT_PATCH_LIST[*]}" REF_LIST=() # create reference list with patch number-refspec for PATCH in "${GERRIT_PATCH_LIST[@]}"; do - REFSPEC=$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query change:${PATCH} --current-patch-set \ + REFSPEC=$(ssh -p 29418 "jenkins-$SILO@git.opendaylight.org" gerrit query "change:${PATCH}" --current-patch-set \ | grep 'ref:' | awk '{{ print $2 }}') REF_LIST+=("${PATCH}-${REFSPEC/refs\/changes\/}") done @@ -76,9 +84,16 @@ if [[ "${PATCHES_TO_BUILD}" == *topic* ]]; then IFS=$'\n' SORT_REF=$(sort <<<"${REF_LIST[*]}") && unset IFS read -rd '' -a SORT_REF_LIST <<< "${SORT_REF[*]}" || true # add refspec to patches to build list + COUNT=0 for PATCH in "${SORT_REF_LIST[@]}"; do - # cherry-pick is better than checkout patch - PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}" + COUNT=$((COUNT+1)) + if [ "${COUNT}" == "1" ] && [ "${CHERRY_PICK}" == "false" ]; then + # checkout patch + PATCHES_TO_BUILD="${PATCHES_TO_BUILD}=${PATCH/*-/}" + else + # cherry-pick is better than checkout patch + PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}" + fi done fi done @@ -113,17 +128,17 @@ for patch in "${PATCHES[@]}" do echo "-- working on ${patch} --" # For patch=controller=61/29761/5:45/29645/6, this gives controller. - PROJECT="$(echo ${patch} | cut -d\: -f 1 | cut -d\= -f 1)" + PROJECT="$(echo "${patch}" | cut -d':' -f 1 | cut -d'=' -f 1)" if [ "${PROJECT}" == "integration/distribution" ]; then distribution_status="included" fi PROJECT_SHORTNAME="${PROJECT##*/}" # http://stackoverflow.com/a/3162500 PROJECTS+=("${PROJECT_SHORTNAME}") echo "1. cloning project ${PROJECT}" - git clone "https://git.opendaylight.org/gerrit/p/${PROJECT}" - cd ${PROJECT_SHORTNAME} + git clone "https://git.opendaylight.org/gerrit/${PROJECT}" + cd "${PROJECT_SHORTNAME}" # For patch = controller=61/29761/5:45/29645/6, this gives 61/29761/5. - CHECKOUT="$(echo ${patch} | cut -d\= -s -f 2 | cut -d\: -f 1)" + CHECKOUT="$(echo "${patch}" | cut -d'=' -s -f 2 | cut -d':' -f 1)" # If there is a base patch for this project, checkout patch, otherwise use # distribution pom.xml file to figure out right branch or tag to checkout. if [ "x${CHECKOUT}" != "x" ]; then @@ -132,27 +147,41 @@ do git fetch "https://git.opendaylight.org/gerrit/${PROJECT}" "refs/changes/$CHECKOUT" git checkout FETCH_HEAD # If the patch is for MRI project, adjust the MRI versions - if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then + # shellcheck disable=SC2235 + if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || [ "${PROJECT}" == "mdsal" ] || ([ "${PROJECT}" == "controller" ] && [ "${DISTROSTREAM}" != "magnesium" ]); then ODLPARENT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:odlparent.version ../pom.xml)" echo "change odlparent version to ${ODLPARENT_VERSION}" - 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 + 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}" + 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}" fi - if [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then + # shellcheck disable=SC2235 + if [ "${PROJECT}" == "yangtools" ] || [ "${PROJECT}" == "mdsal" ] || ([ "${PROJECT}" == "controller" ] && [ "${DISTROSTREAM}" != "magnesium" ]); then YANGTOOLS_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:yangtools.version ../pom.xml)" echo "change yangtools version to ${YANGTOOLS_VERSION}" - 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 + 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}" + 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}" fi - if [ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]; then + # shellcheck disable=SC2235 + if [ "${PROJECT}" == "mdsal" ] || ([ "${PROJECT}" == "controller" ] && [ "${DISTROSTREAM}" != "magnesium" ]); then MDSAL_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:mdsal.version ../pom.xml)" echo "change mdsal version to ${MDSAL_VERSION}" - 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 + 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}" + 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}" + fi + if [ "${PROJECT}" == "controller" ] && [ "${DISTROSTREAM}" != "magnesium" ]; then + CONTROLLER_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:controller.version ../pom.xml)" + echo "change controller version to ${CONTROLLER_VERSION}" + 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.controller\"\] -v "${CONTROLLER_VERSION}" + 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.controller\"\] -v "${CONTROLLER_VERSION}" fi else # If project with no patch is MRI, download release tag: - if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || ([ "${PROJECT}" == "mdsal" ] && [ "${DISTROSTREAM}" != "fluorine" ]); then + # shellcheck disable=SC2235 + if [ "${PROJECT}" == "odlparent" ] || [ "${PROJECT}" == "yangtools" ] || [ "${PROJECT}" == "mdsal" ] || ([ "${PROJECT}" == "controller" ] && [ "${DISTROSTREAM}" != "magnesium" ]); then + # shellcheck disable=SC2086 PROJECT_VERSION="$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v //x:${PROJECT_SHORTNAME}.version ../pom.xml)" echo "2. checking out tag v${PROJECT_VERSION}" - git checkout tags/v${PROJECT_VERSION} + git checkout "tags/v${PROJECT_VERSION}" # Otherwise download distribution branch: else echo "2. checking out branch ${DISTRIBUTION_BRANCH_TO_BUILD}" @@ -160,7 +189,7 @@ do fi fi # For patch=controller=61/29761/5:45/29645/6, this gives 45/29645/6 - PICK_SEGMENT="$(echo "${patch}" | cut -d\: -s -f 2-)" + PICK_SEGMENT="$(echo "${patch}" | cut -d: -s -f 2-)" IFS=':' read -ra PICKS <<< "${PICK_SEGMENT}" for pick in "${PICKS[@]}" do @@ -176,7 +205,7 @@ if [ "${distribution_status}" == "not_included" ]; then echo "adding integration/distribution" PROJECTS+=(distribution) # clone distribution and add it as a module in root pom - git clone "https://git.opendaylight.org/gerrit/p/integration/distribution" + git clone "https://git.opendaylight.org/gerrit/integration/distribution" cd distribution git checkout "${DISTRIBUTION_BRANCH_TO_BUILD}" cd "${BUILD_DIR}" @@ -185,26 +214,32 @@ fi # Second phase: build everything for PROJECT_SHORTNAME in "${PROJECTS[@]}"; do + # Set Fast build if project is not in BUILD_NORMAL and BUILD_FAST is true + if [[ "${BUILD_NORMAL}" != *"${PROJECT_SHORTNAME}"* ]] && ${BUILD_FAST}; then + fast_option="-Pq" + else + fast_option="" + fi pushd "${PROJECT_SHORTNAME}" - # Build project - "$MVN" clean install \ - -e ${fast_option} \ - -Dstream="$DISTROSTREAM" \ - -Dgitid.skip=false \ - -Dmaven.gitcommitid.skip=false \ - --global-settings "$GLOBAL_SETTINGS_FILE" \ - --settings "$SETTINGS_FILE" \ - $MAVEN_OPTIONS - # Since we've installed the artifacts, we can clean the build and save - # disk space - "$MVN" clean \ - -e ${fast_option} \ - -Dstream="$DISTROSTREAM" \ - -Dgitid.skip=false \ - -Dmaven.gitcommitid.skip=false \ - --global-settings "$GLOBAL_SETTINGS_FILE" \ - --settings "$SETTINGS_FILE" \ - $MAVEN_OPTIONS + # Build project + # shellcheck disable=SC2086 + "$MVN" clean install \ + -e ${fast_option} \ + -Dstream="$DISTROSTREAM" \ + -Dgitid.skip=false \ + -Dmaven.gitcommitid.skip=false \ + --global-settings "$GLOBAL_SETTINGS_FILE" \ + --settings "$SETTINGS_FILE" \ + $MAVEN_OPTIONS + # Since we've installed the artifacts, we can clean the build and save disk space + # shellcheck disable=SC2086 + "$MVN" clean \ + -e ${fast_option} \ + -Dstream="$DISTROSTREAM" \ + -Dgitid.skip=false \ + -Dmaven.gitcommitid.skip=false \ + --global-settings "$GLOBAL_SETTINGS_FILE" \ + --settings "$SETTINGS_FILE" \ + $MAVEN_OPTIONS popd done -