# maven_post_build_debian_wrapper.sh
#
# this script is run after maven for maven build jobs
-# it updates debian/changelog, builds the debian package(s) and uploads to our repo.
-#
-
-function cleanup {
- echo cleaning up ...
- # revert changelog changes
- git checkout -- debian/changelog
- # remove files created by debian build
- git clean -fd debian
- echo cleanup done
-}
-
-function validateSettings {
- REPO=pb-${SUITE}
- VERSION=$(mvn -B -N help:evaluate -Dexpression=project.version 2>/dev/null| grep -v "^\[" | grep -v "^D" )
- if [[ -z "${VERSION}" ]]; then
- echo "ERROR: Cannot get version from maven using 'mvn -B -N help:evaluate -Dexpression=project.version'"
- mvn -B -N help:evaluate -Dexpression=project.version
- exit 1
- fi
-
- if [[ "$GIT_BRANCH_NAME" = "integration" ]] || [[ ${GIT_BRANCH_NAME:0:8} = "feature/" ]] || [[ ${GIT_BRANCH_NAME:0:3} = "poc/" ]] || [[ ${GIT_BRANCH_NAME:0:7} = "bugfix/" ]]; then
- APPEND_TO_VERSION="experimental"
- REPO="dev-${SUITE}"
- if [[ "$GIT_BRANCH_NAME" = "integration" ]]; then
- DISTRIBUTION="dev-integration"
- else
- # set proper DISTRIBUTION for feature branches
- DISTRIBUTION=$(echo "dev-${GIT_BRANCH_NAME}" | tr '/' '-')
- fi
- elif [[ "$GIT_BRANCH_NAME" = "master" ]] || [[ ${GIT_BRANCH_NAME:0:7} = "hotfix/" ]]; then
- APPEND_TO_VERSION=""
- DISTRIBUTION="production-proposed-updates"
- else
- DISTRIBUTION="unstable"
- APPEND_TO_VERSION="develop"
- fi
-
- if [[ ! -z "$APPEND_TO_VERSION" ]]; then
- # remove -SNAPSHOT
- VERSION=$(echo $VERSION | sed -s "s#-SNAPSHOT##g")
- BUILD_START=$(date +%Y%m%d%H%M%S)
- VERSION="${VERSION}~${APPEND_TO_VERSION}${BUILD_START}+${BUILD_NUMBER}+g${GIT_COMMIT:0:7}"
- fi
-
- SOURCE=$(dpkg-parsechangelog 2>/dev/null|grep ^Source:|cut -d " " -f2) # get the name of the source package
- echo "About to start to build the debian packages:"
- echo "============================================"
- echo "$SOURCE $VERSION" "$DISTRIBUTION"
- echo "============================================"
-}
-
-function doDebianPackaging {
- if [[ -d "$WORKSPACE/debian" ]]; then
- return 1
- else
- return 0
- fi
-}
#############
# MAIN
#############
-SUITE=$1 # this has to be either squeeze or wheezy currently
-
-if [[ doDebianPackaging ]]; then
- if [[ -z "${SUITE}" ]]; then
- SUITE="squeeze"
- echo "Warning: SUITE not defined, defaulting to \"squeeze\"."
- fi
-fi
-
cd $WORKSPACE
-if [[ doDebianPackaging ]]; then
- validateSettings
-else
- echo "No debian folder detected, skipping handling"
-fi
-
export
set -e # fail on error
set -x # echo commands executed
-if [[ doDebianPackaging ]]; then
- # write correct debian/changelog
- if [[ "$GIT_BRANCH_NAME" = "master" ]] || [[ "${GIT_BRANCH_NAME:0:7}" = "hotfix/" ]]; then
- # generate debian/changelog entries since the last upload
- git-dch -a --ignore-branch --no-full --no-meta --id-length=7 -N $VERSION
- # make sure distribution in changelog is set correctly
- # (read the comments for the sed command 5 lines below to understand this)
- sed -i "0,/).*\$/s//) $DISTRIBUTION; urgency=low/" debian/changelog
- else
- # change version in changelog
- dch -i --no-auto-nmu "Generated by jenkins"
- git-dch -a --ignore-branch --no-full --no-meta --id-length=7
- # replace first occurance of a version (enclosed in brackets) with real version
- # (we cannot use (git-)dch as the version might be lower than the last),
- # and also set distribution here.
- # sed explained: look for the first occurance of (.*).*$ - so thats something
- # in brackets until the end of the line. = first line of a debian/changelog
- sed -i "0,/(.*).*\$/s//($VERSION) $DISTRIBUTION; urgency=low/" debian/changelog
- fi
- # check that we replaced things correctly...
- D=$(dpkg-parsechangelog 2>/dev/null|grep ^Distribution:|cut -d " " -f2)
- if [[ "$D" != "$DISTRIBUTION" ]]; then
- figlet "Wrong distribution!"
- dpkg-parsechangelog
- exit 1
- fi
- figlet "$DISTRIBUTION"
-
- # build debian package (just binary, no source package)
- dpkg-buildpackage -us -uc -b
-
- # upload to reprepro
- CHANGES_FILE=${SOURCE}_${VERSION}_amd64.changes
- cd $WORKSPACE/..
- # upload
- dcmd scp $CHANGES_FILE reprepro@alexandria.pb.local:/srv/$REPO/incoming/profitbricks/
- ssh reprepro@alexandria.pb.local /srv/$REPO/bin/pb_processincoming
- figlet "Uploaded."
- # cleanup
- dcmd rm $CHANGES_FILE
- cd $WORKSPACE
-
- # push back to git repo if build from master or hotfix/
- if [[ "$GIT_BRANCH_NAME" = "master" ]] || [[ "${GIT_BRANCH_NAME:0:7}" = "hotfix/" ]]; then
- git add debian/changelog
- git commit -m "[no-jenkins] trigger - automatic commit by jenkins after build of $BUILD_NUMBER"
- # ~ and : are not valid in git tags, replace them:
- TAG=$(echo $VERSION | tr '~' '_' | tr ':' ',')
- git tag $TAG
- git push origin $GIT_BRANCH_NAME
- git push origin $TAG
- figlet "Tagged."
- fi
-
- # show the changelog
- dpkg-parsechangelog
-
- # call cleanup function
- cleanup
-fi
-
# push back integration branch if we merged a feature branch
if [[ ${GIT_BRANCH_NAME:0:8} = "feature/" ]] || [[ ${GIT_BRANCH_NAME:0:7} = "bugfix/" ]]; then
if [[ "$BUILD_TRIGGERS" = *"merge"* ]]; then