From 3fa892dd24a1c935776fae7c1beb79a97b295371 Mon Sep 17 00:00:00 2001 From: jenkins Date: Tue, 18 Jun 2024 15:27:58 +0800 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index be4eec3..8178d5d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { app_name = "astro" label = "v1.6" images_repository = "${REGISTRY}/${project}/${app_name}" - image_name = "${REGISTRY}/${project}/${app_name}:${label}" + image_name = "${REGISTRY}/${project}/${app_name}" secret_name = "harbor" docker_registry_auth = "98195b64-dc71-42d6-899b-46dd4b566242" } @@ -26,15 +26,21 @@ pipeline { stage('SCM Checkout') { steps { git branch: "${GIT_BRANCH}", credentialsId: "${GIT_CREDENTIAL_ID}", url: "${GIT_URL}" + sh ('docker build -t ${image_name} .') } } stage('docker build & push') { steps { + // Login to Harbor using credentials withCredentials([usernamePassword(credentialsId: "${docker_registry_auth}", passwordVariable: 'password', usernameVariable: 'username')]) { - sh ('docker build -t ${image_name} .') + + // Tag the image + sh 'docker tag ${image_name} ${image_name}:v${BUILD_NUMBER}' + + // Push the image to Harbor sh ('echo "$DOCKER_PASSWORD" | docker login $images_repository -u "$DOCKER_USERNAME" --password-stdin') - sh ('docker push $image_name') + sh ('docker push ${image_name}:v${BUILD_NUMBER}') } } }