[aa5563b] | 1 | pipeline { |
---|
[6146538] | 2 | agent { label 'built-in' } |
---|
| 3 | |
---|
| 4 | options { |
---|
| 5 | timestamps() |
---|
| 6 | // Conserva la concurrencia como en el job original (no añadimos disableConcurrentBuilds) |
---|
| 7 | skipDefaultCheckout(true) // Haremos el checkout con los parámetros manualmente |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | parameters { |
---|
| 11 | string(name: 'OGLIVE_BUILDER_BRANCH', defaultValue: 'main', |
---|
| 12 | description: 'What branch of repository oglive-builder to work in.') |
---|
| 13 | string(name: 'OGCLONE_ENGINE_BRANCH', defaultValue: 'main', |
---|
| 14 | description: 'What branch of repository ogclone-engine to pick files from.') |
---|
| 15 | string(name: 'OGREPOSITORY_BRANCH', defaultValue: 'main', |
---|
| 16 | description: 'What branch of repository ogrepository to pick files from.') |
---|
| 17 | booleanParam(name: 'REUSE_PREV_FS', defaultValue: true, |
---|
| 18 | description: 'Whether to reuse the virtual filesystem from the previous build or to start from scratch.') |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | environment { |
---|
| 22 | CODENAME = 'noble' // Igual que en tu script actual (hardcoded) |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | stages { |
---|
| 26 | stage('Workspace cleanup (pre-build)') { |
---|
[6c25f76] | 27 | when { |
---|
[89491cd] | 28 | expression { return params.REUSE_PREV_FS == false } |
---|
[6c25f76] | 29 | } |
---|
| 30 | steps { |
---|
[6146538] | 31 | // Equivalente al PreBuildCleanup del plugin ws-cleanup |
---|
[f527d33] | 32 | cleanWs() |
---|
[6146538] | 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | stage('Checkout oglive-builder') { |
---|
| 37 | steps { |
---|
| 38 | checkout([ |
---|
| 39 | $class: 'GitSCM', |
---|
| 40 | userRemoteConfigs: [[ |
---|
| 41 | url: 'https://ognproject.evlt.uma.es/gitea/opengnsys/oglive-builder.git', |
---|
| 42 | credentialsId: 'gitea-unizar' |
---|
| 43 | ]], |
---|
| 44 | branches: [[ name: "refs/heads/${params.OGLIVE_BUILDER_BRANCH}" ]], |
---|
| 45 | extensions: [] |
---|
| 46 | ]) |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | stage('Build ogLive') { |
---|
| 51 | steps { |
---|
| 52 | sh '''#!/bin/bash |
---|
| 53 | set -euo pipefail |
---|
| 54 | export CODENAME="${CODENAME}" ## hardcoded at the moment |
---|
| 55 | |
---|
| 56 | echo ========================= Parameters |
---|
| 57 | echo OGLIVE_BUILDER_BRANCH=${OGLIVE_BUILDER_BRANCH} |
---|
| 58 | echo OGCLONE_ENGINE_BRANCH=${OGCLONE_ENGINE_BRANCH} |
---|
| 59 | echo OGREPOSITORY_BRANCH=${OGREPOSITORY_BRANCH} |
---|
| 60 | echo REUSE_PREV_FS=${REUSE_PREV_FS} |
---|
| 61 | echo CODENAME=${CODENAME} |
---|
| 62 | |
---|
| 63 | echo ========================= Clone/fetch clone-engine repo |
---|
| 64 | if [[ -d ogclone-engine-repo ]]; then |
---|
| 65 | cd ogclone-engine-repo; git fetch; git checkout "${OGCLONE_ENGINE_BRANCH}"; cd .. |
---|
| 66 | else |
---|
| 67 | git clone -c http.sslVerify=false --branch "${OGCLONE_ENGINE_BRANCH}" \ |
---|
| 68 | https://ognproject.evlt.uma.es/gitea/opengnsys/ogclone-engine.git ogclone-engine-repo |
---|
| 69 | fi |
---|
| 70 | HEAD=$(git --git-dir ./ogclone-engine-repo/.git rev-parse HEAD) |
---|
| 71 | echo "ogclone-engine HEAD: $HEAD" |
---|
| 72 | |
---|
| 73 | echo ========================= Clone/fetch ogrepository repo |
---|
| 74 | if [[ -d ogrepository-repo ]]; then |
---|
| 75 | cd ogrepository-repo; git fetch; git checkout "${OGREPOSITORY_BRANCH}"; cd .. |
---|
| 76 | else |
---|
| 77 | git clone -c http.sslVerify=false --branch "${OGREPOSITORY_BRANCH}" \ |
---|
| 78 | https://ognproject.evlt.uma.es/gitea/opengnsys/ogrepository.git ogrepository-repo |
---|
| 79 | fi |
---|
| 80 | HEAD=$(git --git-dir ./ogrepository-repo/.git rev-parse HEAD) |
---|
| 81 | echo "ogrepository HEAD: $HEAD" |
---|
| 82 | |
---|
| 83 | echo ========================= Take stuff out of the ogclone-engine repo |
---|
| 84 | mkdir -p shared |
---|
| 85 | mkdir -p engine |
---|
| 86 | cp -a ./ogclone-engine-repo/ogclient/{bin,etc,lib,scripts} shared/ |
---|
| 87 | cp -a ./ogclone-engine-repo/ogclient/lib/engine/bin engine/ |
---|
| 88 | git --git-dir ./ogclone-engine-repo/.git log --date format:r%Y%m%d --format=%ad.%h -1 > gitrelease |
---|
| 89 | |
---|
| 90 | echo ========================= Take stuff out of the ogrepository repo |
---|
| 91 | mkdir -p ogrepo-ssh-key |
---|
| 92 | cp ./ogrepository-repo/installer/ssh-keys/opengnsys ogrepo-ssh-key/ |
---|
| 93 | cp ./ogrepository-repo/installer/ssh-keys/opengnsys.pub ogrepo-ssh-key/ |
---|
| 94 | |
---|
| 95 | # echo ========================= Fetch deb packages from the artefacts server |
---|
| 96 | # AGENT_DEB=$(env - /bin/ls -t /mnt/srv/artefactos/ogagent/*.deb 2>/dev/null | head -n 1) |
---|
| 97 | # BROWSER_DEB=$(env - /bin/ls -t /mnt/srv/artefactos/ogbrowser/* | head -n 1) |
---|
| 98 | # echo "Found agent package '$AGENT_DEB' and browser package '$BROWSER_DEB'" |
---|
| 99 | # cp -vf $AGENT_DEB $BROWSER_DEB . |
---|
| 100 | |
---|
| 101 | echo ========================= Build docker image |
---|
| 102 | docker build --build-arg OPENGNSYS_HEAD="$HEAD" -t opengnsys/mkoglive . ## invalidate cache when $HEAD changes |
---|
| 103 | rm -rf shared engine gitrelease ogrepo-ssh-key |
---|
| 104 | |
---|
| 105 | echo ========================= Build ogLive |
---|
| 106 | if [[ "${REUSE_PREV_FS}" == "false" ]]; then |
---|
| 107 | echo "Not reusing old build" |
---|
| 108 | sudo chown user:user "$WORKSPACE/ogclient" || true |
---|
| 109 | rm -rf ogclient |
---|
| 110 | else |
---|
| 111 | echo "Reusing old build. In the following 'ls' output there should be something" |
---|
| 112 | ls -la ogclient/ || true |
---|
| 113 | fi |
---|
| 114 | mkdir -p ogclient ## run this as user; otherwise docker may create it as root |
---|
| 115 | if [[ "zuser" != "z$(stat --format %U ogclient)" ]]; then |
---|
| 116 | echo "warning: directory 'ogclient' not owned by user 'user'" |
---|
| 117 | fi |
---|
| 118 | |
---|
| 119 | docker run --rm --name mkoglive --privileged=true \ |
---|
| 120 | --volume "$PWD/ogclient:/var/lib/tftpboot/ogclient" \ |
---|
| 121 | opengnsys/mkoglive --codename "$CODENAME" --loglevel debug |
---|
| 122 | |
---|
| 123 | echo Uploading to the artefactos NFS share |
---|
| 124 | [[ -d /mnt/srv ]] || mount /mnt |
---|
| 125 | cp -av ogclient/ogLive-*.iso /mnt/srv/artefactos/oglive/ || true |
---|
| 126 | |
---|
| 127 | echo Cleaning up |
---|
| 128 | sudo chown jenkins:jenkins "$WORKSPACE/ogclient" || true |
---|
| 129 | rm -vf ogclient/ogclient.sqfs* ogclient/ogLive-*.iso ogclient/*.iso.sum ogclient/oginitrd.img* ogclient/ogvmlinuz* || true |
---|
| 130 | ''' |
---|
| 131 | } |
---|
[aa5563b] | 132 | } |
---|
[6146538] | 133 | } |
---|
| 134 | |
---|
| 135 | // Si te interesa conservar el ISO como artefacto de Jenkins, descomenta el 'post' siguiente y |
---|
| 136 | // mueve/duplica el borrado de ficheros para que ocurra después del archiveArtifacts. |
---|
| 137 | // post { |
---|
| 138 | // success { |
---|
| 139 | // archiveArtifacts artifacts: 'ogclient/ogLive-*.iso, ogclient/*.iso.sum', allowEmptyArchive: true |
---|
| 140 | // } |
---|
| 141 | // always { |
---|
| 142 | // wsCleanup() |
---|
| 143 | // } |
---|
| 144 | // } |
---|
| 145 | } |
---|