From 62563442c3183e8664c106926980c3c15c2782b1 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Mon, 13 Jan 2025 13:50:16 +0700 Subject: [PATCH] f --- Jenkinsfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 33dafa1..0548ed3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,21 +38,21 @@ pipeline { script { // Build with commit hash tag def commitHash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - sh ''' + sh """ docker build -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest . docker tag ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${commitHash} - ''' + """ } } } stage('Push to Docker Hub') { steps { - sh ''' + sh """ # Push both tags docker push ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${commitHash} docker push ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest - ''' + """ } } } @@ -65,17 +65,18 @@ pipeline { // Clean up local images script { try { - sh ''' - docker rmi ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${GIT_COMMIT_HASH} + sh """ + # Push both tags + docker rmi ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${commitHash} docker rmi ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest - ''' + """ } catch (err) { echo "Failed to clean up images: ${err}" } } } success { - echo "Successfully built and pushed Docker image with tags: latest and ${GIT_COMMIT_HASH}" + echo "Successfully built and pushed Docker image with tags: latest and ${commitHash}" } failure { echo 'Failed to build/push Docker image!'