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

main
Cizz22 3 weeks ago
parent 421642495e
commit 5105219a4d

4
Jenkinsfile vendored

@ -54,7 +54,10 @@ 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')]) {
// Logic and variable definitions go inside 'script'
script {
def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}"
sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ." sh "docker build --build-arg GITEA_TOKEN=${GITEA_TOKEN} -t ${fullImageName}:${IMAGE_TAG} ."
if (SECONDARY_TAG) { if (SECONDARY_TAG) {
@ -63,6 +66,7 @@ pipeline {
} }
} }
} }
}
stage('Push to Docker Hub') { stage('Push to Docker Hub') {
steps { steps {

Loading…
Cancel
Save