// need to approve all static functions in Dashboard > Manage Jenkins > ScriptApproval // method hudson.model.Item getAllJobs // method hudson.model.Item getName // method hudson.model.ItemGroup getItem java.lang.String // method hudson.model.ItemGroup getItems // method jenkins.model.Jenkins getItemByFullName java.lang.String // new java.util.ArrayList // staticMethod jenkins.model.Jenkins getInstance def ArrayList getBranches(projectName){ def jobs = jenkins.model.Jenkins.instance.getItemByFullName(projectName).getAllJobs(); Iterator iterator = jobs.iterator(); def arr = new ArrayList(); while (iterator.hasNext()) { def job = iterator.next(); arr.add(job.getName()); } return arr; } def generateStage(name) { return { stage("ANTOS ${name}") { env.tag = name; sh''' echo "Build AntOS deb package for version $tag on architecture $arch" set -e set -x ./build_deb.sh $tag $arch ''' } } } def parallelStagesMap = getBranches("gitea-sync/antos").collectEntries { ["${it}" : generateStage(it)] } pipeline{ agent { node{ label'workstation' }} options { // Limit build history with buildDiscarder option: // daysToKeepStr: history is only kept up to this many days. // numToKeepStr: only this many build logs are kept. // artifactDaysToKeepStr: artifacts are only kept up to this many days. // artifactNumToKeepStr: only this many builds have their artifacts kept. buildDiscarder(logRotator(numToKeepStr: "1")) // Enable timestamps in build log console timestamps() // Maximum time to run the whole pipeline before canceling it timeout(time: 3, unit: 'HOURS') // Use Jenkins ANSI Color Plugin for log console ansiColor('xterm') // Limit build concurrency to 1 per branch disableConcurrentBuilds() } stages { stage('Prepare binaries') { steps { sh''' [ -d build ] && rm -rf build mkdir build [ -d antos ] && rm -rf antos mkdir antos ''' copyArtifacts(projectName: 'gitea-sync/antos-appimage/master', target: 'antos/'); sh''' ls -al antos ''' } } stage("AMD64") { agent { docker { image 'xsangle/ci-tools:bionic-amd64' reuseNode true } } steps { script { env.arch = "x86_64"; parallel parallelStagesMap; } } } stage("ARM64") { agent { docker { image 'xsangle/ci-tools:bionic-arm64' reuseNode true } } steps { script { env.arch = "aarch64"; parallel parallelStagesMap; } } } stage("ARM") { agent { docker { image 'xsangle/ci-tools:bionic-arm' reuseNode true } } steps { script { env.arch = "armv7l"; parallel parallelStagesMap; } } } stage('Archive') { steps { script { archiveArtifacts artifacts: 'build/', fingerprint: true } sh''' cp -rf build/* /home/dany/public/antos-release/binaries/deb ''' } } } }