Skip to content

Commit cd3bca9

Browse files
committed
resolute build
1 parent 7dd3568 commit cd3bca9

2 files changed

Lines changed: 98 additions & 66 deletions

File tree

debian/Jenkinsfile

Lines changed: 97 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
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

55
String[] distributions = [
6-
'debian:bookworm',
7-
'debian:trixie',
8-
'debian:forky',
9-
'ubuntu:jammy',
10-
'ubuntu:noble'
6+
'debian:bookworm',
7+
'debian:trixie',
8+
'debian:forky',
9+
'ubuntu:jammy',
10+
'ubuntu:noble',
11+
'ubuntu:resolute',
1112
]
1213

1314
String vendor = 'vitexsoftware'
14-
String imagePrefix = 'multiflexi-'
15+
//String distroFamily = ''
1516

1617
properties([
1718
copyArtifactPermission('*'),
@@ -22,94 +23,123 @@ properties([
2223
blockingJobs: 'RebulidDEBRepoByAnsible'
2324
)
2425
])
25-
26-
node {
26+
node() {
2727
ansiColor('xterm') {
2828
stage('SCM Checkout') {
29+
sh 'sudo chown -R jenkins:jenkins . 2>/dev/null || true'
2930
checkout scm
3031
}
3132
}
3233
}
3334

3435
def branches = [:]
35-
3636
distributions.each { distro ->
3737
branches[distro] = {
38-
def (distroFamily, distroCode) = distro.split(':')
39-
def imageName = "${vendor}/${imagePrefix}${distroCode}:latest"
40-
def buildImage
38+
def distroName = distro
39+
println "Dist:" + distroName
40+
41+
def dist = distroName.split(':')
42+
def distroFamily = dist[0]
43+
def distroCode = dist[1]
44+
def buildImage = ''
4145
def artifacts = []
42-
def buildVer
46+
def buildVer = ''
4347

4448
node {
4549
ansiColor('xterm') {
46-
stage("Checkout ${distro}") {
50+
stage('Checkout ' + distroName) {
51+
sh 'sudo chown -R jenkins:jenkins . 2>/dev/null || true'
4752
checkout scm
53+
def imageName = vendor + '/' + distro
4854
buildImage = docker.image(imageName)
49-
5055
sh 'git checkout debian/changelog'
51-
buildVer = sh(
52-
script: "dpkg-parsechangelog --show-field Version",
56+
def version = sh (
57+
script: 'dpkg-parsechangelog --show-field Version',
5358
returnStdout: true
54-
).trim() + ".${env.BUILD_NUMBER}~${distroCode}"
59+
).trim()
60+
buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode
5561
}
56-
57-
stage("Build ${distro}") {
58-
buildImage.inside('--ipc=host') {
59-
sh """
60-
dch -b -v ${buildVer} "${env.BUILD_TAG}"
61-
sudo apt-get update --allow-releaseinfo-change
62-
sudo chown -R jenkins:jenkins . ..
63-
debuild-pbuilder -r'sudo -E' -i -us -uc -b
64-
mkdir -p \$WORKSPACE/dist/debian/
65-
rm -rf \$WORKSPACE/dist/debian/*
66-
for deb in \$(awk '{print \$1}' debian/files); do
67-
mv "../\$deb" \$WORKSPACE/dist/debian/
68-
done
69-
"""
70-
artifacts = sh(
71-
script: "awk '{print \$1}' debian/files",
62+
stage('Build ' + distroName) {
63+
buildImage.inside {
64+
// Set unique build directories for this parallel build to avoid conflicts
65+
def uniqueBuildId = env.BUILD_NUMBER + '-' + distroCode + '-' + env.EXECUTOR_NUMBER
66+
sh '''
67+
export DH_INTERNAL_BUILDDIR="/tmp/debhelper-build-''' + uniqueBuildId + '''"
68+
export TMPDIR="/tmp/build-''' + uniqueBuildId + '''"
69+
mkdir -p "$DH_INTERNAL_BUILDDIR" "$TMPDIR"
70+
'''
71+
sh 'dch -b -v ' + buildVer + ' "' + env.BUILD_TAG + '"'
72+
sh 'sudo apt-get update --allow-releaseinfo-change'
73+
sh 'sudo chown jenkins:jenkins ..'
74+
sh 'sudo rm -rf debian/$(dpkg-parsechangelog --show-field Source)/ debian/.debhelper/ debian/tmp/'
75+
sh '''
76+
export DH_INTERNAL_BUILDDIR="/tmp/debhelper-build-''' + uniqueBuildId + '''"
77+
export TMPDIR="/tmp/build-''' + uniqueBuildId + '''"
78+
debuild-pbuilder -r"sudo -E" -i -us -uc -b
79+
'''
80+
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'
81+
artifacts = sh (
82+
script: "cat debian/files | awk '{print \$1}'",
7283
returnStdout: true
7384
).trim().split('\n')
7485
}
7586
}
7687

77-
stage("Test ${distro}") {
78-
buildImage.inside('--ipc=host') {
79-
def debconf_debug = 0
80-
sh """
81-
cd \$WORKSPACE/dist/debian/
82-
dpkg-scanpackages . /dev/null > Packages
83-
gzip -9c Packages > Packages.gz
84-
cd \$WORKSPACE
85-
echo "deb [trusted=yes] file://///\$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list
86-
sudo apt-get update --allow-releaseinfo-change
87-
"""
88-
artifacts.each { deb_file ->
88+
stage('Test ' + distroName) {
89+
buildImage.inside {
90+
def debconf_debug = 0 //Set to "5" or "developer" to debug debconf
91+
sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz; cd $WORKSPACE'
92+
sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list'
93+
sh 'sudo apt-get update --allow-releaseinfo-change'
94+
sh 'echo "INSTALATION"'
95+
96+
def installOrder = [
97+
// '',
98+
]
99+
100+
def sorted_artifacts = artifacts.toList()
101+
102+
// If installOrder is empty, install all produced packages
103+
if (installOrder.isEmpty()) {
104+
sorted_artifacts.each { deb_file ->
89105
if (deb_file.endsWith('.deb')) {
90106
def pkgName = deb_file.tokenize('/')[-1].replaceFirst(/_.*/, '')
91-
def distroCodename = sh(
92-
script: "lsb_release -sc",
93-
returnStdout: true
94-
).trim()
95-
echo "Installing ${pkgName} on ${distroCodename}"
96-
sh """
97-
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=${debconf_debug} \
98-
apt-get -y install ${pkgName} \
99-
|| sudo apt-get -y -f install
100-
"""
107+
sh 'echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "'
108+
sh 'sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName
109+
}
110+
}
111+
} else {
112+
// Install packages in specified order
113+
installOrder.each { pkgPrefix ->
114+
def debFile = null
115+
for (item in sorted_artifacts) {
116+
def itemStr = item.toString()
117+
if (itemStr.startsWith(pkgPrefix) && itemStr.endsWith('.deb')) {
118+
debFile = itemStr
119+
break
120+
}
121+
}
122+
if (debFile) {
123+
def pkgName = debFile.tokenize('/')[-1].replaceFirst(/_.*/, '')
124+
sh 'echo -e "${GREEN} installing ' + pkgName + ' on `lsb_release -sc` ${ENDCOLOR} "'
125+
sh 'sudo DEBIAN_FRONTEND=noninteractive DEBCONF_DEBUG=' + debconf_debug + ' apt-get -y install ' + pkgName
101126
}
102127
}
103128
}
104-
}
105129

106-
stage("Archive artifacts ${distro}") {
107-
buildImage.inside('--ipc=host') {
130+
}
131+
stage('Archive artifacts ' + distroName ) {
132+
// Only run if previous stages (Build and Test) succeeded
133+
buildImage.inside {
134+
// Archive all produced artifacts listed in debian/files
108135
artifacts.each { deb_file ->
109-
println "Archiving artifact: ${deb_file}"
110-
archiveArtifacts artifacts: "dist/debian/${deb_file}"
136+
println "Archiving artifact: " + deb_file
137+
archiveArtifacts artifacts: 'dist/debian/' + deb_file
111138
}
112139

140+
// Cleanup: remove any produced files named in debian/files
141+
// Try both the dist location and any potential original locations referenced by debian/files
142+
def uniqueBuildId = env.BUILD_NUMBER + '-' + distroCode + '-' + env.EXECUTOR_NUMBER
113143
sh '''
114144
set -e
115145
if [ -f debian/files ]; then
@@ -120,20 +150,22 @@ distributions.each { distro ->
120150
rm -f "$WORKSPACE/$file" || true
121151
done < debian/files
122152
fi
153+
# Cleanup temporary build directories
154+
rm -rf "/tmp/debhelper-build-''' + uniqueBuildId + '''" || true
155+
rm -rf "/tmp/build-''' + uniqueBuildId + '''" || true
123156
'''
124157
}
125158
}
126-
127159
}
128160
}
129161
}
130162
}
131-
163+
}
132164

133165
parallel branches
134166

135167
node {
136168
stage('Publish to Aptly') {
137-
publishDebToAptly()
169+
publishDebToAptly()
138170
}
139171
}

debian/Jenkinsfile.release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!groovy
22

3-
String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble']
3+
String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble', 'ubuntu:resolute']
44

55
String vendor = 'vitexsoftware'
66
String imagePrefix = 'multiflexi-'

0 commit comments

Comments
 (0)