11#! groovy
22
3- // Current version of this Pipeline https://github.com/VitexSoftware/BuildImages/blob/main/Test/Jenkinsfile-parael
3+ // Current version of this Pipeline https://github.com/VitexSoftware/BuildImages/blob/main/Test/Jenkinsfile
44
5- String [] distributions = [
6- ' debian:bookworm' ,
7- ' debian:trixie' ,
8- ' debian:forky' ,
9- ' ubuntu:jammy' ,
10- ' ubuntu:noble'
11- ]
5+ String [] distributions = [' debian:bookworm' , ' debian:trixie' , ' debian:forky' , ' ubuntu:jammy' , ' ubuntu:noble' ]
126
137String vendor = ' vitexsoftware'
148// String distroFamily = ''
@@ -25,7 +19,6 @@ node() {
2519}
2620
2721def branches = [:]
28-
2922distributions. each { distro ->
3023 branches[distro] = {
3124 def distroName = distro
@@ -53,10 +46,22 @@ distributions.each { distro ->
5346 }
5447 stage(' Build ' + distroName) {
5548 buildImage. inside {
49+ // Set unique build directories for this parallel build to avoid conflicts
50+ def uniqueBuildId = env. BUILD_NUMBER + ' -' + distroCode + ' -' + env. EXECUTOR_NUMBER
51+ sh '''
52+ export DH_INTERNAL_BUILDDIR="/tmp/debhelper-build-''' + uniqueBuildId + ''' "
53+ export TMPDIR="/tmp/build-''' + uniqueBuildId + ''' "
54+ mkdir -p "$DH_INTERNAL_BUILDDIR" "$TMPDIR"
55+ '''
5656 sh ' dch -b -v ' + buildVer + ' "' + env. BUILD_TAG + ' "'
5757 sh ' sudo apt-get update --allow-releaseinfo-change'
5858 sh ' sudo chown jenkins:jenkins ..'
59- sh ' debuild-pbuilder -i -us -uc -b'
59+ sh ' sudo rm -rf debian/$(dpkg-parsechangelog --show-field Source)/ debian/.debhelper/ debian/tmp/'
60+ sh '''
61+ export DH_INTERNAL_BUILDDIR="/tmp/debhelper-build-''' + uniqueBuildId + ''' "
62+ export TMPDIR="/tmp/build-''' + uniqueBuildId + ''' "
63+ debuild-pbuilder -r"sudo -E" -i -us -uc -b
64+ '''
6065 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'
6166 artifacts = sh (
6267 script : " cat debian/files | awk '{print \$ 1}'" ,
@@ -72,14 +77,41 @@ distributions.each { distro ->
7277 sh ' echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
7378 sh ' sudo apt-get update --allow-releaseinfo-change'
7479 sh ' echo "INSTALATION"'
75- artifacts. each { deb_file ->
80+
81+ def installOrder = [
82+ // '',
83+ ]
84+
85+ def sorted_artifacts = artifacts. toList()
86+
87+ // If installOrder is empty, install all produced packages
88+ if (installOrder. isEmpty()) {
89+ sorted_artifacts. each { deb_file ->
7690 if (deb_file. endsWith(' .deb' )) {
7791 def pkgName = deb_file. tokenize(' /' )[-1 ]. replaceFirst(/ _.*/ , ' ' )
7892 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'
93+ sh ' sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName
94+ }
95+ }
96+ } else {
97+ // Install packages in specified order
98+ installOrder. each { pkgPrefix ->
99+ def debFile = null
100+ for (item in sorted_artifacts) {
101+ def itemStr = item. toString()
102+ if (itemStr. startsWith(pkgPrefix) && itemStr. endsWith(' .deb' )) {
103+ debFile = itemStr
104+ break
105+ }
106+ }
107+ if (debFile) {
108+ def pkgName = debFile. tokenize(' /' )[-1 ]. replaceFirst(/ _.*/ , ' ' )
109+ sh ' echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "'
110+ sh ' sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName
80111 }
81112 }
82113 }
114+
83115 }
84116 stage(' Archive artifacts ' + distroName ) {
85117 // Only run if previous stages (Build and Test) succeeded
@@ -92,6 +124,7 @@ distributions.each { distro ->
92124
93125 // Cleanup: remove any produced files named in debian/files
94126 // Try both the dist location and any potential original locations referenced by debian/files
127+ def uniqueBuildId = env. BUILD_NUMBER + ' -' + distroCode + ' -' + env. EXECUTOR_NUMBER
95128 sh '''
96129 set -e
97130 if [ -f debian/files ]; then
@@ -102,19 +135,22 @@ distributions.each { distro ->
102135 rm -f "$WORKSPACE/$file" || true
103136 done < debian/files
104137 fi
138+ # Cleanup temporary build directories
139+ rm -rf "/tmp/debhelper-build-''' + uniqueBuildId + ''' " || true
140+ rm -rf "/tmp/build-''' + uniqueBuildId + ''' " || true
105141 '''
106142 }
107143 }
108144 }
109145 }
110146 }
111147}
112-
148+ }
113149
114150parallel branches
115151
116152node {
117153 stage(' Publish to Aptly' ) {
118- publishDebToAptly()
154+ publishDebToAptly()
119155 }
120156}
0 commit comments