forked from TritonDataCenter/sdc-headnode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
241 lines (221 loc) · 7.92 KB
/
Jenkinsfile
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* 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 2022 Joyent, Inc.
* Copyright 2022 MNX Cloud, Inc.
*/
@Library('[email protected]') _
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '30'))
timestamps()
}
agent none
// Build the master branch once per day, and start a few hours before
// nightly reflashes tend to kick off, at 'H 2 * * *',
// so we get reasonably up to date headnode images to
// test with.
triggers {
cron(env.BRANCH_NAME == 'master' ? 'H 2 * * *' : '')
}
parameters {
text(
name: 'CONFIGURE_BRANCHES',
defaultValue: '',
description:
'<p>\n' +
'Rather than writing JSON for the BUILD_SPEC_LOCAL\n' +
'parameter, this allows you to specify the branches for the\n' +
'various components you wish to to use in the headnode\n' +
' image.</p>' +
'<p>See documentation from the\n' +
'<a href="https://github.com/TritonDataCenter/sdc-headnode/blob/master/README.md#build-specification-buildspec-and-buildspeclocal">\n' +
'sdc-headnode</a> repository. In particular, see <a href="https://github.com/TritonDataCenter/sdc-headnode/blob/master/README.md#alternative-branch-selection">\n' +
'how to override branches</a>.\n' +
'</p>\n' +
'\n' +
'<p>\n' +
'Example:\n' +
'</p>\n' +
'\n' +
'<p>\n' +
'<pre>\n' +
'bits-branch: release-20150514\n' +
'cnapi: master\n' +
'platform: master\n' +
'</pre>\n' +
'</p>'
)
text(
name: 'BUILD_SPEC_LOCAL',
defaultValue: '',
description:
'For power users, supply the full contents of a\n' +
'build.spec.local file.\n' +
'This is merged into the configuration before any\n' +
'build.spec.branches file (hich is generated from\n' +
'configure-branches)'
)
booleanParam(
name: 'INCLUDE_DEBUG_STAGE',
defaultValue: false,
description: 'This parameter declares whether to build ' +
'debug bits as well as the default non-debug bits'
)
}
stages {
stage('check') {
agent {
node {
label '!virt:kvm && !virt:bhyve && fs:pcfs && fs:ufs && jenkins_agent:3 && pkgsrc_arch:multiarch'
customWorkspace "workspace/headnode-${BRANCH_NAME}-check"
}
}
tools {
nodejs 'sdcnode-v6-zone'
}
steps{
sh('''
set -o errexit
set -o pipefail
make check
''')
}
post {
// We don't mattermost-notify here, as that doesn't add much
// value. The checks should always pass, and it's unlikely
// that developers will care when they do. If they don't
// pass, then the (likely) GitHub PR will be updated with a
// failure status, and the developer can then investigate.
// https://jenkins.io/doc/pipeline/steps/ws-cleanup/
// We don't clean on build failure so that there's a chance to
// investigate the breakage. Hopefully, a subsequent successful
// build will then clean up the workspace, though that's not
// guaranteed for abandoned branches.
always {
cleanWs cleanWhenSuccess: true,
cleanWhenFailure: false,
cleanWhenAborted: true,
cleanWhenNotBuilt: true,
deleteDirs: true
}
}
}
stage('default') {
agent {
node {
label '!virt:kvm && !virt:bhyve && fs:pcfs && fs:ufs && jenkins_agent:3 && pkgsrc_arch:multiarch'
customWorkspace "workspace/headnode-${BRANCH_NAME}-default"
}
}
when {
// We only want to trigger a full headnode build on either a
// push to master, or an explicit build request from a user.
// Otherwise, every push to a PR branch would cause a build,
// which might be excessive. The exception is the 'check' stage
// above, which is ~ a 2 minute build.
beforeAgent true
anyOf {
branch 'master'
triggeredBy cause: 'UserIdCause'
}
}
tools {
nodejs 'sdcnode-v6-zone'
}
steps {
sh('git clean -fdx')
sh('''
set -o errexit
set -o pipefail
# validate-buildenv checks for a delegated dataset,
# unnecessary for the headnode build
export ENGBLD_SKIP_VALIDATE_BUILDENV=true
if [[ -n "$CONFIGURE_BRANCHES" ]]; then
echo "${CONFIGURE_BRANCHES}" > configure-branches
fi
if [[ -n "$BUILD_SPEC_LOCAL" ]]; then
echo "$BUILD_SPEC_LOCAL" > build.spec.local
json < build.spec.local
fi
# Ensure the 'gz-tools' image gets published.
export ENGBLD_BITS_UPLOAD_IMGAPI=true
# note we intentionally use bits-upload-latest
# so that our Manta path gets the 'latest-timestamp' override
# from our 'publish' target
make print-STAMP all publish bits-upload-latest
''')
}
post {
always {
cleanWs cleanWhenSuccess: true,
cleanWhenFailure: false,
cleanWhenAborted: true,
cleanWhenNotBuilt: true,
deleteDirs: true
}
}
}
stage('debug') {
agent {
node {
label '!virt:kvm && !virt:bhyve && fs:pcfs && fs:ufs && jenkins_agent:3 && pkgsrc_arch:multiarch'
customWorkspace "workspace/headnode-${BRANCH_NAME}-debug"
}
}
when {
beforeAgent true
environment name: 'INCLUDE_DEBUG_STAGE', value: 'true'
anyOf {
branch 'master'
triggeredBy cause: 'UserIdCause'
}
}
tools {
nodejs 'sdcnode-v6-zone'
}
steps {
sh('git clean -fdx')
sh('''
set -o errexit
set -o pipefail
# validate-buildenv checks for a delegated dataset,
# unnecessary for the headnode build
export ENGBLD_SKIP_VALIDATE_BUILDENV=true
export HEADNODE_VARIANT=debug
env
if [[ -n "$CONFIGURE_BRANCHES" ]]; then
echo "${CONFIGURE_BRANCHES}" > configure-branches
fi
if [[ -n "$BUILD_SPEC_LOCAL" ]]; then
echo "$BUILD_SPEC_LOCAL" > build.spec.local
json < build.spec.local
fi
# Ensure the 'gz-tools' image gets published.
export ENGBLD_BITS_UPLOAD_IMGAPI=true
# note we intentionally use bits-upload-latest
# so that our Manta path gets the 'latest-timestamp' override
# from our 'publish' target
make print-STAMP all publish bits-upload-latest
''')
}
post {
always {
cleanWs cleanWhenSuccess: true,
cleanWhenFailure: false,
cleanWhenAborted: true,
cleanWhenNotBuilt: true,
deleteDirs: true
}
}
}
}
post {
always {
joySlackNotifications(channel: 'jenkins')
}
}
}