Skip to content

Commit 3d3b37d

Browse files
committed
Jenkinsfile update
1 parent 0a13c37 commit 3d3b37d

File tree

1 file changed

+87
-54
lines changed

1 file changed

+87
-54
lines changed

debian/Jenkinsfile

Lines changed: 87 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!groovy
22

3-
String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble']
3+
// Current version of this Pipeline https://github.com/VitexSoftware/BuildImages/blob/main/Test/Jenkinsfile-parael
4+
5+
String[] distributions = [
6+
'debian:bookworm',
7+
'debian:trixie',
8+
'debian:forky',
9+
'ubuntu:jammy',
10+
'ubuntu:noble'
11+
]
412

513
String vendor = 'vitexsoftware'
6-
String distribution = ''
714
//String distroFamily = ''
8-
String distroCodename = ''
9-
String ver = ''
1015

1116
properties([
1217
copyArtifactPermission('*')
@@ -19,69 +24,97 @@ node() {
1924
}
2025
}
2126

22-
distributions.each {
23-
distribution = it
24-
25-
println "Dist:" + distribution
27+
def branches = [:]
2628

27-
def dist = distribution.split(':')
28-
distroCodename = dist[1]
29+
distributions.each { distro ->
30+
branches[distro] = {
31+
def distroName = distro
32+
println "Dist:" + distroName
2933

30-
def buildImage = ''
34+
def dist = distroName.split(':')
35+
def distroFamily = dist[0]
36+
def distroCode = dist[1]
37+
def buildImage = ''
38+
def artifacts = []
39+
def buildVer = ''
3140

32-
def artifacts = []
33-
34-
node {
35-
ansiColor('xterm') {
36-
stage('Checkout ' + distribution) {
37-
checkout scm
38-
buildImage = docker.image(vendor + '/' + distribution)
39-
sh 'git checkout debian/changelog'
40-
def version = sh (
41-
script: 'dpkg-parsechangelog --show-field Version',
42-
returnStdout: true
43-
).trim()
44-
ver = version + '.' + env.BUILD_NUMBER + '~' + distroCodename
45-
}
46-
stage('Build ' + distribution) {
47-
buildImage.inside {
48-
sh 'dch -b -v ' + ver + ' "' + env.BUILD_TAG + '"'
49-
sh 'sudo apt-get update --allow-releaseinfo-change'
50-
sh 'sudo chown jenkins:jenkins ..'
51-
sh 'debuild-pbuilder -i -us -uc -b'
52-
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'
53-
artifacts = sh (
54-
script: "cat debian/files | awk '{print \$1}'",
41+
node {
42+
ansiColor('xterm') {
43+
stage('Checkout ' + distroName) {
44+
checkout scm
45+
def imageName = vendor + '/' + distro
46+
buildImage = docker.image(imageName)
47+
sh 'git checkout debian/changelog'
48+
def version = sh (
49+
script: 'dpkg-parsechangelog --show-field Version',
5550
returnStdout: true
56-
).trim().split('\n')
51+
).trim()
52+
buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode
53+
}
54+
stage('Build ' + distroName) {
55+
buildImage.inside {
56+
sh 'dch -b -v ' + buildVer + ' "' + env.BUILD_TAG + '"'
57+
sh 'sudo apt-get update --allow-releaseinfo-change'
58+
sh 'sudo chown jenkins:jenkins ..'
59+
sh 'debuild-pbuilder -i -us -uc -b'
60+
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'
61+
artifacts = sh (
62+
script: "cat debian/files | awk '{print \$1}'",
63+
returnStdout: true
64+
).trim().split('\n')
65+
}
5766
}
58-
}
5967

60-
stage('Test ' + distribution) {
61-
buildImage.inside {
62-
def debconf_debug = 0 //Set to "5" or "developer" to debug debconf
63-
sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz; cd $WORKSPACE'
64-
sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
65-
sh 'sudo apt-get update --allow-releaseinfo-change'
66-
sh 'echo "INSTALATION"'
67-
artifacts.each { deb_file ->
68-
if (deb_file.endsWith('.deb')) {
69-
sh 'echo -e "${GREEN} installing ' + deb_file + ' on `lsb_release -sc` ${ENDCOLOR} "'
70-
sh 'sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install $WORKSPACE/dist/debian/' + deb_file
68+
stage('Test ' + distroName) {
69+
buildImage.inside {
70+
def debconf_debug = 0 //Set to "5" or "developer" to debug debconf
71+
sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz; cd $WORKSPACE'
72+
sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
73+
sh 'sudo apt-get update --allow-releaseinfo-change'
74+
sh 'echo "INSTALATION"'
75+
artifacts.each { deb_file ->
76+
if (deb_file.endsWith('.deb')) {
77+
def pkgName = deb_file.tokenize('/')[-1].replaceFirst(/_.*/, '')
78+
sh 'echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "'
79+
sh 'sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName + ' || sudo apt-get -y -f install'
80+
}
7181
}
7282
}
7383
}
74-
}
75-
stage('Copy artifacts ' + distribution ) {
76-
buildImage.inside {
77-
artifacts.each { deb_file ->
78-
println "Copying artifact: " + deb_file
79-
archiveArtifacts artifacts: 'dist/debian/' + deb_file
80-
sh 'cp $WORKSPACE/dist/debian/' + deb_file + ' $WORKSPACE'
84+
stage('Archive artifacts ' + distroName ) {
85+
// Only run if previous stages (Build and Test) succeeded
86+
buildImage.inside {
87+
// Archive all produced artifacts listed in debian/files
88+
artifacts.each { deb_file ->
89+
println "Archiving artifact: " + deb_file
90+
archiveArtifacts artifacts: 'dist/debian/' + deb_file
91+
}
92+
93+
// Cleanup: remove any produced files named in debian/files
94+
// Try both the dist location and any potential original locations referenced by debian/files
95+
sh '''
96+
set -e
97+
if [ -f debian/files ]; then
98+
while read -r file _; do
99+
[ -n "$file" ] || continue
100+
rm -f "dist/debian/$file" || true
101+
rm -f "../$file" || true
102+
rm -f "$WORKSPACE/$file" || true
103+
done < debian/files
104+
fi
105+
'''
81106
}
82107
}
83108
}
84109
}
85110
}
86111
}
87112

113+
114+
parallel branches
115+
116+
node {
117+
stage('Publish to Aptly') {
118+
publishDebToAptly()
119+
}
120+
}

0 commit comments

Comments
 (0)