forked from TritonDataCenter/smartos-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_jenkins
executable file
·184 lines (160 loc) · 5.05 KB
/
build_jenkins
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
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Copyright 2019 Joyent, Inc.
#
#
# This is a wrapper used by jenkins to invoke the different targets needed for
# the Triton platform and SmartOS build variants.
#
if [[ -n "${TRACE}" ]]; then
export PS4='${BASH_SOURCE}:${LINENO}: '
set -o xtrace
fi
set -o errexit
set -o pipefail
# Allow users to override the Manta path where we publish artifacts
if [[ -z "${ENGBLD_DEST_OUT_PATH}" ]]; then
export ENGBLD_DEST_OUT_PATH=/public/builds
fi
export TIMESTAMP=$(TZ=UTC /bin/date "+%Y%m%dT%H%M%SZ")
export BUILDSTAMP=${TIMESTAMP}
# Used to flag if this is a non-default build. This modifies the description
# used for the platform manifest.
export ENGBLD_CUSTOM=''
# Jenkins should set this, otherwise default to the current branch, assuming
# our working directory is a smartos-live repository.
if [[ -z "${BRANCH}" ]]; then
export BRANCH=$(git branch 2> /dev/null | \
sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
fi
#
# Emit usage information
#
function usage {
echo "Usage: build_jenkins [options]"
echo "OPTIONS"
echo " -d build a debug platform"
echo " -F <flavor> build one of the following build flavors:"
echo " triton (default) a normal platform build"
echo " smartos only smartos platform bits"
echo " triton-and-smartos both of the above"
echo ""
echo "ENVIRONMENT"
echo " BRANCH the branch of smartos-live being built"
echo " ENGBLD_DEST_OUT_PATH the Manta path used when uploading artifacts"
echo " PLAT_CONFIGURE_ARGS additional arguments to pass to 'configure'"
echo " PLATFORM_BUILD_FLAVOR one of the -F arguments, as above"
echo " CONFIGURE_PROJECTS content for the 'configure-projects' file"
echo ""
echo "NOTE"
echo " Production builds expect we're building in a freshly cloned"
echo " repository. We do not attempt to 'make clean' before rebuilding."
exit 2
}
#
# A simple log wrapper for running a major build step
#
function log_cmd {
echo "==== Running $@ ====" | tee -a ${ENGBLD_LOG}
$@ 2>&1 | tee -a ${ENGBLD_LOG}
}
#
# A simple log wrapper
#
function log {
$@ 2>&1 | tee -a ${ENGBLD_LOG}
}
#
# Main
#
while getopts "dhF:" opt; do
case "${opt}" in
d)
# build debug platform bits
ENGBLD_CONFIGURE_DEBUG_ARG='-d'
ENGBLD_DEBUG_SUFFIX='-debug'
;;
F)
PLATFORM_BUILD_FLAVOR="${OPTARG}"
;;
h)
usage
;;
*)
echo "Error: Unknown argument ${opt}"
usage
esac
done
shift $((OPTIND - 1))
if [[ -z "$PLATFORM_BUILD_FLAVOR" ]]; then
PLATFORM_BUILD_FLAVOR="triton"
fi
case "${PLATFORM_BUILD_FLAVOR}" in
'triton'|'smartos'|'triton-and-smartos')
;;
*)
echo "Error: unknown platform build flavor: ${PLATFORM_BUILD_FLAVOR}"
usage
esac
ENGBLD_LOGDIR=output/bits/platform${ENGBLD_DEBUG_SUFFIX}
ENGBLD_LOG=${ENGBLD_LOGDIR}/build.log
# Rotate our output directories, mostly for the benefit of non-production builds
# We can't log these commands as we're physically removing the log location.
for output in output output-iso output-usb output-vmware; do
if [[ -d "${output}" ]]; then
echo "Removing old ${output} directory"
rm -rf ${output}.old
echo "Renaming output to ${output}.old"
mv ${output} ${output}.old
fi
done
mkdir -p ${ENGBLD_LOGDIR}
touch ${ENGBLD_LOG}
# Remove any old logs so that these don't get swept up as Jenkins artifacts
log rm -rf log projects/illumos/log
# Is this a release branch build
if echo "${BRANCH}" | grep -q "^release"; then
ENGBLD_RELEASE=true
else
ENGBLD_RELEASE=""
fi
#
# ${CONFIGURE_PROJECTS} is multi-line jenkins parameter, set so that users can
# specify which branches of the repositories in the smartos-live 'projects'
# framework to build, and from where they should be cloned.
#
if [[ -z "${CONFIGURE_PROJECTS}" ]]; then
echo "using default configure-projects"
else
echo "${CONFIGURE_PROJECTS}" > configure-projects
fi
# Configure the build based on the arguments we've gathered
log_cmd ./configure -r \
${ENGBLD_CONFIGURE_DEBUG_ARG} \
${PLAT_CONFIGURE_ARGS}
log_cmd gmake common-release
case "${PLATFORM_BUILD_FLAVOR}" in
'triton')
log_cmd gmake triton-release
;;
'smartos')
log_cmd gmake smartos-only-release
;;
'triton-and-smartos')
log_cmd gmake triton-smartos-release
;;
esac
# Update Manta snaplinks for smartos, only if this is a non-debug release build
if [[ -z "${ENGBLD_CONFIGURE_DEBUG_ARG}" && -n "${ENGBLD_RELEASE}" ]]; then
case "${PLATFORM_BUILD_FLAVOR}" in
'smartos'|'triton-and-smartos')
log_cmd env TRACE=1 ./tools/smartos-release \
"${BRANCH}" "${TIMESTAMP}"
;;
esac
fi