Added inital Jenkinsfile

The jenkinsfile can  build packages for x86_64,aarch64, armhf  and armv7
And collect the packages as artifacts in Jenkins
This commit is contained in:
2023-10-05 21:54:53 +02:00
parent 43fcaf38a1
commit fcb2de6c9e
2 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#!/bin/ash
Arch=armv7
Name=$Arch
chrootDir=/chroot/$Name
#Setup core
apk -X http://192.168.1.3/alpine/v3.18/main -U --allow-untrusted -p ${chrootDir} --arch ${Arch} --initdb add alpine-base git doas doas-sudo-shim alpine-sdk
#Create required device nodes
mknod -m 666 ${chrootDir}/dev/full c 1 7
mknod -m 666 ${chrootDir}/dev/ptmx c 5 2
mknod -m 644 ${chrootDir}/dev/random c 1 8
mknod -m 644 ${chrootDir}/dev/urandom c 1 9
mknod -m 666 ${chrootDir}/dev/zero c 1 5
mknod -m 666 ${chrootDir}/dev/tty c 5 0
#Setup DNS
cp -L /etc/resolv.conf ${chrootDir}/etc/
#Setup Repo
mkdir -p ${chrootDir}/etc/apk
cp -L /etc/apk/repositories ${chrootDir}/etc/apk/repositories
#Install config files
echo "PS1='(Chroot-$Name)Test:\w\$ '" >> ${chrootDir}/etc/profile
cp -L -p /etc/doas.d/jenkinsAPKbuilder.conf ${chrootDir}/etc/doas.d/jenkinsAPKbuilder.conf
#Setup user
echo "jenkins:x:1000:1000::/home/jenkins:/bin/sh" >> ${chrootDir}/etc/passwd
echo "jenkins:x:1000:" >> ${chrootDir}/etc/group
sed -i 's/abuild.*/abuild:x:300:jenkins/' ${chrootDir}/etc/group
mkdir -p ${chrootDir}/home/jenkins
chown jenkins:jenkins ${chrootDir}/home/jenkins
cp -L -r /home/jenkins/.abuild ${chrootDir}/home/jenkins/
chgrp abuild ${chrootDir}/var/cache/distfiles
chmod g+w ${chrootDir}/var/cache/distfiles

117
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,117 @@
//When setting up this pipeline, please enable SCM branch to '*/Main' and enable 'checkout to subdirectory' to checkout to 'AlpinePackages'
pipeline {
agent none
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '1'))
}
stages {
stage('BuildAndTest') {
matrix {
agent {
label "AlpinePKG-Builder && ${Arch}"
}
axes {
axis {
name 'Arch'
values 'amd64', 'aarch64'
}
}
stages {
stage('Prepair') {
steps {
echo "Prepairing on ${Arch}"
// cleanWs()
// Checkout the repository
checkout scm
sh 'if [ ! -L out ];then ln -s ~/packages/AlpinePackages ./out;fi'
script{
def PkgArchs = ['x86_64', 'aarch64', 'armhf','armv7']
def PackageList = sh script: "cd AlpinePackages && ls -d */ | tr -d '/'", returnStdout: true
def NativeArch = sh script: "cat /etc/apk/arch | tr -d '\n'", returnStdout: true
env.NativeArch = NativeArch
def NativeArchNormalized = sh script: '''
case "$NativeArch" in
x86 | i[3456]86 | x86_64) printf 'x86';;
armhf | armv[4-9] | aarch64 ) printf 'arm';;
*) printf "$1";;
esac
''', returnStdout: true
for(PkgArch in PkgArchs){
env.NativeArchNormalized = NativeArchNormalized
env.PkgArch = PkgArch
def PkgArchNormalized = sh script: '''
case "$PkgArch" in
x86 | i[3456]86 | x86_64) printf 'x86';;
armhf | armv[4-9] | aarch64 ) printf 'arm';;
*) printf "$1";;
esac
''', returnStdout: true
if("${NativeArch}" == "${PkgArch}") {
println("Building ${PkgArch}(${PkgArchNormalized}) Native on ${NativeArch}(${NativeArchNormalized})")
sh 'doas apk update'
for(Package in PackageList.split()) {
env.Package = Package
env.PkgArch = PkgArch
stage("Build ${Package} on ${PkgArch}") {
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh '''
cd $WORKSPACE/AlpinePackages/$Package
abuild -r
'''
}
}
}
} else if("${NativeArchNormalized}" == "${PkgArchNormalized}") {
println("Building ${PkgArch} ${PkgArch}(${PkgArchNormalized}) Chrooted on ${NativeArch}(${NativeArchNormalized})")
sh '''
rm -rf /chroot/$PkgArch/home/jenkins/AlpinePackages
cp -r -p $WORKSPACE/AlpinePackages /chroot/$PkgArch/home/jenkins/AlpinePackages
doas chroot /chroot/$PkgArch /sbin/apk update
echo '#!/bin/ash
cd /home/jenkins/AlpinePackages/$1
doas -u jenkins abuild -r
' > /chroot/$PkgArch/home/jenkins/RunBuild.sh
chmod +x /chroot/$PkgArch/home/jenkins/RunBuild.sh
'''
for(Package in PackageList.split()) {
env.Package = Package
env.PkgArch = PkgArch
stage("Build ${Package} on ${PkgArch}") {
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh 'doas chroot /chroot/$PkgArch /home/jenkins/RunBuild.sh $Package'
}
}
}
} else{
println("Skipping ${PkgArch}(${PkgArchNormalized}) on ${NativeArch}(${NativeArchNormalized})")
}
}
stage("Collecting packages form ${NativeArchNormalized}") {
archiveArtifacts allowEmptyArchive: true, artifacts: 'out/**/*.apk', onlyIfSuccessful: true
}
}
}
}
}
}
}
}
}