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