This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Jenkinsfile
308 lines (261 loc) · 9.51 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!groovy
import java.text.SimpleDateFormat;
@NonCPS
def getChangeDetail() {
def changeDetail = ""
def changes = currentBuild.changeSets
for (int i = 0; i < changes.size(); i++) {
def entries = changes[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
Date entry_timestamp = new Date(entry.timestamp)
SimpleDateFormat timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
changeDetail += "${entry.commitId.take(7)} by [${entry.author}] on ${timestamp.format(entry_timestamp)}: ${entry.msg}\n\n"
}
}
if (!changeDetail) {
changeDetail = "No new changes"
}
return changeDetail
}
IS_MASTER_BRANCH = env.BRANCH_NAME == "master"
IS_RELEASE_BRANCH = (env.BRANCH_NAME ==~ /\d+\.\d+\.\d+/)
def sendEmailNotification() {
final def EXTRECIPIENTS = emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider'],
[$class: 'DevelopersRecipientProvider']
])
def RECIPIENTS = EXTRECIPIENTS != null ? EXTRECIPIENTS : env.CHANGE_AUTHOR_EMAIL;
def SUBJECT = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}!"
def CHANGE = getChangeDetail();
emailext(
to: RECIPIENTS,
subject: "${SUBJECT}",
body: """
<b>Build result:</b>
<br><br>
${currentBuild.currentResult}
<br><br>
<b>Project name - Build number:</b>
<br><br>
${currentBuild.fullProjectName} - Build #${env.BUILD_NUMBER}
<br><br>
<b>Check console output for more detail:</b>
<br><br>
<a href="${currentBuild.absoluteUrl}console">${currentBuild.absoluteUrl}console</a>
<br><br>
<b>Changes:</b>
<br><br>
${CHANGE}
<br><br>
"""
);
}
def BUILD_CONTAINER = """
image: node:10-jessie
tty: true
command:
- cat
resources:
limits:
memory: "2Gi"
cpu: "1"
requests:
memory: "2Gi"
cpu: "1"
"""
echo "Branch is ${env.BRANCH_NAME}"
echo "Is master branch build ? ${IS_MASTER_BRANCH}"
echo "Is release branch build ? ${IS_RELEASE_BRANCH}"
// https://stackoverflow.com/a/44902622
def CRON_STRING = ""
// https://jenkins.io/doc/book/pipeline/syntax/#cron-syntax
if (IS_MASTER_BRANCH) {
// Build daily between 0600-0659
CRON_STRING = "H 6 * * *"
}
def VSCODE_BUILDER = "vscode-builder"
def CHE_BUILDER = "che-builder"
def STASH_PJ = "release-package-json"
def STASH_VSCODE = "vscode-vsix"
def STASH_CHE = "che-vsix"
pipeline {
agent {
kubernetes {
label "vscode-buildpod"
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: ${VSCODE_BUILDER}
${BUILD_CONTAINER}
- name: ${CHE_BUILDER}
${BUILD_CONTAINER}
"""
}
}
options {
timestamps()
skipStagesAfterUnstable()
timeout(time: 2, unit: "HOURS")
}
triggers {
cron(CRON_STRING)
}
stages {
stage("Set Codewind version") {
when {
equals expected: true, actual: IS_RELEASE_BRANCH
}
// In the build containers, HOME gets set to / which causes permissions issues.
environment {
HOME="${env.WORKSPACE}"
}
steps {
container(VSCODE_BUILDER) {
dir("dev") {
println "Release branch detected; updating Codewind image version"
sh 'npm install'
sh './vsce-package.js --codewindImageTagOnly'
stash includes: "package.json", name: STASH_PJ
}
}
}
}
stage("Test") {
when {
beforeAgent true
not {
environment name: "SKIP_TESTS", value: "true"
}
}
options {
timeout(time: 1, unit: "HOURS")
}
agent {
label "docker-build"
}
steps {
script {
if (IS_RELEASE_BRANCH) {
unstash STASH_PJ
sh '''#!/usr/bin/env bash
echo "Unstashed release package.json"
mv -v package.json dev/
'''
}
}
sh '''#!/usr/bin/env bash
echo "Git commit is: $(git log --format=medium -1 ${GIT_COMMIT})"
./ci-scripts/run-tests.sh
'''
}
}
// we duplicate the cloned repo so that we can build vscode and che-theia in parallel without the builds interfering with one another
// see that 'build for che' uses a different dir
stage("Duplicate code") {
steps {
container(VSCODE_BUILDER) {
sh '''#!/usr/bin/env bash
set -x
cd ..
cp -r "$OLDPWD" codewind-che
'''
}
}
}
stage("Build") {
// In the build containers, HOME gets set to / which causes permissions issues.
environment {
HOME="${env.WORKSPACE}"
}
parallel {
stage("Build for VS Code") {
steps {
container(VSCODE_BUILDER) {
sh 'ci-scripts/package.sh'
// The parallel stages cannot share a stash or they will overwrite and corrupt each other
stash includes: '*.vsix', name: STASH_VSCODE
}
}
}
stage("Build for Che") {
steps {
container(CHE_BUILDER) {
// use the dir from the duplicate step
dir("../codewind-che") {
sh 'ci-scripts/package.sh che'
stash includes: '*.vsix', name: STASH_CHE
}
}
}
}
}
}
stage ("Upload") {
// This when clause disables PR build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
not {
changeRequest()
}
}
options {
skipDefaultCheckout()
}
agent any
steps {
sshagent (['projects-storage.eclipse.org-bot-ssh']) {
unstash STASH_VSCODE
unstash STASH_CHE
sh '''#!/usr/bin/env bash
export REPO_NAME="codewind-vscode"
export OUTPUT_NAME="codewind"
export OUTPUT_CHE_NAME="codewind-che"
export DOWNLOAD_AREA_URL="https://archive.eclipse.org/codewind/$REPO_NAME"
export LATEST_DIR="latest"
export BUILD_INFO="build_info.properties"
export sshHost="genie.codewind@projects-storage.eclipse.org"
export deployParentDir="/home/data/httpd/archive.eclipse.org/codewind/$REPO_NAME"
export BACKUP_DIR=temp_backup
UPLOAD_DIR="$GIT_BRANCH/$BUILD_ID"
BUILD_URL="$DOWNLOAD_AREA_URL/$UPLOAD_DIR"
ssh $sshHost rm -rf $deployParentDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost mkdir -p $deployParentDir/$GIT_BRANCH/$LATEST_DIR
cp $OUTPUT_CHE_NAME-*.vsix $OUTPUT_CHE_NAME.vsix
scp $OUTPUT_CHE_NAME.vsix $sshHost:$deployParentDir/$GIT_BRANCH/$LATEST_DIR/$OUTPUT_CHE_NAME.vsix
echo "# Build date: $(date +%F-%T)" >> $BUILD_INFO
echo "build_info.url=$BUILD_URL" >> $BUILD_INFO
SHA1_CHE=$(sha1sum ${OUTPUT_CHE_NAME}.vsix | cut -d ' ' -f 1)
echo "build_info.che.SHA-1=${SHA1_CHE}" >> $BUILD_INFO
rm $OUTPUT_CHE_NAME.vsix
mkdir $BACKUP_DIR
mv $OUTPUT_CHE_NAME-*.vsix $BACKUP_DIR/
cp $OUTPUT_NAME-*.vsix $OUTPUT_NAME.vsix
scp $OUTPUT_NAME.vsix $sshHost:$deployParentDir/$GIT_BRANCH/$LATEST_DIR/$OUTPUT_NAME.vsix
SHA1=$(sha1sum ${OUTPUT_NAME}.vsix | cut -d ' ' -f 1)
echo "build_info.SHA-1=${SHA1}" >> $BUILD_INFO
scp $BUILD_INFO $sshHost:$deployParentDir/$GIT_BRANCH/$LATEST_DIR/$BUILD_INFO
rm $BUILD_INFO
rm $OUTPUT_NAME.vsix
mv $BACKUP_DIR/* .
rmdir $BACKUP_DIR
export deployDir="$deployParentDir/$UPLOAD_DIR"
printf "Uploading files:\n$(ls -l *.vsix)\n"
ssh $sshHost rm -rf $deployDir
ssh $sshHost mkdir -p $deployDir
scp *.vsix $sshHost:$deployDir
echo "Uploaded to https://download.eclipse.org${deployDir##*download.eclipse.org}"
'''
}
}
}
}
post {
failure {
sendEmailNotification()
}
}
}