|
1 | 1 | #!groovy |
2 | 2 |
|
| 3 | +// Current version of this Pipeline https://github.com/VitexSoftware/BuildImages/blob/main/Test/Jenkinsfile-parael |
3 | 4 |
|
4 | | -String repoUrl = 'https://github.com/raspberrypi/rpi-imager.git' |
5 | | -String repoBranch = 'qml' // scm.userRemoteConfigs[0].branch |
| 5 | +String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble'] |
6 | 6 |
|
7 | | -String[] architectures = ['amd64', 'aarch64', 'armhf'] |
8 | | -String[] distributions = ['debian:bullseye', 'debian:bookworm', 'ubuntu:focal', 'ubuntu:jammy'] // 'debian:buster' |
9 | | - |
10 | | -String imageVendor = 'vitexsoftware' |
11 | | -String distribution = '' |
12 | | -String architecture = '' |
13 | | -String distroCodename = '' |
14 | | -String ver = '' |
| 7 | +String vendor = 'vitexsoftware' |
| 8 | +String imagePrefix = 'multiflexi-' |
| 9 | +//String distroFamily = '' |
15 | 10 |
|
16 | 11 | properties([ |
17 | 12 | copyArtifactPermission('*') |
18 | 13 | ]) |
19 | 14 | node() { |
20 | 15 | ansiColor('xterm') { |
21 | 16 | stage('SCM Checkout') { |
22 | | - checkout([$class: 'GitSCM', branches: [[name: '*/' + repoBranch ]], extensions: [], userRemoteConfigs: [[url: repoUrl]]]) |
23 | | - def control = readFile(file: env.WORKSPACE + '/debian/control') |
24 | | - def lines = control.readLines() |
25 | | - for (line in lines) { |
26 | | - if (line.trim()) { |
27 | | - def (key,value) = line.split(': ').collect { it.trim() } |
28 | | - if (key == 'Architecture') { |
29 | | - if (value == 'any') { |
30 | | - architectures = ['amd64', 'armhf', 'aarch64'] |
31 | | - } else { |
32 | | - architectures = [value] |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - } |
| 17 | + checkout scm |
37 | 18 | } |
38 | 19 | } |
39 | 20 | } |
40 | 21 |
|
41 | | -architectures.each { |
42 | | - architecture = it |
43 | | - |
44 | | - println 'Arch: ' + architecture |
| 22 | +def branches = [:] |
| 23 | +distributions.each { distro -> |
| 24 | + branches[distro] = { |
| 25 | + def distroName = distro |
| 26 | + println "Dist:" + distroName |
45 | 27 |
|
46 | | - distributions.each { |
47 | | - distribution = it |
| 28 | + def dist = distroName.split(':') |
| 29 | + def distroCode = dist[1] |
| 30 | + def buildImage = '' |
| 31 | + def artifacts = [] |
| 32 | + def buildVer = '' |
48 | 33 |
|
49 | | - println 'Dist:' + distribution |
50 | | - |
51 | | - def String dist = distribution.split(':') |
52 | | - // distroFamily = dist[0] |
53 | | - distroCodename = dist[1] |
54 | | - |
55 | | - def String buildImage = '' |
56 | | - |
57 | | - node(architecture) { |
| 34 | + node { |
58 | 35 | ansiColor('xterm') { |
59 | | - stage('Checkout ' + architecture + ' ' + distribution) { |
60 | | - buildImage = docker.image(imageVendor + '/' + distribution) |
61 | | - sh 'cd ' + env.WORKSPACE + '; ls -la; pwd' |
| 36 | + stage('Checkout ' + distroName) { |
| 37 | + checkout scm |
| 38 | + def imageName = vendor + '/' + imagePrefix + distroCode + ':latest' |
| 39 | + buildImage = docker.image(imageName) |
62 | 40 | sh 'git checkout debian/changelog' |
63 | | - def String pkgVer = sh( |
| 41 | + def version = sh ( |
64 | 42 | script: 'dpkg-parsechangelog --show-field Version', |
65 | 43 | returnStdout: true |
66 | 44 | ).trim() |
67 | | - ver = pkgVer + '~' + distroCodename + '~' + env.BUILD_NUMBER |
| 45 | + buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode |
68 | 46 | } |
69 | | - stage('Build ' + architecture + ' ' + distribution) { |
| 47 | + stage('Build ' + distroName) { |
70 | 48 | buildImage.inside { |
71 | | - sh 'dch -b -v ' + ver + ' "' + env.BUILD_TAG + '"' |
| 49 | + sh 'dch -b -v ' + buildVer + ' "' + env.BUILD_TAG + '"' |
72 | 50 | sh 'sudo apt-get update --allow-releaseinfo-change' |
73 | | - // sh 'sudo apt install -y libgnutls28-dev' |
74 | 51 | sh 'sudo chown jenkins:jenkins ..' |
75 | 52 | sh 'debuild-pbuilder -i -us -uc -b' |
76 | 53 | sh 'mkdir -p $WORKSPACE/dist/debian/ ; rm -rf $WORKSPACE/dist/debian/* ; for deb in $(cat debian/files | awk \'{print $1}\'); do mv "../$deb" $WORKSPACE/dist/debian/; done' |
| 54 | + artifacts = sh ( |
| 55 | + script: "cat debian/files | awk '{print \$1}'", |
| 56 | + returnStdout: true |
| 57 | + ).trim().split('\n') |
77 | 58 | } |
78 | 59 | } |
79 | 60 |
|
80 | | - stage('Test ' + architecture + ' ' + distribution) { |
| 61 | + stage('Test ' + distroName) { |
81 | 62 | buildImage.inside { |
82 | 63 | def debconf_debug = 0 //Set to "5" or "developer" to debug debconf |
83 | | - sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz; cd $WORKSPACE' |
| 64 | + sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz; cd $WORKSPACE' |
84 | 65 | sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list' |
85 | 66 | sh 'sudo apt-get update --allow-releaseinfo-change' |
86 | 67 | sh 'echo "INSTALATION"' |
87 | | - sh 'IFS="\n\b"; for package in `cat debian/files | awk -F_ \'{print \$1}\'` ; do echo -e "${GREEN} installing ${package} on `lsb_release -sc` ${ENDCOLOR} " ; sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install $WORKSPACE/dist/debian/$package ; done;' |
88 | | - stash includes: 'dist/**', name: 'dist-' + distroCodename |
| 68 | + artifacts.each { deb_file -> |
| 69 | + if (deb_file.endsWith('.deb')) { |
| 70 | + def pkgName = deb_file.tokenize('/')[-1].replaceFirst(/_.*/, '') |
| 71 | + sh 'echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "' |
| 72 | + sh 'sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName + ' || sudo apt-get -y -f install' |
| 73 | + } |
| 74 | + } |
89 | 75 | } |
90 | 76 | } |
91 | | - stage('Copy artifacts ' + architecture + ' ' + distribution ) { |
| 77 | + stage('Archive artifacts ' + distroName ) { |
| 78 | + // Only run if previous stages (Build and Test) succeeded |
92 | 79 | buildImage.inside { |
93 | | - sh 'mv $WORKSPACE/dist/debian/*.deb $WORKSPACE' |
| 80 | + // Archive all produced artifacts listed in debian/files |
| 81 | + artifacts.each { deb_file -> |
| 82 | + println "Archiving artifact: " + deb_file |
| 83 | + archiveArtifacts artifacts: 'dist/debian/' + deb_file |
| 84 | + } |
| 85 | + |
| 86 | + // Cleanup: remove any produced files named in debian/files |
| 87 | + // Try both the dist location and any potential original locations referenced by debian/files |
| 88 | + sh ''' |
| 89 | + set -e |
| 90 | + if [ -f debian/files ]; then |
| 91 | + while read -r file _; do |
| 92 | + [ -n "$file" ] || continue |
| 93 | + rm -f "dist/debian/$file" || true |
| 94 | + rm -f "../$file" || true |
| 95 | + rm -f "$WORKSPACE/$file" || true |
| 96 | + done < debian/files |
| 97 | + fi |
| 98 | + ''' |
94 | 99 | } |
95 | 100 | } |
96 | 101 | } |
97 | 102 | } |
98 | 103 | } |
99 | 104 | } |
| 105 | +parallel branches |
0 commit comments