Skip to content

Commit e2b86e1

Browse files
committed
build pipelines update
1 parent 13a6771 commit e2b86e1

2 files changed

Lines changed: 95 additions & 73 deletions

File tree

debian/Jenkinsfile

Lines changed: 87 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
#!groovy
22

3-
// Aktuální verze 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

137
String vendor = 'vitexsoftware'
14-
String imagePrefix = 'multiflexi-'
8+
//String distroFamily = ''
159

1610
properties([
1711
copyArtifactPermission('*')
1812
])
19-
20-
node {
13+
node() {
2114
ansiColor('xterm') {
2215
stage('SCM Checkout') {
2316
checkout scm
@@ -26,84 +19,112 @@ node {
2619
}
2720

2821
def branches = [:]
29-
3022
distributions.each { distro ->
3123
branches[distro] = {
32-
def (distroFamily, distroCode) = distro.split(':')
33-
def imageName = "${vendor}/${imagePrefix}${distroCode}:latest"
34-
def buildImage
24+
def distroName = distro
25+
println "Dist:" + distroName
26+
27+
def dist = distroName.split(':')
28+
def distroFamily = dist[0]
29+
def distroCode = dist[1]
30+
def buildImage = ''
3531
def artifacts = []
36-
def buildVer
32+
def buildVer = ''
3733

3834
node {
3935
ansiColor('xterm') {
40-
stage("Checkout ${distro}") {
36+
stage('Checkout ' + distroName) {
4137
checkout scm
38+
def imageName = vendor + '/' + distro
4239
buildImage = docker.image(imageName)
43-
4440
sh 'git checkout debian/changelog'
45-
buildVer = sh(
46-
script: "dpkg-parsechangelog --show-field Version",
41+
def version = sh (
42+
script: 'dpkg-parsechangelog --show-field Version',
4743
returnStdout: true
48-
).trim() + ".${env.BUILD_NUMBER}~${distroCode}"
44+
).trim()
45+
buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode
4946
}
50-
51-
stage("Build ${distro}") {
47+
stage('Build ' + distroName) {
5248
buildImage.inside {
53-
sh """
54-
dch -b -v ${buildVer} "${env.BUILD_TAG}"
55-
sudo apt-get update --allow-releaseinfo-change
56-
sudo chown jenkins:jenkins ..
57-
debuild-pbuilder -i -us -uc -b
58-
mkdir -p \$WORKSPACE/dist/debian/
59-
rm -rf \$WORKSPACE/dist/debian/*
60-
for deb in \$(awk '{print \$1}' debian/files); do
61-
mv "../\$deb" \$WORKSPACE/dist/debian/
62-
done
63-
"""
64-
artifacts = sh(
65-
script: "awk '{print \$1}' debian/files",
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+
'''
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 '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+
'''
65+
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'
66+
artifacts = sh (
67+
script: "cat debian/files | awk '{print \$1}'",
6668
returnStdout: true
6769
).trim().split('\n')
6870
}
6971
}
7072

71-
stage("Test ${distro}") {
73+
stage('Test ' + distroName) {
7274
buildImage.inside {
73-
def debconf_debug = 0
74-
sh """
75-
cd \$WORKSPACE/dist/debian/
76-
dpkg-scanpackages . /dev/null > Packages
77-
gzip -9c Packages > Packages.gz
78-
cd \$WORKSPACE
79-
echo "deb [trusted=yes] file://///\$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list
80-
sudo apt-get update --allow-releaseinfo-change
81-
"""
82-
artifacts.each { deb_file ->
75+
def debconf_debug = 0 //Set to "5" or "developer" to debug debconf
76+
sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz; cd $WORKSPACE'
77+
sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
78+
sh 'sudo apt-get update --allow-releaseinfo-change'
79+
sh 'echo "INSTALATION"'
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 ->
8390
if (deb_file.endsWith('.deb')) {
8491
def pkgName = deb_file.tokenize('/')[-1].replaceFirst(/_.*/, '')
85-
def distroCodename = sh(
86-
script: "lsb_release -sc",
87-
returnStdout: true
88-
).trim()
89-
echo "Installing ${pkgName} on ${distroCodename}"
90-
sh """
91-
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=${debconf_debug} \
92-
apt-get -y install ${pkgName} \
93-
|| sudo apt-get -y -f install
94-
"""
92+
sh 'echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "'
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
95111
}
96112
}
97113
}
98-
}
99114

100-
stage("Archive artifacts ${distro}") {
115+
}
116+
stage('Archive artifacts ' + distroName ) {
117+
// Only run if previous stages (Build and Test) succeeded
101118
buildImage.inside {
119+
// Archive all produced artifacts listed in debian/files
102120
artifacts.each { deb_file ->
103-
println "Archiving artifact: ${deb_file}"
104-
archiveArtifacts artifacts: "dist/debian/${deb_file}"
121+
println "Archiving artifact: " + deb_file
122+
archiveArtifacts artifacts: 'dist/debian/' + deb_file
105123
}
106124

125+
// Cleanup: remove any produced files named in debian/files
126+
// Try both the dist location and any potential original locations referenced by debian/files
127+
def uniqueBuildId = env.BUILD_NUMBER + '-' + distroCode + '-' + env.EXECUTOR_NUMBER
107128
sh '''
108129
set -e
109130
if [ -f debian/files ]; then
@@ -114,20 +135,22 @@ distributions.each { distro ->
114135
rm -f "$WORKSPACE/$file" || true
115136
done < debian/files
116137
fi
138+
# Cleanup temporary build directories
139+
rm -rf "/tmp/debhelper-build-''' + uniqueBuildId + '''" || true
140+
rm -rf "/tmp/build-''' + uniqueBuildId + '''" || true
117141
'''
118142
}
119143
}
120-
121144
}
122145
}
123146
}
124147
}
125-
148+
}
126149

127150
parallel branches
128151

129152
node {
130153
stage('Publish to Aptly') {
131-
publishDebToAptly()
154+
publishDebToAptly()
132155
}
133156
}

debian/Jenkinsfile.release

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!groovy
22

3-
// Current version of this Pipeline https://raw.githubusercontent.com/VitexSoftware/multiflexi-buildimages/refs/heads/main/Test/multiflexi-halloworld/Jenkinsfile
4-
53
String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble']
64

75
String vendor = 'vitexsoftware'
@@ -14,6 +12,7 @@ properties([
1412
node() {
1513
ansiColor('xterm') {
1614
stage('SCM Checkout') {
15+
sh 'sudo chown -R jenkins:jenkins . || true'
1716
checkout scm
1817
}
1918
}
@@ -34,8 +33,9 @@ distributions.each { distro ->
3433
node {
3534
ansiColor('xterm') {
3635
stage('Checkout ' + distroName) {
36+
sh 'sudo chown -R jenkins:jenkins . || true'
3737
checkout scm
38-
def imageName = vendor + '/' + imagePrefix + distroCode + ':latest'
38+
def imageName = vendor + '/' + imagePrefix + dist[0] + ':' + distroCode
3939
buildImage = docker.image(imageName)
4040
sh 'git checkout debian/changelog'
4141
def version = sh (
@@ -45,11 +45,11 @@ distributions.each { distro ->
4545
buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode
4646
}
4747
stage('Build ' + distroName) {
48-
buildImage.inside {
48+
buildImage.inside('--ipc=host') {
4949
sh 'dch -b -v ' + buildVer + ' "' + env.BUILD_TAG + '"'
5050
sh 'sudo apt-get update --allow-releaseinfo-change'
51-
sh 'sudo chown jenkins:jenkins ..'
52-
sh 'debuild-pbuilder -i -us -uc -b'
51+
sh 'sudo chown -R jenkins:jenkins . ..'
52+
sh 'debuild-pbuilder -r"sudo -E" -i -us -uc -b'
5353
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'
5454
artifacts = sh (
5555
script: "cat debian/files | awk '{print \$1}'",
@@ -59,7 +59,7 @@ distributions.each { distro ->
5959
}
6060

6161
stage('Test ' + distroName) {
62-
buildImage.inside {
62+
buildImage.inside('--ipc=host') {
6363
def debconf_debug = 0 //Set to "5" or "developer" to debug debconf
6464
sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz; cd $WORKSPACE'
6565
sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
@@ -75,13 +75,12 @@ distributions.each { distro ->
7575
}
7676
stage('Archive artifacts ' + distroName ) {
7777
// Only run if previous stages (Build and Test) succeeded
78-
buildImage.inside {
78+
buildImage.inside('--ipc=host') {
7979
// Archive all produced artifacts listed in debian/files
8080
artifacts.each { deb_file ->
8181
println "Archiving artifact: " + deb_file
8282
archiveArtifacts artifacts: 'dist/debian/' + deb_file
8383
}
84-
8584
// Cleanup: remove any produced files named in debian/files
8685
// Try both the dist location and any potential original locations referenced by debian/files
8786
sh '''

0 commit comments

Comments
 (0)