refactor: encapsulate Docker build and tag logic within a script block in Jenkinsfile.

main
Cizz22 3 weeks ago
parent 421642495e
commit 5105219a4d

12
Jenkinsfile vendored

@ -54,11 +54,15 @@ pipeline {
stage('Build & Tag') { stage('Build & Tag') {
steps { steps {
withCredentials([string(credentialsId: GITEA_ID, variable: 'GITEA_TOKEN')]) { withCredentials([string(credentialsId: GITEA_ID, variable: 'GITEA_TOKEN')]) {
def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" // Logic and variable definitions go inside 'script'
sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ." script {
def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}"
if (SECONDARY_TAG) { sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ."
sh "docker tag ${fullImageName}:${IMAGE_TAG} ${fullImageName}:${SECONDARY_TAG}"
if (SECONDARY_TAG) {
sh "docker tag ${fullImageName}:${IMAGE_TAG} ${fullImageName}:${SECONDARY_TAG}"
}
} }
} }
} }

Loading…
Cancel
Save