From dee7e6b12b1060f5953a0c63aa5809c39f06435c Mon Sep 17 00:00:00 2001 From: adelyaou Date: Wed, 22 Oct 2025 16:02:07 +0700 Subject: [PATCH] fix: checkout application repo stage --- Jenkinsfile | 57 ++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1e5cbad..8787a7b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,6 @@ pipeline { REGISTRY = "docker.io/adelyao" APP_NAME = "employee" MANIFEST_REPO = "https://git.winteraccess.id/adel/Employee-manifest.git" - APP_REPO = "https://git.winteraccess.id/adel/Employee-app.git" MANIFEST_CRED_ID = "GIT_CRED_ID" DOCKER_CRED_ID = "DOCKER_CRED_ID" BRANCH = "main" @@ -17,9 +16,10 @@ pipeline { stages { - stage('Clean Workspace') { + stage('Prepare Workspace') { steps { cleanWs() + checkout scm // ✅ otomatis clone repo Gitea tempat Jenkinsfile berada } } @@ -38,36 +38,24 @@ pipeline { } } - stage('Checkout Application Repo') { + stage('Build and Push Docker Images') { steps { - dir('app') { - git branch: env.BRANCH, - url: env.APP_REPO, - credentialsId: env.MANIFEST_CRED_ID - } - } - } + script { + def tag = params.IMAGE_TAG ?: "build-${env.BUILD_NUMBER}" + echo "Building and pushing image with tag: ${tag}" - stage('Build and Push Docker Image') { - steps { - dir('app') { - script { - def tag = params.IMAGE_TAG ?: "build-${env.BUILD_NUMBER}" - echo "Building and pushing image with tag: ${tag}" - - withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { - sh """ - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin - docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be - docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./employee-fe - docker push ${REGISTRY}/${APP_NAME}-be:${tag} - docker push ${REGISTRY}/${APP_NAME}-fe:${tag} - docker logout - """ - } - - env.IMAGE_TAG_FINAL = tag + withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { + sh """ + echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin + docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be + docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./employee-fe + docker push ${REGISTRY}/${APP_NAME}-be:${tag} + docker push ${REGISTRY}/${APP_NAME}-fe:${tag} + docker logout + """ } + + env.IMAGE_TAG_FINAL = tag } } } @@ -77,7 +65,10 @@ pipeline { dir('manifest') { checkout([$class: 'GitSCM', branches: [[name: env.BRANCH]], - userRemoteConfigs: [[url: env.MANIFEST_REPO, credentialsId: env.MANIFEST_CRED_ID]] + userRemoteConfigs: [[ + url: env.MANIFEST_REPO, + credentialsId: env.MANIFEST_CRED_ID + ]] ]) } } @@ -108,7 +99,7 @@ pipeline { git add -A git diff --staged --quiet || (git commit -m "chore: update image to ${env.IMAGE_TAG_FINAL}" && git push https://${GIT_USER}:${GIT_PASS}@${env.MANIFEST_REPO.replace('https://', '')} ${env.BRANCH}) """ - echo "Manifest repo updated successfully" + echo "✅ Manifest repo updated successfully" } } } @@ -123,10 +114,10 @@ pipeline { post { success { - echo "GitOps pipeline completed successfully!" + echo "🎉 GitOps pipeline completed successfully!" } failure { - echo "Pipeline failed. Check previous logs." + echo "❌ Pipeline failed. Check previous logs." } } }