forked from ayufan-rock64/linux-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
165 lines (146 loc) · 5.64 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
/**
properties([
parameters([
string(defaultValue: '1.0', description: 'Current version number', name: 'VERSION'),
text(defaultValue: '', description: 'A list of changes', name: 'CHANGES'),
choice(choices: 'all\njessie-minimal-rock64\njessie-openmediavault-rock64\nstretch-minimal-rock64\nxenial-i3-rock64\nxenial-mate-rock64\nxenial-minimal-rock64\nlinux-virtual', description: 'What makefile image to target', name: 'MAKE_TARGET')
booleanParam(defaultValue: true, description: 'Whether to upload to Github for release or not', name: 'GITHUB_UPLOAD'),
booleanParam(defaultValue: false, description: 'If build should be marked as pre-release', name: 'GITHUB_PRERELEASE'),
string(defaultValue: 'ayufan-rock64', description: 'GitHub username or organization', name: 'GITHUB_USER'),
string(defaultValue: 'linux-build', description: 'GitHub repository', name: 'GITHUB_REPO'),
])
])
*/
node('docker && linux-build') {
timestamps {
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {
stage('Environment') {
checkout scm
def environment = docker.image('pfeerick/rock64-dockerfiles:x86_64')
environment.inside("--privileged -u 0:0") {
withEnv([
"USE_CCACHE=true",
"RELEASE_NAME=$VERSION",
"RELEASE=$BUILD_NUMBER"
]) {
stage('Prepare') {
sh '''#!/bin/bash
set -xe
export CCACHE_DIR=$WORKSPACE/ccache
ccache -M 0 -F 0
git clean -ffdx -e ccache
'''
}
stage('Sources') {
sh '''#!/bin/bash
set -xe
export HOME=$WORKSPACE
export USER=jenkins
repo init -u https://github.com/pfeerick-rock64/linux-manifests -b default --depth=1 --no-clone-bundle
repo sync -j 20 -c --force-sync
'''
}
stage('U-boot') {
sh '''#!/bin/bash
set -xe
export CCACHE_DIR=$WORKSPACE/ccache
make u-boot-build
'''
}
stage('Kernel') {
sh '''#!/bin/bash
set -xe
export CCACHE_DIR=$WORKSPACE/ccache
make kernel-build KERNEL_DIR=kernel
make kernel-build KERNEL_DIR=kernel-mainline
'''
}
stage('Images') {
sh '''#!/bin/bash
set -xe
export CCACHE_DIR=$WORKSPACE/ccache
make -j$(nproc) $MAKE_TARGET
'''
}
}
withEnv([
"VERSION=$VERSION",
"CHANGES=$CHANGES",
"GITHUB_PRERELEASE=$GITHUB_PRERELEASE",
"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
'''
}
stage('Tagging') {
sh '''#!/bin/bash
# use -ve, otherwise we could leak GITHUB_TOKEN...
set -ve
repo forall -g tagged -e -c git tag "$GITHUB_USER/$GITHUB_REPO/$VERSION"
'''
if (params.GITHUB_UPLOAD) {
retry(2) {
sh '''#!/bin/bash
# use -ve, otherwise we could leak GITHUB_TOKEN...
set -ve
echo "machine github.com login user password $GITHUB_TOKEN" > ~/.netrc
repo forall -g tagged -e -c git push pfeerick "$GITHUB_USER/$GITHUB_REPO/$VERSION" -f
rm ~/.netrc
'''
}
} else {
echo 'Flagged as an no tagging release job'
}
}
stage('Release') {
if (params.GITHUB_UPLOAD) {
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 *.xz *.deb; do
github-release upload \
--tag "${VERSION}" \
--name "$(basename "$file")" \
--file "$file" &
done
wait
if [[ "$GITHUB_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
'''
} else {
echo 'Flagged as an no upload release job'
}
}
}
}
}
}
}
}