From 5105219a4d03d572fc6734dc94aecc388e5c4e71 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Thu, 19 Feb 2026 12:03:46 +0700 Subject: [PATCH] refactor: encapsulate Docker build and tag logic within a script block in Jenkinsfile. --- Jenkinsfile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 360b549..9861249 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,11 +54,15 @@ pipeline { stage('Build & Tag') { steps { withCredentials([string(credentialsId: GITEA_ID, variable: 'GITEA_TOKEN')]) { - def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" - sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ." - - if (SECONDARY_TAG) { - sh "docker tag ${fullImageName}:${IMAGE_TAG} ${fullImageName}:${SECONDARY_TAG}" + // Logic and variable definitions go inside 'script' + script { + def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" + + sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ." + + if (SECONDARY_TAG) { + sh "docker tag ${fullImageName}:${IMAGE_TAG} ${fullImageName}:${SECONDARY_TAG}" + } } } }