diff --git a/Jenkinsfile b/Jenkinsfile index 2559cb0..2d43bd4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,6 @@ pipeline { environment { DOCKER_HUB_USERNAME = 'aimodocker' // This creates DOCKER_AUTH_USR and DOCKER_AUTH_PSW - DOCKER_AUTH = credentials('aimodocker') IMAGE_NAME = 'lcca-service' SERVICE_NAME = 'ahm-app' @@ -55,13 +54,6 @@ pipeline { // } // } - stage('Docker Login') { - steps { - // Fixed variable names based on the 'DOCKER_AUTH' environment key - sh "echo ${DOCKER_AUTH_PSW} | docker login -u ${DOCKER_AUTH_USR} --password-stdin" - } - } - stage('Build & Tag') { steps { script { @@ -75,14 +67,19 @@ pipeline { } } - stage('Push to Docker Hub') { + stage('Docker Login & Push') { steps { script { def fullImageName = "${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" - sh "docker push ${fullImageName}:${IMAGE_TAG}" - - if (SECONDARY_TAG) { - sh "docker push ${fullImageName}:${SECONDARY_TAG}" + withCredentials([usernamePassword(credentialsId: 'aimodocker', passwordVariable: 'DOCKER_PSW', usernameVariable: 'DOCKER_USR')]) { + // Use single quotes to prevent Groovy from interpolating the secret in logs + sh 'echo $DOCKER_PSW | docker login -u $DOCKER_USR --password-stdin' + + sh "docker push ${fullImageName}:${IMAGE_TAG}" + + if (SECONDARY_TAG) { + sh "docker push ${fullImageName}:${SECONDARY_TAG}" + } } } }