-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJenkinsfile
More file actions
221 lines (193 loc) · 6.22 KB
/
Jenkinsfile
File metadata and controls
221 lines (193 loc) · 6.22 KB
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
pipeline {
agent { label 'aarch64' }
options {
timestamps()
}
environment {
// Shared directories
SHARED_DIR = "/home/jenkins/shared"
CCACHE_DIR = "${SHARED_DIR}/ccache"
BINPKGS_DIR = "${SHARED_DIR}/binpkgs"
DISTFILES_DIR="${SHARED_DIR}/distfiles"
BINARY_ASSETS="${SHARED_DIR}/binary_assets"
OVERLAYS_CACHE_DIR = "${SHARED_DIR}/overlays-cache"
BUILD_DIR = "${WORKSPACE}/build"
NO_PARALLEL="yes"
// Build configuration
INIT_SYSTEMS_STR = "OpenRC,Systemd"
BUILDVERSION = sh(script: "date +%d-%m-%y", returnStdout: true).trim()
SUDO_CMD = "sudo -E"
// MinIO configuration (should match your Jenkins credentials)
MINIO_BUCKET = "images"
}
stages {
// Initial cleanup and setup (runs in main workspace)
stage('Initial Setup') {
agent { label 'aarch64' }
steps {
sh "cat /proc/mounts"
sh "for var in ./build/*/image/*; do sudo umount -lfd \$var || sudo umount -ld \$var || sudo umount -l \$var || echo \"\$var not a mount point\"; done"
sh "for var in ./build/*/*; do sudo umount -lfd \$var || sudo umount -ld \$var || sudo umount -l \$var || echo \"\$var not a mount point\"; done"
sh "sudo losetup -all --list --output NAME,BACK-FILE"
sh "for var in \$(sudo losetup -all --list --output NAME,BACK-FILE | grep deleted | cut -f1 -d' '); do losetup -d \$var || echo \"\$(sudo losetup -all --list --output NAME,BACK-FILE | grep \$var) cant be detached\"; done"
sh "sudo losetup -D"
sh "sudo rm -rf ./*"
sh "git checkout ."
sh "sudo mkdir -p $CCACHE_DIR $BINPKGS_DIR $DISTFILES_DIR $BINARY_ASSETS $OVERLAYS_CACHE_DIR"
}
}
stage('Print Environment'){
agent { label 'aarch64' }
steps {
// Clear out anything from the previous build...
sh "env"
sh "ls -lah $CCACHE_DIR"
sh "ls -lahR $BINPKGS_DIR"
sh "ls -lahR $DISTFILES_DIR"
sh "ls -lahR $BINARY_ASSETS"
// Will kill the build if doesn't exist otherwise..
sh "ls -lah $OVERLAYS_CACHE_DIR"
}}
// Base images - each gets its own native workspace (@1, @2, etc.)
stage('Build Base Images') {
matrix {
axes {
axis {
name 'INIT_SYSTEM'
values 'OpenRC', 'Systemd', 'Osuosl'
}
}
stages {
stage('Build') {
agent {
label 'aarch64'
// Jenkins will automatically assign @1, @2, etc.
}
steps {
script {
// Fresh checkout in this workspace
checkout scm
def project = "GenPi64${INIT_SYSTEM}"
echo "Building ${project} base in workspace ${env.WORKSPACE}"
buildProject(project)
}
}
}
}
}
}
// Desktop images - each gets its own native workspace
stage('Build Desktop Images') {
matrix {
axes {
axis {
name 'INIT_SYSTEM'
values 'OpenRC', 'Systemd'
}
}
stages {
stage('Build') {
agent {
label 'aarch64'
// Jenkins will automatically assign @3, @4, etc.
}
steps {
script {
// Fresh checkout in this workspace
checkout scm
def project = "GenPi64${INIT_SYSTEM}Desktop"
echo "Building ${project} in workspace ${env.WORKSPACE}"
buildProject(project)
}
}
}
}
}
}
stage('Upload Artifacts') {
agent { label 'aarch64' }
steps {
script {
def initSystems = ['OpenRC', 'Systemd', 'Osuosl']
def variants = ['', 'Desktop']
for (initSystem in initSystems) {
if (initSystem == 'Osuosl') {
variants = [''] // Osuosl has no variants
} else {
variants = ['', 'Desktop']
}
for (variant in variants) {
def project = "GenPi64${initSystem}${variant}"
uploadArtifacts(project)
}
}
}
}
}
stage('Upload binary packages') {
agent { label 'aarch64' }
environment {
BINPKGS_DIR="${HOME}/shared/binpkgs"
}
steps {
sh "ls -lah ${BINPKGS_DIR}"
minio(bucket:"binpkgs", includes:"${BINPKGS_DIR}/**")
}
}
}
post {
always {
script {
// Cleanup with retries
echo "Cleaning up..."
// Clear out anything from the previous build...
sh "cat /proc/mounts"
sh "for var in ./build/*/image/*; do sudo umount -lfd \$var || sudo umount -ld \$var || sudo umount -l \$var || echo \"\$var not a mount point\"; done"
sh "for var in ./build/*/*; do sudo umount -lfd \$var || sudo umount -ld \$var || sudo umount -l \$var || echo \"\$var not a mount point\"; done"
sh "for var in \$(find . -maxdepth 1 -name './build/*/chroot/var/log/emerge.log' -print); do sudo cat \$var; done"
sh "sudo losetup -all --list --output NAME,BACK-FILE"
sh "for var in \$(sudo losetup -all --list --output NAME,BACK-FILE | grep deleted | cut -f1 -d' '); do losetup -d \$var || echo \"\$(sudo losetup -all --list --output NAME,BACK-FILE | grep \$var) cant be detached\"; done"
sh "sudo losetup -D"
}
}
success {
echo "Build completed successfully!"
}
failure {
echo "Build failed! Check logs for details."
}
}
}
// Helper function to build a project
def buildProject(project) {
def envVars = [
"PROJECT=${project}",
"CCACHE_DIR=${CCACHE_DIR}",
"BINPKGS_DIR=${BINPKGS_DIR}",
"OVERLAYS_CACHE_DIR=${OVERLAYS_CACHE_DIR}",
"BUILDVERSION=${BUILDVERSION}",
"WORKSPACE=${WORKSPACE}"
].join(' ')
sh "${envVars} ${SUDO_CMD} ${WORKSPACE}/build.sh"
}
// Helper function to upload artifacts using MinIO plugin
def uploadArtifacts(project) {
def artifacts = [
"${project}-${BUILDVERSION}.img.zst",
"${project}-${BUILDVERSION}.tar.zst",
"${project}-${BUILDVERSION}.img.zst.sum"
]
sh "sudo --preserve-env ./.ci/scripts/check-filename-is-renamed.sh"
for (artifact in artifacts) {
def fullPath = "${BUILD_DIR}/${project}/${artifact}"
if (fileExists(fullPath)) {
echo "Uploading ${artifact} to MinIO..."
minio(
bucket: env.MINIO_BUCKET,
includes: fullPath
)
} else {
echo "Warning: Artifact ${fullPath} not found"
}
}
}