/usr/bin/generate-svn-snapshot is in jenkins-debian-glue 0.18.4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #!/bin/bash
if [ -z ${JENKINS_DEBIAN_GLUE_QUIET:-} ]; then
set -x
fi
set -e
set -u
export LC_ALL=C
export LANG=C
if [ -r /etc/jenkins/debian_glue ] ; then
. /etc/jenkins/debian_glue
fi
[ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins-debian-glue Autobuilder <jenkins@`hostname -f`>"
export DEBEMAIL
if [ ! -d source ] ; then
echo "Please run the script in the jenkins workspace." >&2
echo 'NOTE: Make sure to set the "Local module directory (optional)" option in the Subversion configuration to "source"' >&2
exit 1
fi
if [ -z "${BUILD_NUMBER:-}" ] ; then
echo "No BUILD_NUMBER defined, please run it in jenkins." >&2
exit 1
fi
if [ -z "${SVN_REVISION:-}" ] ; then
echo "No SVN_REVISION defined, please run it with a subversion repository." >&2
exit 1
fi
if ! [ -x "$(which svn2cl)" ] ; then
echo "Error: svn2cl not available, please install subversion-tools <= 1.6.18dfsg-1 or svn2cl." >&2
exit 1
fi
if ! [ -x "$(which svn)" ] ; then
echo "Error: svn not available, please install subversion." >&2
exit 1
fi
if ! [ -x "$(which dpkg-parsechangelog)" ] ; then
echo "Error: dpkg-parsechangelog not available, please install dpkg-dev." >&2
exit 1
fi
JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
fi
echo "*** source package build phase ***"
rm -f ./* || true
ORIG_DIR=$(pwd)
cd source/${branch:-}
if ! [ -r debian/changelog ] ; then
echo "Error: could not find debian/changelog (not a Debian package or wrong tag/branch?)" >&2
exit 1
fi
# Force the upgrade if subversion 1.7 (which introduced the upgrade command) or
# later is available. Otherwise, if the system has been upgraded, the 'svn info'
# will fail with an unhelpful error message
SVN_VERSION="$(svn --version | awk '/, version / {print $3}')"
if dpkg --compare-versions "$SVN_VERSION" ge 1.7 ; then
echo "*** Executing 'svn upgrade' to make sure svn is up2date ***"
svn upgrade
fi
SINCE_REVISION=$(svn info debian/changelog 2>/dev/null | awk '/Last Changed Rev:/ {print $4}')
if [ -z "${SINCE_REVISION:-}" ] ; then
echo "Error: could not detect svn revision which modified debian/changelog." >&2
exit 1
fi
# required for dpkg-parsechangelog
if ! [ -r debian/changelog ] ; then
echo "Error: debian/changelog could not be read. Is this really a Debian package?" >&2
exit 1
fi
# package name
PACKAGE=$(dpkg-parsechangelog --count 1 | awk '/^Source: / {print $2}')
# get newest version number from changelog
PREVIOUS_VERSION=$(dpkg-parsechangelog --count 1 | awk '/^Version: / {print $2}')
build_snapshot() {
DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
if [ -n "${TIMESTAMP_FORMAT:-}" ] ; then
echo "*** Using custom timestamp format as specified by TIMESTAMP_FORMAT ***"
TIMESTAMP="$(date -u +"$TIMESTAMP_FORMAT")"
else
TIMESTAMP="$(date -u +%Y%m%d%H%M%S)"
fi
if [ "$DISTRIBUTION" = "UNRELEASED" ] ; then
# we do NOT raise the version number, if we detect an unreleased version
SNAPSHOT_VERSION="${PREVIOUS_VERSION}~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
else
# calculate new snapshot version
SNAPSHOT_VERSION="$(increase-version-number "$PREVIOUS_VERSION")~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
fi
# generate changelog
SVN_CHANGELOG_ORIG=$(mktemp)
SVN_CHANGELOG_EDIT=$(mktemp)
# build GNU like changelog with svn2cl as helper tool
# timeout after 15 seconds without progress, we might be running into e.g.
# "xsltApplyXSLTTemplate: A potential infinite template recursion was detected."
if ! timeout -k 16 16 svn2cl --reparagraph --stdout --include-rev -r HEAD:$SINCE_REVISION > "$SVN_CHANGELOG_ORIG" ; then
echo ' * Sorry, generating changelog using svn2cl failed. :(
Make sure the svn2cl command works on the jenkins host.
For example validating server certificates is a common error.
' > "$SVN_CHANGELOG_ORIG"
fi
## disclaimer: use separate sed calls to make it easier to adjust if necessary
# reduce changelog to just the first line of the commit message
sed -n '/^\t*\s*\* \[r/,/^\t*\s*$/p' "$SVN_CHANGELOG_ORIG" > "$SVN_CHANGELOG_EDIT"
# get rid of author information that might be present from git-svn users
sed -i '/^\t\s\sFrom: /d' "$SVN_CHANGELOG_EDIT"
# replace tabs at beginning of lines with two spaces
sed -i 's/^\t/ /' "$SVN_CHANGELOG_EDIT"
# get rid of lines with just 4 space chars only
sed -i '/^ $/d' "$SVN_CHANGELOG_EDIT"
# get rid of empty lines
sed -i '/^$/d' "$SVN_CHANGELOG_EDIT"
# get rid of of the timestamp lines, looking like:
# 2011-12-02 21:25 mprokop
sed -ri '/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}/d' "$SVN_CHANGELOG_EDIT"
cat > debian/changelog.new << EOF
$PACKAGE ($SNAPSHOT_VERSION) UNRELEASED; urgency=low
** SNAPSHOT build **
EOF
cat "$SVN_CHANGELOG_EDIT" >> debian/changelog.new
cat >> debian/changelog.new << EOF
-- $DEBEMAIL $(date -u -R)
EOF
# append original changelog
cat debian/changelog >> debian/changelog.new
# finally install new changelog
mv debian/changelog.new debian/changelog
rm -f "$SVN_CHANGELOG_ORIG" "$SVN_CHANGELOG_EDIT"
}
case "${branch:-}" in
tags/*) echo "Building a tag version, not modifying the package" ;;
*) build_snapshot;;
esac
cd $ORIG_DIR
# subversion >=1.9 fails hard, see github issue #164
debian_only="$(svn propget mergeWithUpstream source/${branch:-}/debian || true)"
if [ -n "${SBP_OPTS:-}" ] ; then
echo "*** Found environment variable SBP_OPTS, set to ${SBP_OPTS} ***"
else
echo "*** Using svn-buildpackage default options provided by jenkins-debian-glue ***"
SBP_OPTS="-nc --svn-download-orig -S --svn-builder dpkg-buildpackage -d --svn-move-to=${ORIG_DIR} --svn-dont-purge -uc -us --svn-ignore-new -rfakeroot"
fi
if [ "${debian_only:-}" = "1" ] ; then
(
cd "source/${branch:-}"
echo "mergeWithUpstream detected, using svn-buildpackage to create source package"
svn-buildpackage ${SBP_OPTS:-}
)
else
if [ -n "${PRE_SOURCE_HOOK:-}" ] ; then
echo "*** Found environment variable PRE_SOURCE_HOOK, set to ${PRE_SOURCE_HOOK:-} ***"
sh ${PRE_SOURCE_HOOK:-}
fi
dpkg-source --tar-ignore=\.svn -b "source/${branch:-}"
(
if [ -n "${SNAPSHOT_VERSION:-}" ] ; then
CHANGES_FILE="${ORIG_DIR}/${PACKAGE}_${SNAPSHOT_VERSION}_source.changes"
else
CHANGES_FILE="${ORIG_DIR}/${PACKAGE}_${PREVIOUS_VERSION}_source.changes"
fi
cd "source/${branch:-}"
dpkg-genchanges -S -u"${ORIG_DIR}" > "${CHANGES_FILE}"
)
fi
if [ -n "${KEY_ID:-}" ] ; then
echo "*** Found environment variable KEY_ID, set to ${KEY_ID:-}, signing source package ***"
if ! [ -x "$(which debsign)" ] ; then
echo "Error: debsign not available, please make sure the devscripts package is installed." >&2
exit 1
fi
debsign -k"${KEY_ID:-}" *_source.changes
fi
# revert to original debian/changelog to avoid highly increasing version numbers with each build
( cd source/${branch:-} ; svn revert debian/changelog )
# vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2
|