// 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}") { copyArtifacts(projectName: 'gitea-sync/antos/' + name, target: 'antos/frontend/' + name); env.tag = name; sh''' echo "Deploy antos webapps for version $tag" set -e set -x cp -rfv antos/webapps/build/opt/www/htdocs/os antos/frontend/$tag/build/opt/www/htdocs # mv antos/frontend/$tag/build/opt/www/htdocs/os/mimes.json antos/frontend/$tag/build/opt/www/htdocs/ # release antos doc [ -d "/home/dany/public/antos-release/doc/$tag" ] && rm -rf /home/dany/public/antos-release/doc/$tag || true [ -d "antos/frontend/$tag/doc" ] && cp -rf antos/frontend/$tag/doc /home/dany/public/antos-release/doc/$tag || true # release antos sdk [ -d "/home/dany/public/antos-release/sdk/$tag" ] && rm -rf /home/dany/public/antos-release/sdk/$tag || true [ -d "antos/frontend/$tag/d.ts" ] && cp -rf antos/frontend/$tag/d.ts /home/dany/public/antos-release/sdk/$tag || true echo $tag >> /home/dany/public/antos-release/sdk/versions.txt ''' } } } 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 -p antos/frontend mkdir -p antos/backend mkdir -p antos/webapps cat /dev/null > /home/dany/public/antos-release/sdk/versions.txt ''' copyArtifacts(projectName: 'gitea-sync/ant-http/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/antd-fcgi-plugin/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/luafcgi/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/antd-tunnel-plugin/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/antd-wvnc-plugin/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/antd-tunnel-publishers/master', target: 'antos/backend'); copyArtifacts(projectName: 'luasocket', target: 'antos/backend'); copyArtifacts(projectName: 'luasec', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/silk/master', target: 'antos/backend'); copyArtifacts(projectName: 'gitea-sync/antos-backend/master', target: 'antos/webapps'); script { parallel parallelStagesMap; } sh''' mv antos/frontend/master antos/frontend/latest # clean up servies find antos/ -name "systemd" -exec rm -rv {} +; # header files find antos/ -name "include" -exec rm -rv {} +; # .la files find antos/ -name "*.la" -type f -delete tree antos ''' } } stage('Build AMD64') { steps { sh''' cd $WORKSPACE for file in antos/frontend/*; do echo "Building for AMD64 version $tag" ./mkimg.sh amd64 $(basename $file) done ''' } } stage('Build arm64') { steps { sh''' cd $WORKSPACE for file in antos/frontend/*; do echo "Building for arm64 version $tag" ./mkimg.sh arm64 $(basename $file) done ''' } } stage('Build arm') { steps { sh''' cd $WORKSPACE for file in antos/frontend/*; do echo "Building for arm version $tag" ./mkimg.sh arm $(basename $file) done ''' } } stage('Archive') { steps { script { archiveArtifacts artifacts: 'build/', fingerprint: true } sh''' cp -rf build/* /home/dany/public/antos-release/binaries ''' } } } }