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