From b17f820236f54cc0ae8b9a641fec207f78c378b8 Mon Sep 17 00:00:00 2001 From: The_Spider Date: Thu, 31 Mar 2022 07:03:20 -0500 Subject: [PATCH] updates to declarative pipeline --- build-minecraft.jenkins | 116 ++++++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 40 deletions(-) diff --git a/build-minecraft.jenkins b/build-minecraft.jenkins index b815533..0cedc7b 100644 --- a/build-minecraft.jenkins +++ b/build-minecraft.jenkins @@ -1,11 +1,37 @@ +#!groovy + def repository = "registry.c.test-chamber-13.lan" def repositoryCreds = "harbor-repository-creds" -def paperVersion = "1.18.1" -def memoryMin = "1g" -def memoryMax = "48g" +def workspace +def dockerFile +def paperVersion +def memoryMin +def memoryMax -def dockerFile = """FROM registry.c.test-chamber-13.lan/library/alpine:latest as builder +def label = "kubernetes-${UUID.randomUUID().toString()}" +def templateName = "pipeline-worker" +pipeline { + agent { + kubernetes { + yaml functions.podYaml( + repo: repository, + templateName: templateName, + kaniko: true, + alpine: true + ) + } + } + + stages { + stage ('Initalize Jenkins') { + steps { + script { + workspace = pwd() + paperVersion = "1.18.2" + memoryMin = "1g" + memoryMax = "48g" + dockerFile = """FROM registry.c.test-chamber-13.lan/library/alpine:latest as builder ARG paperDownload @@ -31,44 +57,54 @@ WORKDIR /minecraft/data ENTRYPOINT ["/usr/bin/java", "-Xms${memoryMin}", "-Xmx${memoryMax}", "-jar"] CMD ["../paper-mc.jar"] """ - -def label = "kubernetes-${UUID.randomUUID().toString()}" -def templateName = "pipeline-worker" -podTemplate( - label: label, - name: templateName, - yaml: functions.podYaml( - repo: repository, - templateName: templateName, - kaniko: true, - alpine: true - ) -) { - node (label) { - def workspace = pwd() - - stage ("Get Paper-MC Version") { - container ("alpine") { - sh "apk add --no-cache curl jq" - paperDownload = sh ( - script: """ - paperBuild=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion} | jq '.builds | max') - paperFile=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild} | jq '.downloads.application.name') - echo https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild}/downloads/\${paperFile} - """, - returnStdout: true - ).trim() + } } } - functions.buildContainer( - repository: repository, - imageDest: "${repository}/library/minecraft:latest", - dockerFile: dockerFile, - repoCreds: repositoryCreds, - [ - "paperDownload=${paperDownload}" - ] - ) + stage ("Get Paper-MC Version") { + steps { + container ("alpine") { + script { + sh """ + if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then + apk add --no-cache curl + fi + if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then + apk add --no-cache jq + fi + """ + paperDownload = sh ( + script: """ + paperBuild=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion} | jq '.builds | max') + paperFile=\$(curl --silent --location --fail https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild} | jq '.downloads.application.name') + echo https://nexus.c.test-chamber-13.lan/repository/paper-io/api/v2/projects/paper/versions/${paperVersion}/builds/\${paperBuild}/downloads/\${paperFile} + """, + returnStdout: true + ).trim() + } + } + } + } + + stage ('Build & Push') { + steps { + container ('kaniko') { + script { + declarativeFunctions.buildContainerMultipleDestinations( + dockerFile: dockerFile, + repositoryAccess: [ + [ + repository: repository, + credentials: repositoryCreds + ], + ], + destination: [ + "${repository}/library/minecraft:latest", + ] + ) + } + } + } + } } }