jenkins: extract common parts of build scripts to separate file

Have all complexity in one common shell script, greatly simplify the individual
scripts.

This allows to provide a specific branch or git hash to build instead of
current master. Some scripts allowed to provide branch names before, this now
also allows using git hashes directly.

Environment variables can be used to override the git hash/branch to use for
specific repositories.

Motivation for this patch: we need this to investigate failure causes more
easily.

Change-Id: I5ac2f90d006a1b2f6c246976346d852a70c89089
diff --git a/contrib/jenkins-build-osmo-nitb.sh b/contrib/jenkins-build-osmo-nitb.sh
index 86d787c..76fd6ba 100755
--- a/contrib/jenkins-build-osmo-nitb.sh
+++ b/contrib/jenkins-build-osmo-nitb.sh
@@ -1,82 +1,15 @@
 #!/bin/sh
 set -e -x
-
 base="$PWD"
-prefix="$base/inst-osmo-nitb"
+name="osmo-nitb"
+. "$(dirname "$0")/jenkins-build-common.sh"
 
-rm -f "$base/osmo-nitb*.tgz"
+build_repo libosmocore
+build_repo libosmo-abis
+build_repo libosmo-netif
+build_repo openggsn
+build_repo libsmpp34
+build_repo libosmo-sccp
+build_repo openbsc --enable-smpp --enable-osmo-bsc --enable-nat
 
-deps="
-libosmocore
-libosmo-abis
-libosmo-netif
-openggsn
-libsmpp34
-libosmo-sccp
-openbsc
-"
-
-have_repo() {
-	repo="$1"
-	cd "$base"
-	if [ ! -d "$repo" ]; then
-		git clone "git://git.osmocom.org/$repo" "$repo"
-	fi
-	cd "$repo"
-	git clean -dxf
-	git fetch origin
-	git reset --hard origin/master
-	git rev-parse HEAD
-	cd "$base"
-}
-
-rm -rf "$prefix"
-mkdir -p "$prefix"
-
-export PKG_CONFIG_PATH="$prefix/lib/pkgconfig"
-export LD_LIBRARY_PATH="$prefix/lib"
-
-for dep in $deps; do
-	set +x; echo "
-
-====================== $dep
-
-"; set -x
-
-	have_repo "$dep"
-	cd "$dep"
-	rm -rf *
-	git checkout .
-
-	echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-nitb_git_hashes.txt"
-
-	config_opts=""
-
-	case "$dep" in
-	'openbsc')
-		config_opts="$config_opts --enable-smpp --enable-osmo-bsc --enable-nat"
-		cd openbsc/
-	;;
-	esac
-
-	autoreconf -fi
-	set +x;	echo; echo; set -x
-	./configure --prefix="$prefix" $config_opts
-	set +x;	echo; echo; set -x
-	make -j8 || make  # libsmpp34 can't build in parallel
-	set +x;	echo; echo; set -x
-	make install
-done
-
-# don't package documentation -- the libosmocore docs can be up to 16 Mb large,
-# a significant amount compared to the binaries
-rm -rf "$prefix/share/doc"
-
-# build the archive that is going to be copied to the tester
-rm "$base"/*.tgz "$base"/*.md5 || true
-cd "$prefix"
-this="osmo-nitb.build-${BUILD_NUMBER}"
-tar="${this}.tgz"
-tar czf "$base/$tar" *
-cd "$base"
-md5sum "$tar" > "${this}.md5"
+create_bin_tgz