From cf07732b36907b6f4d2226b0117caa165b994a93 Mon Sep 17 00:00:00 2001 From: VIPIN Date: Thu, 28 Aug 2025 21:42:03 +0530 Subject: [PATCH] Trigger fresh Jenkins build --- Jenkinsfile | 82 ++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e887000..1da6021 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,82 +2,80 @@ pipeline { agent any tools { - nodejs 'Node' // Jenkins -> Global Tool Config -> NodeJS must be named "Node" + nodejs 'Node' // Name of your NodeJS installation in Jenkins } environment { - WEB_IP = '13.49.223.142' // update if EC2 IP changes - SSH_CRED = 'deploy-ec2-key' // Jenkins credential ID for your EC2 SSH key - NODE_OPTIONS = "--max_old_space_size=512" // prevent Node from eating all memory + WEB_IP = '13.49.223.142' // EC2 Web server IP + SSH_CRED = 'deploy-ec2-key' // Jenkins credential ID for SSH key + NODE_OPTIONS = "--max_old_space_size=512" // Limit Node memory + } + + options { + ansiColor('xterm') // Colorized console logs + timestamps() // Show timestamps in console + timeout(time: 30, unit: 'MINUTES') // Fail build if it hangs } stages { stage('Checkout') { steps { + echo "🔄 Checking out code..." checkout scm } } - stage('Install') { + stage('Install Dependencies') { steps { - sh ''' - echo "📦 Installing dependencies..." - npm install - ''' + echo "📦 Installing npm dependencies..." + sh 'npm ci' } } stage('Build') { steps { - sh ''' - echo "🏗️ Building project..." - npm run build - ''' + echo "🏗️ Building project..." + sh 'npm run build' } } - stage('Package') { + stage('Package Build') { steps { - sh ''' - OUT_DIR="build" - [ -d dist ] && OUT_DIR="dist" - - if [ ! -d "$OUT_DIR" ]; then - echo "❌ ERROR: No build output found (build/ or dist/)" - ls -la - exit 1 - fi - + script { + def outDir = fileExists('dist') ? 'dist' : 'build' + if (!fileExists(outDir)) { + error "❌ Build output not found in 'build/' or 'dist/'!" + } echo "📦 Packaging build output..." - tar -czf build.tar.gz -C "$OUT_DIR" . - ''' - archiveArtifacts artifacts: 'build.tar.gz' + sh "tar -czf build.tar.gz -C ${outDir} ." + archiveArtifacts artifacts: 'build.tar.gz' + } } } stage('Deploy') { steps { - sshagent(credentials: [env.SSH_CRED]) { - sh ''' - echo "🚀 Deploying to ${WEB_IP} ..." - scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz - - ssh -o StrictHostKeyChecking=no deploy@${WEB_IP} ' - sudo rm -rf /var/www/reactapp/*; - sudo mkdir -p /var/www/reactapp; - sudo tar -xzf /tmp/build.tar.gz -C /var/www/reactapp; - sudo systemctl reload nginx - ' - - echo "✅ Deployment finished" - ''' + script { + sshagent(credentials: [env.SSH_CRED]) { + echo "🚀 Deploying build to ${WEB_IP}..." + sh """ + scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz + ssh -o StrictHostKeyChecking=no deploy@${WEB_IP} ' + sudo rm -rf /var/www/reactapp/* + sudo mkdir -p /var/www/reactapp + sudo tar -xzf /tmp/build.tar.gz -C /var/www/reactapp + sudo systemctl reload nginx + ' + """ + echo "✅ Deployment finished!" + } } } } } post { - success { echo "✅ Pipeline completed successfully" } + success { echo "🎉 Pipeline completed successfully!" } failure { echo "❌ Pipeline failed — check console log" } } }