|
| 1 | +#!groovy |
| 2 | + |
| 3 | +// Current version of this Pipeline https://raw.githubusercontent.com/VitexSoftware/multiflexi-buildimages/refs/heads/main/Test/multiflexi-halloworld/Jenkinsfile |
| 4 | + |
| 5 | +String[] distributions = ['debian:bookworm', 'debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble'] |
| 6 | + |
| 7 | +String vendor = 'vitexsoftware' |
| 8 | +String imagePrefix = 'multiflexi-' |
| 9 | +//String distroFamily = '' |
| 10 | + |
| 11 | +properties([ |
| 12 | + copyArtifactPermission('*') |
| 13 | +]) |
| 14 | +node() { |
| 15 | + ansiColor('xterm') { |
| 16 | + stage('SCM Checkout') { |
| 17 | + checkout scm |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +def branches = [:] |
| 23 | +distributions.each { distro -> |
| 24 | + branches[distro] = { |
| 25 | + def distroName = distro |
| 26 | + println "Dist:" + distroName |
| 27 | + |
| 28 | + def dist = distroName.split(':') |
| 29 | + def distroCode = dist[1] |
| 30 | + def buildImage = '' |
| 31 | + def artifacts = [] |
| 32 | + def buildVer = '' |
| 33 | + |
| 34 | + node { |
| 35 | + ansiColor('xterm') { |
| 36 | + stage('Checkout ' + distroName) { |
| 37 | + checkout scm |
| 38 | + def imageName = vendor + '/' + imagePrefix + distroCode + ':latest' |
| 39 | + buildImage = docker.image(imageName) |
| 40 | + sh 'git checkout debian/changelog' |
| 41 | + def version = sh ( |
| 42 | + script: 'dpkg-parsechangelog --show-field Version', |
| 43 | + returnStdout: true |
| 44 | + ).trim() |
| 45 | + buildVer = version + '.' + env.BUILD_NUMBER + '~' + distroCode |
| 46 | + } |
| 47 | + stage('Build ' + distroName) { |
| 48 | + buildImage.inside { |
| 49 | + sh 'dch -b -v ' + buildVer + ' "' + env.BUILD_TAG + '"' |
| 50 | + sh 'sudo apt-get update --allow-releaseinfo-change' |
| 51 | + sh 'sudo chown jenkins:jenkins ..' |
| 52 | + sh 'debuild-pbuilder -i -us -uc -b' |
| 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') |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + stage('Test ' + distroName) { |
| 62 | + buildImage.inside { |
| 63 | + def debconf_debug = 0 //Set to "5" or "developer" to debug debconf |
| 64 | + sh 'cd $WORKSPACE/dist/debian/ ; dpkg-scanpackages . /dev/null > Packages; gzip -9c Packages > Packages.gz; cd $WORKSPACE' |
| 65 | + sh 'echo "deb [trusted=yes] file://///$WORKSPACE/dist/debian/ ./" | sudo tee /etc/apt/sources.list.d/local.list' |
| 66 | + sh 'sudo apt-get update --allow-releaseinfo-change' |
| 67 | + sh 'echo "INSTALATION"' |
| 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 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + stage('Archive artifacts ' + distroName ) { |
| 78 | + // Only run if previous stages (Build and Test) succeeded |
| 79 | + buildImage.inside { |
| 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 | + ''' |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | +parallel branches |
| 106 | + |
| 107 | +if (!currentBuild.result || currentBuild.result == 'SUCCESS') { |
| 108 | + build job: 'MultiFlexi-publish', |
| 109 | + wait: false, |
| 110 | + parameters: [ |
| 111 | + string(name: 'UPSTREAM_JOB', value: env.JOB_NAME), |
| 112 | + string(name: 'UPSTREAM_BUILD', value: env.BUILD_NUMBER), |
| 113 | + string(name: 'REMOTE_SSH', value: 'multirepo@repo.multiflexi.eu'), |
| 114 | + string(name: 'REMOTE_REPO_DIR', value: '/srv/repo'), |
| 115 | + string(name: 'COMPONENT', value: 'main'), |
| 116 | + string(name: 'DEB_DIST', value: '') |
| 117 | + ] |
| 118 | +} |
0 commit comments