Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Trigger the build of a debian package for a Git SCM project via Jenkins CI
# 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 <>
# 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 ]
echo "Release request not Found" && exit 0;
# Make sure we have a Job name ( Comes from Jenkins CI)
if [ -z "$JOB_NAME" ]
echo "Job Name not provided" && exit 1;
# 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
# 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}" ]
rm -fR "${PACKAGE_PATH}"
# 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" ]
rm "${PACKAGE_PATH}/build.xml"
# 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
Something went wrong with that request. Please try again.