Refactor Jenkinsfile (same structure as in PaperDockerBuilder)

This commit is contained in:
Marc Baloup 2024-01-18 17:29:26 +01:00
parent d5e743c6e3
commit bb5e7d7557

43
Jenkinsfile vendored
View File

@ -4,50 +4,55 @@ Required plugins in Jenkins:
- Docker Pipeline - Docker Pipeline
*/ */
def geyser_version def app_version
def geyser_build def app_build
def runnable_jar def url_download
def app_filename
def docker_tag def docker_tag
def docker_tag_latest def docker_tag_latest
pipeline { pipeline {
agent any agent any
environment { environment {
URL_BUILD = 'https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest' URL_BASE = 'https://download.geysermc.org/v2/projects/geyser/versions'
URL_DOWNLOAD = "${URL_BUILD}/downloads/standalone" URL_BUILD_INFOS = "${URL_BASE}/latest/builds/latest"
DOCKER_TAG_BASE = 'cr.pandacube.fr/geyser' DOCKER_TAG_BASE = 'cr.pandacube.fr/geyser'
DOCKER_CR_PANDACUBE_CREDENTIALS = 'cr-pandacube-credentials' DOCKER_REGISTRY_URL = 'https://cr.pandacube.fr'
DOCKER_REGISTRY_CREDENTIALS = 'cr-pandacube-credentials'
} }
stages { stages {
stage('Get build data') { stage('Get build data') {
steps { steps {
sh 'curl -L -s $URL_BUILD -o build_infos.json' sh "curl -L -s '$URL_BUILD_INFOS' -o build_infos.json"
script { script {
def build_infos = readJSON file: 'build_infos.json' def build_infos = readJSON file: 'build_infos.json'
geyser_version = build_infos.version
geyser_build = build_infos.build app_version = build_infos.version
runnable_jar = "Geyser-${geyser_version}-${geyser_build}.jar" app_build = build_infos.build
docker_tag = "${DOCKER_TAG_BASE}:${geyser_version}-${geyser_build}" url_download = "${URL_BASE}/${app_version}/builds/${app_build}/downloads/standalone"
app_filename = "Geyser-${app_version}-${app_build}.jar"
docker_tag = "${DOCKER_TAG_BASE}:${app_version}-${app_build}"
docker_tag_latest = "${DOCKER_TAG_BASE}:latest" docker_tag_latest = "${DOCKER_TAG_BASE}:latest"
} }
echo "Geyser version ${geyser_version} build #${geyser_build}" echo "Geyser version ${app_version} build #${app_build}"
} }
} }
stage('Download jar') { stage('Download jar') {
steps { steps {
echo "From $URL_DOWNLOAD" sh "curl -L -o '$app_filename' '$URL_DOWNLOAD'"
echo "To $runnable_jar"
sh "curl -L -o '$runnable_jar' '$URL_DOWNLOAD'"
} }
} }
stage('Build Docker image') { stage('Build Docker image') {
steps { steps {
script { script {
docker.build(docker_tag, "--build-arg RUNNABLE_JAR=$runnable_jar .") docker.build(docker_tag, "--build-arg RUNNABLE_JAR=$app_filename .")
} }
sh "docker tag ${docker_tag} ${docker_tag_latest}" sh "docker tag ${docker_tag} ${docker_tag_latest}"
} }
@ -56,7 +61,7 @@ pipeline {
stage('Push Docker image') { stage('Push Docker image') {
steps { steps {
script { script {
docker.withRegistry('https://cr.pandacube.fr', DOCKER_CR_PANDACUBE_CREDENTIALS) { docker.withRegistry(DOCKER_REGISTRY_URL, DOCKER_REGISTRY_CREDENTIALS) {
docker.image(docker_tag).push() docker.image(docker_tag).push()
docker.image(docker_tag_latest).push() docker.image(docker_tag_latest).push()
} }
@ -65,8 +70,8 @@ pipeline {
} }
} }
post { post {
always { cleanup {
cleanWs() cleanWs()
} }
} }