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 28
/
Jenkinsfile
323 lines (265 loc) · 11.6 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!groovy
pipeline {
agent {
kubernetes {
label 'go-pod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: go
image: golang:1.12-stretch
tty: true
command:
- cat
resources:
limits:
memory: "4Gi"
cpu: "1"
requests:
memory: "4Gi"
cpu: "1"
"""
}
}
options {
timestamps()
skipStagesAfterUnstable()
}
environment {
CODE_DIRECTORY_FOR_GO = 'src/github.com/eclipse/codewind-installer'
DEFAULT_WORKSPACE_DIR_FILE = 'temp_default_dir'
CODECOV_TOKEN = credentials('codecov-token')
}
stages {
stage ('Build') {
// This when clause disables Tagged build
when {
beforeAgent true
not {
buildingTag()
}
}
steps {
container('go') {
sh '''#!/bin/bash
echo "starting preInstall.....: GOPATH=$GOPATH"
# add the base directory to the gopath
DEFAULT_CODE_DIRECTORY=$PWD
cd ../..
export GOPATH=$GOPATH:$(pwd)
# create a new directory to store the code for go compile
if [ -d $CODE_DIRECTORY_FOR_GO ]; then
rm -rf $CODE_DIRECTORY_FOR_GO
fi
mkdir -p $CODE_DIRECTORY_FOR_GO
cd $CODE_DIRECTORY_FOR_GO
# copy the code into the new directory for go compile
cp -r $DEFAULT_CODE_DIRECTORY/* .
echo $DEFAULT_CODE_DIRECTORY >> $DEFAULT_WORKSPACE_DIR_FILE
# run go mod tidy
export GO111MODULE=on
go mod tidy
# go cache setup
mkdir .cache
cd .cache
mkdir go-build
cd ../
# now compile the code
cd cmd/cli
export HOME=$JENKINS_HOME
export GOCACHE=/home/jenkins/agent/$CODE_DIRECTORY_FOR_GO/.cache/go-build
export GOARCH=amd64
GOOS=darwin go build -ldflags="-s -w" -o cwctl-macos
GOOS=windows go build -ldflags="-s -w" -o cwctl-win.exe
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o cwctl-linux
GOOS=linux GOARCH=ppc64le go build -o cwctl-ppc64le
chmod -v +x cwctl-*
# clean up the cache directory
cd ../../
rm -rf .cache
cd cmd/cli
# move the built binaries to the top level direcotory
mv cwctl-* ../../
cd ../../
'''
}
}
}
stage('Test') {
// This when clause disables Tagged build
when {
beforeAgent true
not {
buildingTag()
}
}
options {
timeout(time: 10, unit: 'MINUTES')
retry(3)
}
steps {
echo 'Starting tests'
container('go') {
sh '''#!/bin/bash
export GOPATH=/go:/home/jenkins/agent
# go cache setup
mkdir .cache
cd .cache
mkdir go-build
cd ../
export GOCACHE=/home/jenkins/agent/$CODE_DIRECTORY_FOR_GO/.cache/go-build
cd ../../$CODE_DIRECTORY_FOR_GO
export GO111MODULE=on
go test ./... -short -coverprofile=coverage.txt -covermode=count
TEST_RESULT=$?
if [ $TEST_RESULT -ne 0 ]; then
exit $TEST_RESULT
fi
# Report coverage
if [ -n "$CODECOV_TOKEN" ]; then
echo "Reporting coverage to codecov"
bash <(curl -s https://codecov.io/bash) -f ./coverage.txt
else
echo "CODECOV_TOKEN not set, not reporting coverage"
fi
# clean up the cache directory
rm -rf .cache
'''
}
echo 'End of test stage'
}
}
stage('Upload') {
// This when clause disables Tagged build
when {
beforeAgent true
not {
buildingTag()
}
}
steps {
script {
sh '''
# switch to the code go directory
cd ../../$CODE_DIRECTORY_FOR_GO
echo $(pwd)
if [ -d codewind-installer ]; then
rm -rf codewind-installer
fi
mkdir codewind-installer
TIMESTAMP="$(date +%F-%H%M)"
# WINDOWS EXE: Submit Windows unsigned.exe and save signed output to signed.exe
# only sign windows exe if not a pull request
if [ -z $CHANGE_ID ]; then
curl -o codewind-installer/cwctl-win-${TIMESTAMP}.exe -F [email protected] http://build.eclipse.org:31338/winsign.php
rm cwctl-win.exe
fi
# move other executable to codewind-installer directory and add timestamp to the name
for fileid in cwctl-*; do
mv -v $fileid codewind-installer/${fileid}-$TIMESTAMP
done
DEFAULT_WORKSPACE_DIR=$(cat $DEFAULT_WORKSPACE_DIR_FILE)
mkdir $DEFAULT_WORKSPACE_DIR/codewind-installer
cp -r codewind-installer/* $DEFAULT_WORKSPACE_DIR/codewind-installer
'''
// stash the executables so they are avaialable outside of this agent
dir('codewind-installer') {
sh 'echo "Stashing: $(ls -lA cwctl*)"'
stash includes: 'cwctl*', name: 'EXECUTABLES'
}
}
}
}
stage('Deploy') {
// This when clause disables PR/Tag build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
allOf {
not {
changeRequest()
}
not {
buildingTag()
}
}
}
options {
timeout(time: 120, unit: 'MINUTES')
retry(3)
}
agent any
steps {
sshagent ( ['projects-storage.eclipse.org-bot-ssh']) {
println("Deploying codewind-installer to download area...")
// get the stashed executables
unstash 'EXECUTABLES'
sh '''
export REPO_NAME="codewind-installer"
export ARCHIVE_AREA_URL="https://archive.eclipse.org/codewind/$REPO_NAME"
export DOWNLOAD_AREA_URL="https://download.eclipse.org/codewind/$REPO_NAME"
export LATEST_DIR="latest"
export BUILD_INFO="build_info.properties"
export sshHost="[email protected]"
export deployDir="/home/data/httpd/archive.eclipse.org/codewind/$REPO_NAME"
export deployDownloadDir="/home/data/httpd/download.eclipse.org/codewind/$REPO_NAME"
export CWCTL_BASENAME="cwctl"
export CWCTL_LINUX="${CWCTL_BASENAME}-linux"
export CWCTL_PPC64LE="${CWCTL_BASENAME}-ppc64le"
export CWCTL_MACOS="${CWCTL_BASENAME}-macos"
export CWCTL_WIN="${CWCTL_BASENAME}-win"
UPLOAD_DIR="$GIT_BRANCH/$BUILD_ID"
BUILD_URL="$ARCHIVE_AREA_URL/$UPLOAD_DIR"
ssh $sshHost rm -rf $deployDir/${UPLOAD_DIR}
ssh $sshHost mkdir -p $deployDir/${UPLOAD_DIR}
ssh $sshHost rm -rf $deployDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost mkdir -p $deployDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost rm -rf $deployDownloadDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost mkdir -p $deployDownloadDir/$GIT_BRANCH/$LATEST_DIR
ls -lA
# Copy artifacts before renaming to the build ID'd directory
scp ${CWCTL_BASENAME}* $sshHost:$deployDir/${UPLOAD_DIR}
# Now prepare to copy to latest/ directory
# Rename to remove timestamps
mv $CWCTL_LINUX-* $CWCTL_LINUX
mv $CWCTL_PPC64LE-* $CWCTL_PPC64LE
mv $CWCTL_MACOS-* $CWCTL_MACOS
mv $CWCTL_WIN-* $CWCTL_WIN.exe
# Make a targz copy of each build and copy it into zips/
export ZIPS_DIR="zips"
if [ -d ${ZIPS_DIR} ]; then
rm -rf ${ZIPS_DIR}
fi
mkdir ${ZIPS_DIR}
for f in $(ls ${CWCTL_BASENAME}*); do
export TARGZ_NAME="${f}.tar.gz"
tar -czvf $TARGZ_NAME $f
mv $TARGZ_NAME ${ZIPS_DIR}
done
# Assemble build_info.properties with build date and shasums
echo "# Build date: $(date +%F-%T)" >> $BUILD_INFO
echo "build_info.url=$BUILD_URL" >> $BUILD_INFO
SHA1_LINUX=$(sha1sum $CWCTL_LINUX | cut -d ' ' -f 1)
echo "build_info.linux.SHA-1=${SHA1_LINUX}" >> $BUILD_INFO
SHA1_PPC64LE=$(sha1sum $CWCTL_PPC64LE | cut -d ' ' -f 1)
echo "build_info.ppc64le.SHA-1=${SHA1_PPC64LE}" >> $BUILD_INFO
SHA1_MACOS=$(sha1sum $CWCTL_MACOS | cut -d ' ' -f 1)
echo "build_info.macos.SHA-1=${SHA1_MACOS}" >> $BUILD_INFO
SHA1_WIN=$(sha1sum $CWCTL_WIN.exe | cut -d ' ' -f 1)
echo "build_info.win.SHA-1=${SHA1_WIN}" >> $BUILD_INFO
# Copy the build.properties, the zips, and the renamed artifacts to the latest/ build directory in archive area
scp -r ${BUILD_INFO} ${CWCTL_BASENAME}* zips/ $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR
# Copy the build.properties, the zips, and the renamed artifacts to the latest/ build directory in download area
scp -r ${BUILD_INFO} ${CWCTL_BASENAME}* zips/ $sshHost:$deployDownloadDir/$GIT_BRANCH/$LATEST_DIR
'''
}
}
}
}
post {
success {
echo 'Build SUCCESS'
}
}
}