-
Notifications
You must be signed in to change notification settings - Fork 17
/
Jenkinsfile
259 lines (227 loc) · 8.29 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
/**
properties([
parameters([
string(defaultValue: '1.0', description: 'Current version number', name: 'VERSION'),
text(defaultValue: '', description: 'A list of changes', name: 'CHANGES'),
booleanParam(defaultValue: false, description: 'If build should be marked as pre-release', name: 'PRERELEASE'),
string(defaultValue: 'ayufan-pine64', description: 'GitHub username or organization', name: 'GITHUB_USER'),
string(defaultValue: 'android-7.1', description: 'GitHub repository', name: 'GITHUB_REPO'),
booleanParam(defaultValue: true, description: 'Select if you want to build tablet version.', name: 'BUILD_TABLET'),
booleanParam(defaultValue: true, description: 'Select if you want to build TV version.', name: 'BUILD_TV'),
booleanParam(defaultValue: true, description: 'Select if you want to build Pinebook version.', name: 'BUILD_PINEBOOK'),
])
])
*/
node('docker && android-build') {
timestamps {
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {
stage "Environment"
dir('build-environment') {
checkout scm
}
def environment = docker.build('build-environment:android-7.1', 'build-environment')
environment.inside {
stage 'Sources'
sh '''#!/bin/bash
set -xe
export HOME=$WORKSPACE
export USER=jenkins
repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r11 --depth=1
rm -rf .repo/local_manifests
git clone https://github.com/ayufan-pine64/local_manifests -b nougat-7.1 .repo/local_manifests
repo sync -j 20 -c --force-sync
'''
withEnv([
"VERSION=$VERSION",
'TARGET=tulip_chiphd-userdebug',
'USE_CCACHE=true',
'CCACHE_DIR=/var/lib/ccache',
]) {
stage 'Prepare'
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
prebuilts/misc/linux-x86/ccache/ccache -M 0 -F 0
rm -f *.gz
'''
}
withEnv([
"VERSION=$VERSION",
"CHANGES=$CHANGES",
"GITHUB_USER=$GITHUB_USER",
"GITHUB_REPO=$GITHUB_REPO"
]) {
stage 'Freeze'
sh '''#!/bin/bash
# use -ve, otherwise we could leak GITHUB_TOKEN...
set -ve
shopt -s nullglob
export HOME=$WORKSPACE
export USER=jenkins
repo manifest -r -o manifest.xml
echo "{\\"message\\":\\"Add $VERSION changes\\", \\"committer\\":{\\"name\\":\\"Jenkins\\",\\"email\\":\\"[email protected]\\"},\\"content\\":\\"$(echo "$CHANGES" | base64 -w 0)\\"}" | \
curl --fail -X PUT -H "Authorization: token $GITHUB_TOKEN" -d @- \
"https://api.github.com/repos/$GITHUB_USER/$GITHUB_REPO/contents/versions/$VERSION/CHANGES.md"
echo "{\\"message\\":\\"Add $VERSION manifest\\", \\"committer\\":{\\"name\\":\\"Jenkins\\",\\"email\\":\\"[email protected]\\"},\\"content\\":\\"$(base64 -w 0 manifest.xml)\\"}" | \
curl --fail -X PUT -H "Authorization: token $GITHUB_TOKEN" -d @- \
"https://api.github.com/repos/$GITHUB_USER/$GITHUB_REPO/contents/versions/$VERSION/manifest.xml"
'''
}
withEnv([
"VERSION=$VERSION",
'TARGET=tulip_chiphd-userdebug',
'USE_CCACHE=true',
'ANDROID_JACK_VM_ARGS=-Xmx3g -Dfile.encoding=UTF-8 -XX:+TieredCompilation',
'ANDROID_NO_TEST_CHECK=true'
]) {
stage 'Regular'
if (params.BUILD_TABLET) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make installclean
'''
retry(2) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make -j$(($(nproc)+1))
'''
}
}
stage 'Image Regular'
if (params.BUILD_TABLET) {
sh '''#!/bin/bash
source build/envsetup.sh
lunch "${TARGET}"
set -xe
sdcard_image "${JOB_NAME}-v${VERSION}-r${BUILD_NUMBER}.img.gz"
sdcard_image "${JOB_NAME}-sopine-v${VERSION}-r${BUILD_NUMBER}.img.gz" "sopine"
'''
}
}
withEnv([
"VERSION=$VERSION",
'TARGET=tulip_chiphd_pinebook-userdebug',
'USE_CCACHE=true',
'ANDROID_JACK_VM_ARGS=-Xmx3g -Dfile.encoding=UTF-8 -XX:+TieredCompilation',
'ANDROID_NO_TEST_CHECK=true'
]) {
stage 'Pinebook'
if (params.BUILD_PINEBOOK) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make installclean
'''
retry(2) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make -j$(($(nproc)+1))
'''
}
}
stage 'Image Pinebook'
if (params.BUILD_PINEBOOK) {
sh '''#!/bin/bash
source build/envsetup.sh
lunch "${TARGET}"
set -xe
sdcard_image "${JOB_NAME}-pinebook-v${VERSION}-r${BUILD_NUMBER}.img.gz" pinebook
'''
}
}
withEnv([
"VERSION=$VERSION",
'TARGET=tulip_chiphd_atv-userdebug',
'USE_CCACHE=true',
'ANDROID_JACK_VM_ARGS=-Xmx3g -Dfile.encoding=UTF-8 -XX:+TieredCompilation',
'ANDROID_NO_TEST_CHECK=true'
]) {
stage 'TV'
if (params.BUILD_TV) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make installclean
'''
retry(2) {
sh '''#!/bin/bash
export CCACHE_DIR=$PWD/ccache
export HOME=$WORKSPACE
export USER=jenkins
source build/envsetup.sh
lunch "${TARGET}"
make -j$(($(nproc)+1))
'''
}
}
stage 'Image TV'
if (params.BUILD_TV) {
sh '''#!/bin/bash
source build/envsetup.sh
lunch "${TARGET}"
set -xe
sdcard_image "${JOB_NAME}-tv-v${VERSION}-r${BUILD_NUMBER}.img.gz"
'''
}
}
withEnv([
"VERSION=$VERSION",
"CHANGES=$CHANGES",
"PRERELEASE=$PRERELEASE",
"GITHUB_USER=$GITHUB_USER",
"GITHUB_REPO=$GITHUB_REPO"
]) {
stage 'Release'
sh '''#!/bin/bash
set -xe
shopt -s nullglob
github-release release \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--draft
github-release upload \
--tag "${VERSION}" \
--name "manifest.xml" \
--file "manifest.xml"
for file in *.gz; do
github-release upload \
--tag "${VERSION}" \
--name "$(basename "$file")" \
--file "$file"
done
if [[ "$PRERELEASE" == "true" ]]; then
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}" \
--pre-release
else
github-release edit \
--tag "${VERSION}" \
--name "$VERSION: $BUILD_TAG" \
--description "${CHANGES}\n\n${BUILD_URL}"
fi
'''
}
}
}
}
}