-
Notifications
You must be signed in to change notification settings - Fork 16
/
jenkins-rpm-build
executable file
·135 lines (109 loc) · 4.74 KB
/
jenkins-rpm-build
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
#!/bin/bash
#
# $1 = test repo number
#
[ -e $(dirname $0)/jenkins-deb-common ] || exit 1
. $(dirname $0)/jenkins-deb-common
jenkins_init
jenkins_set_vars
PROMOTE=${PROMOTE:-0}
function err_cleanup() {
echo "*** In the trap handler err_cleanup"
trap - SIGINT SIGTERM EXIT ERR
set +x
# dumping the log files...
for i in $(ls *.log); do
echo "##########################"
echo "# LOGFILE: $i"
echo "##########################"
cat $i
echo ""
echo ""
done
if [ "${NOCLEAN-0}" == "1" ]; then
exit 0
fi
echo "Cleanup"
if [ -d "${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}" ]; then
rm -rf ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}
fi
if [ -d "${BUILD_ROOT}/${BUILD_JOB}" ]; then
rm -rf ${BUILD_ROOT}/${BUILD_JOB}
fi
exit 1
}
trap "err_cleanup" SIGINT SIGTERM ERR EXIT
BUILD_JOB=${BUILD_NUMBER-na}
if [ "$BUILD_JOB" == "na" ]; then
echo "You need to define BUILD_NUMBER"
exit 1
fi
BUILD_PACKAGE=${RPM_PACKAGE-roush-agent}
BUILD_PACKAGE_VERSION=${PACKAGE_VERSION-1.0}
BUILD_PACKAGE_ARCH="${BUILD_PACKAGE_ARCH:-epel-6-x86_64 fedora-17-x86_64}"
BUILD_GIT_BRANCH=${GIT_BRANCH:-master}
BUILD_ROOT="/home/jenkins/workspace/jenkins-rpm-build"
mkdir -p ${BUILD_ROOT}/${BUILD_JOB}
cd ${BUILD_ROOT}/${BUILD_JOB}
BUILD_GIT_REPO=${GIT_REPO:-unset}
# clone the repo
git clone ${BUILD_GIT_REPO} ${BUILD_PACKAGE}-tmp
# checkout the branch we are building from
pushd ${BUILD_PACKAGE}-tmp
git checkout ${BUILD_GIT_BRANCH}
popd
# get the version from the spec file...
if [ -e "${BUILD_PACKAGE}-tmp/redhat/SPEC/${BUILD_PACKAGE}.spec" ]; then
BUILD_PACKAGE_VERSION=$(grep ^Version: "${BUILD_PACKAGE}-tmp/redhat/SPEC/${BUILD_PACKAGE}.spec" | awk '{print $2}')
fi
mv ${BUILD_PACKAGE}-tmp ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}
#
# format for our repos should be
# package-name/redhat/SPEC/specfile.spec
# package-name/redhat/SOURCES/any_source_files
#
if [ -e "${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}/redhat/SPEC/${BUILD_PACKAGE}.spec" ]; then
sed -i "s/^%define ver [0-9]*/%define ver ${BUILD_JOB}/g" ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}/redhat/SPEC/${BUILD_PACKAGE}.spec
fi
if [ -d "${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}/redhat/SOURCES" ]; then
cp ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}/redhat/SOURCES/* .
fi
tar zcf ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}.tgz ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}
SRCRPM=$(HOME=${BUILD_ROOT}/${BUILD_JOB} rpmbuild -vv -ts ${BUILD_PACKAGE}-${BUILD_PACKAGE_VERSION}.tgz | grep "Wrote:" | awk '{print $2'})
echo "SRCRPM=${SRCRPM}"
for i in $BUILD_PACKAGE_ARCH; do
REPO_PACKAGE_VERSION=`echo $i | cut -d "-" -f 2`
REPO_PACKAGE_ARCH=`echo $i | cut -d "-" -f 3`
TEMP_REPO_PACKAGE_DISTRO=`echo $i | cut -d "-" -f 1`
REPO_PACKAGE_DISTRO=""
if [ "$TEMP_REPO_PACKAGE_DISTRO" == "epel" ]; then
REPO_PACKAGE_DISTRO="RedHat"
elif [ "$TEMP_REPO_PACKAGE_DISTRO" == "fedora" ]; then
REPO_PACKAGE_DISTRO="Fedora"
else
echo "incorrect distro definition"
exit 1
fi
mock --resultdir=${BUILD_ROOT}/${BUILD_JOB} -r ${i} ${SRCRPM}
rm *.log
~/sign-rpm.exp ${BUILD_ROOT}/${BUILD_JOB}/*.src.rpm
~/sign-rpm.exp ${BUILD_ROOT}/${BUILD_JOB}/*.rpm
mkdir -p ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
mkdir -p ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
if [[ "${PROMOTE}" = "1" ]]; then
mkdir -p ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
mkdir -p ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
cp ${BUILD_ROOT}/${BUILD_JOB}/*.src.rpm ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
cp ${BUILD_ROOT}/${BUILD_JOB}/*.rpm ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
createrepo ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
createrepo ${BUILD_ROOT}/prod-repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
fi
mv ${BUILD_ROOT}/${BUILD_JOB}/*.src.rpm ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
mv ${BUILD_ROOT}/${BUILD_JOB}/*.rpm ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
createrepo ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/SRPMS
createrepo ${BUILD_ROOT}/repo/${REPO_PACKAGE_DISTRO}/${REPO_PACKAGE_VERSION}/${REPO_PACKAGE_ARCH}
done;
#rsync -avz -e ssh /home/jenkins/workspace/jenkins-rpm-build/repo/ [email protected]:/var/www/repo-testing/
/home/jenkins/workspace/jenkins-rpm-build/sync-repo.sh
trap - SIGINT SIGTERM EXIT ERR
exit 0