From d85bb18afe9e85f0808c5f3a9e60ab15580ea652 Mon Sep 17 00:00:00 2001 From: dany Date: Sun, 1 Jan 2023 12:35:27 +0100 Subject: [PATCH] Add jenkinfiles --- Jenkinsfile | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..47cc11c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,99 @@ +// 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} AMD64") { + copyArtifacts(projectName: 'gitea-sync/antos/' + name, target: 'antos/frontend/' + name); + env.tag = name; + env.arch = x86_64 + sh''' + echo "Deploy antos webapps for version $tag on architecture $arch" + set -e + set -x + ''' + } + stage("ANTOS ${name} ARM64") { + copyArtifacts(projectName: 'gitea-sync/antos/' + name, target: 'antos/frontend/' + name); + env.tag = name; + env.arch = aarch64 + sh''' + echo "Deploy antos webapps for version $tag on architecture $arch" + set -e + set -x + ''' + } + stage("ANTOS ${name} ARM") { + copyArtifacts(projectName: 'gitea-sync/antos/' + name, target: 'antos/frontend/' + name); + env.tag = name; + env.arch = armv7l + sh''' + echo "Deploy antos webapps for version $tag on architecture $arch" + set -e + set -x + ''' + } + } +} + +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 + ''' + copyArtifacts(projectName: 'gitea-sync/antos-appimage/master', target: 'antos/'); + script + { + parallel parallelStagesMap; + } + sh''' + tree antos + ''' + } + } + } +} \ No newline at end of file