|
1 | 1 | #!groovy |
2 | 2 |
|
3 | | -String[] distributions = ['debian:trixie', 'debian:forky', 'ubuntu:jammy', 'ubuntu:noble'] |
| 3 | +// Aktuální verze 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 | +] |
4 | 12 |
|
5 | 13 | String vendor = 'vitexsoftware' |
6 | | -String distribution = '' |
7 | | -//String distroFamily = '' |
8 | | -String distroCodename = '' |
9 | | -String ver = '' |
| 14 | +String imagePrefix = 'multiflexi-' |
10 | 15 |
|
11 | 16 | properties([ |
12 | 17 | copyArtifactPermission('*') |
13 | 18 | ]) |
14 | | -node() { |
| 19 | + |
| 20 | +node { |
15 | 21 | ansiColor('xterm') { |
16 | 22 | stage('SCM Checkout') { |
17 | 23 | checkout scm |
18 | 24 | } |
19 | 25 | } |
20 | 26 | } |
21 | 27 |
|
22 | | -distributions.each { |
23 | | - distribution = it |
24 | | - |
25 | | - println "Dist:" + distribution |
| 28 | +def branches = [:] |
26 | 29 |
|
27 | | - def dist = distribution.split(':') |
28 | | - distroCodename = dist[1] |
| 30 | +distributions.each { distro -> |
| 31 | + branches[distro] = { |
| 32 | + def (distroFamily, distroCode) = distro.split(':') |
| 33 | + def imageName = "${vendor}/${imagePrefix}${distroCode}:latest" |
| 34 | + def buildImage |
| 35 | + def artifacts = [] |
| 36 | + def buildVer |
29 | 37 |
|
30 | | - def buildImage = '' |
| 38 | + node { |
| 39 | + ansiColor('xterm') { |
| 40 | + stage("Checkout ${distro}") { |
| 41 | + checkout scm |
| 42 | + buildImage = docker.image(imageName) |
31 | 43 |
|
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}'", |
| 44 | + sh 'git checkout debian/changelog' |
| 45 | + buildVer = sh( |
| 46 | + script: "dpkg-parsechangelog --show-field Version", |
55 | 47 | returnStdout: true |
56 | | - ).trim().split('\n') |
| 48 | + ).trim() + ".${env.BUILD_NUMBER}~${distroCode}" |
| 49 | + } |
| 50 | + |
| 51 | + stage("Build ${distro}") { |
| 52 | + 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", |
| 66 | + returnStdout: true |
| 67 | + ).trim().split('\n') |
| 68 | + } |
57 | 69 | } |
58 | | - } |
59 | 70 |
|
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 |
| 71 | + stage("Test ${distro}") { |
| 72 | + 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 -> |
| 83 | + if (deb_file.endsWith('.deb')) { |
| 84 | + 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 | + """ |
| 95 | + } |
71 | 96 | } |
72 | 97 | } |
73 | 98 | } |
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' |
| 99 | + |
| 100 | + stage("Archive artifacts ${distro}") { |
| 101 | + buildImage.inside { |
| 102 | + artifacts.each { deb_file -> |
| 103 | + println "Archiving artifact: ${deb_file}" |
| 104 | + archiveArtifacts artifacts: "dist/debian/${deb_file}" |
| 105 | + } |
| 106 | + |
| 107 | + sh ''' |
| 108 | + set -e |
| 109 | + if [ -f debian/files ]; then |
| 110 | + while read -r file _; do |
| 111 | + [ -n "$file" ] || continue |
| 112 | + rm -f "dist/debian/$file" || true |
| 113 | + rm -f "../$file" || true |
| 114 | + rm -f "$WORKSPACE/$file" || true |
| 115 | + done < debian/files |
| 116 | + fi |
| 117 | + ''' |
81 | 118 | } |
82 | 119 | } |
| 120 | + |
83 | 121 | } |
84 | 122 | } |
85 | 123 | } |
86 | 124 | } |
87 | 125 |
|
| 126 | + |
| 127 | +parallel branches |
| 128 | + |
| 129 | +node { |
| 130 | + stage('Publish to Aptly') { |
| 131 | + publishDebToAptly() |
| 132 | + } |
| 133 | +} |
0 commit comments