Skip to content

Instantly share code, notes, and snippets.

@jeffery
Created July 19, 2011 23:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeffery/1093983 to your computer and use it in GitHub Desktop.
Save jeffery/1093983 to your computer and use it in GitHub Desktop.
Trigger the build of a debian package for a Git SCM project via Jenkins CI
#!/bin/bash
#
# This is a helper script to trigger the build of a debian package for a
# project which is in Git SCM and integrated via Jenkins CI
#
# The trigger used for the package build is a string "bump for release"
# which is part of the commit message for the Git repository.
#
# The Changelog is then parsed to obtain the release version and then
# the repository is exported for package building
#
# Author: Jeffery Fernandez <jeffery@fernandez.net.au>
#
# Requires the following Debian packages:
# dpkg-dev debhelper devscripts fakeroot lintian
##
# Extract the last changelog and discard unwanted data
RELEASE_BUMP=`git log --max-count=1 --pretty -- . | grep -v "^Author: " | grep -v "^Date: " | grep -v "^Merge: " | grep -v "^commit"`
# Very if a release was requested
echo $RELEASE_BUMP | grep -i "bump for release" > /dev/null
if [ $? -eq 1 ]
then
echo "Release request not Found" && exit 0;
fi
# Make sure we have a Job name ( Comes from Jenkins CI)
if [ -z "$JOB_NAME" ]
then
echo "Job Name not provided" && exit 1;
fi
# The PWD needs to be the parent to the debian folder inorder to extract the Version to package
VERSION=`dpkg-parsechangelog | awk '/^Version/ {print $2}'`
# Path for building the Debian Package
PACKAGE_PATH="${JOB_NAME}-${VERSION}"
# Obtain the last Git Revision Hash
HASH=`git rev-parse HEAD`
echo "Building: ${VERSION} from Commit: ${HASH}"
# Clean up old Build path, if it exists
if [ -d "${PACKAGE_PATH}" ]
then
rm -fR "${PACKAGE_PATH}"
fi
# Make sure the Exporting directory exists
mkdir -p "${PACKAGE_PATH}"
# Export the revision and Unarchive it into a build folder
git archive ${HASH} | ( cd "${PACKAGE_PATH}" && tar -xf - ) || {
echo "Exporting Git Repository Failed"; exit 1;
}
# Remove any Build Config file, as we don't want to run tests anymore
if [ -f "${PACKAGE_PATH}/build.xml" ]
then
rm "${PACKAGE_PATH}/build.xml"
fi
# Build Package
cd "${PACKAGE_PATH}" && debuild -i -us -uc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment