From 2ccdf70d9b57dbcc9714c84be57635e3c1e9c364 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Mon, 13 Jan 2025 13:25:46 +0700 Subject: [PATCH] fix jenkins ci/cd --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0e3f032..9dcb7f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,6 @@ pipeline { // Replace with your image name IMAGE_NAME = 'oh-service' // Variable for Git commit hash - GIT_COMMIT_HASH = '' } stages { @@ -36,6 +35,10 @@ pipeline { steps { script { // Build with commit hash tag + if (!GIT_COMMIT_HASH) { + GIT_COMMIT_HASH = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + sh ''' docker build -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${GIT_COMMIT_HASH} . docker tag ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${GIT_COMMIT_HASH} ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest