From 17d2289974da75385c74bc34c47cbb9ce99c4a84 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Mon, 16 Feb 2026 20:35:22 +0530 Subject: [PATCH 1/4] fix: correct agent label for production environment in Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a54e3ae..a539020 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,7 +82,7 @@ pipeline { def getAgentLabel() { if (env.BRANCH_NAME == 'prod') { - return 'oracle-node' + return 'oracle-prod' } else { return 'built-in' // for develop } -- 2.47.3 From 8de5d29a4d0b9fbe827adc419f2e0352a39239f8 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Fri, 6 Mar 2026 07:16:33 +0530 Subject: [PATCH 2/4] refactor: reorganize Jenkinsfile stages and improve environment variable handling --- Jenkinsfile | 185 +++++++++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 80 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a539020..4899b10 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,113 +1,138 @@ pipeline { - agent none +``` +agent none - options { - buildDiscarder(logRotator(numToKeepStr: '10')) - } +options { + buildDiscarder(logRotator(numToKeepStr: '10')) + disableConcurrentBuilds() +} - environment { - DEPLOY_PATH = getDeployPath() - ENV_FILE_ID = getEnvFileId() - TARGET_URL = getHealthUrl() - } +stages { - stages { + stage('Build') { + agent { label getAgentLabel() } - stage('Checkout') { - agent { label getAgentLabel() } - steps { - checkout scm + stages { + + stage('Cleanup Workspace') { + steps { + cleanWs() + } } - } - stage('Inject Environment File') { - agent { label getAgentLabel() } - steps { - configFileProvider( - [configFile( - fileId: ENV_FILE_ID, - targetLocation: 'src/environments/environment.ts', - replaceTokens: true - )] - ) { - echo "Environment file injected for ${env.BRANCH_NAME}" + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Inject Environment File') { + steps { + configFileProvider( + [configFile( + fileId: getEnvFileId(), + targetLocation: 'src/environments/environment.ts', + replaceTokens: true + )] + ) { + echo "Injected environment for ${env.BRANCH_NAME}" + } + } + } + + stage('Install & Build') { + steps { + sh ''' + npm ci + ng build --configuration production --base-href /admin/ + ''' } } } + } - stage('Build Angular') { - agent { label getAgentLabel() } - steps { - sh ''' - npm install - ng build --configuration production --base-href /admin/ - ''' - } + // 🚨 Production Approval Gate + stage('Production Approval') { + when { + branch 'prod' } - - stage('Deploy') { - agent { label getAgentLabel() } - steps { - sh ''' - rm -rf $DEPLOY_PATH/* - cp -r dist/portfolio-admin/browser/* $DEPLOY_PATH/ - sudo /usr/bin/systemctl reload nginx - ''' - } - } - - stage('Health Check') { - agent { label getAgentLabel() } - steps { - sh """ - sleep 2 - curl -f ${TARGET_URL} - """ - } + steps { + input message: "Approve deployment to PRODUCTION?", ok: "Deploy" } } - post { - failure { - echo "Deployment failed!" - } - success { - echo "Deployment successful!" + stage('Deploy & Verify') { + agent { label getAgentLabel() } + + stages { + + stage('Deploy') { + steps { + sh """ + rsync -av --delete dist/portfolio-admin/browser/ ${getDeployPath()}/ + sudo /usr/bin/systemctl reload nginx + """ + } + } + + stage('Health Check') { + steps { + sh """ + sleep 3 + curl -f ${getHealthUrl()} + """ + } + } + } } } +post { + success { + echo "✅ Deployment successful for ${env.BRANCH_NAME}" + } + failure { + echo "❌ Deployment failed for ${env.BRANCH_NAME}" + } +} +``` + +} + +// // -------- Helper Methods -------- +// def getAgentLabel() { - if (env.BRANCH_NAME == 'prod') { - return 'oracle-prod' - } else { - return 'built-in' // for develop - } +if (env.BRANCH_NAME == 'prod') { +return 'oracle-prod' +} else { +return 'built-in' +} } def getEnvFileId() { - if (env.BRANCH_NAME == 'prod') { - return 'admin-prod-properties' - } else { - return 'admin-uat-properties' - } +if (env.BRANCH_NAME == 'prod') { +return 'admin-prod-properties' +} else { +return 'admin-uat-properties' +} } def getDeployPath() { - if (env.BRANCH_NAME == 'prod') { - return "/var/www/bangararaju.kottedi.in/admin" - } else { - return "/var/www/bangararaju.kottedi.in/admin" - } +if (env.BRANCH_NAME == 'prod') { +return "/var/www/bangararaju.kottedi.in/admin" +} else { +return "/var/www/bangararaju.kottedi.in/admin" +} } def getHealthUrl() { - if (env.BRANCH_NAME == 'prod') { - return "https://bangararaju.kottedi.in/admin" - } else { - return "https://bangararaju-uat.kottedi.in/admin" - } +if (env.BRANCH_NAME == 'prod') { +return "https://bangararaju.kottedi.in/admin" +} else { +return "https://bangararaju-uat.kottedi.in/admin" +} } -- 2.47.3 From 85fe20d0f3fee8e16b294537f1cbb247bdfc57e6 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Fri, 6 Mar 2026 07:31:42 +0530 Subject: [PATCH 3/4] fix: remove unnecessary backticks from Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4899b10..b22f775 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,5 @@ pipeline { -``` agent none options { -- 2.47.3 From f33bf8cd0142fbb8b4554bafc1e8a3579c9952e0 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Fri, 6 Mar 2026 07:33:38 +0530 Subject: [PATCH 4/4] fix: remove unnecessary backticks from Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b22f775..440f3f0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -96,7 +96,6 @@ post { echo "❌ Deployment failed for ${env.BRANCH_NAME}" } } -``` } -- 2.47.3