Trigger fresh Jenkins build

This commit is contained in:
VIPIN 2025-08-29 01:19:17 +05:30
parent ba0e4915f5
commit 8003e8992e

25
Jenkinsfile vendored
View File

@ -2,13 +2,14 @@ pipeline {
agent any agent any
tools { tools {
nodejs 'Node' // Make sure NodeJS installation in Jenkins Global Tool Config is named "Node" nodejs 'Node' // Ensure NodeJS installation in Jenkins Global Tool Config is named "Node"
} }
environment { environment {
WEB_IP = '13.49.223.142' // EC2 web server IP WEB_IP = '13.49.223.142' // EC2 web server IP
SSH_CRED = 'deploy-ec2-key' // Jenkins SSH key credential ID SSH_USER = 'deploy' // Deploy user
NODE_OPTIONS = "--max_old_space_size=512" // Prevent Node from consuming all memory SSH_KEY_PATH = '/home/ubuntu/.ssh/jenkins-deploy' // Path to private key on Jenkins server
NODE_OPTIONS = "--max_old_space_size=512"
} }
stages { stages {
@ -58,20 +59,17 @@ pipeline {
stage('Deploy') { stage('Deploy') {
steps { steps {
script { script {
// Use sshagent for passwordless deployment
sshagent([env.SSH_CRED]) {
sh """ sh """
echo "🚀 Deploying to ${WEB_IP}..." echo "🚀 Deploying to ${WEB_IP}..."
# Copy build archive to web server # Copy build to remote server
scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz scp -i ${SSH_KEY_PATH} -o StrictHostKeyChecking=no build.tar.gz ${SSH_USER}@${WEB_IP}:/tmp/build.tar.gz
# Extract and reload nginx (passwordless sudo) # Deploy remotely
ssh -o StrictHostKeyChecking=no deploy@${WEB_IP} ' ssh -i ${SSH_KEY_PATH} -o StrictHostKeyChecking=no ${SSH_USER}@${WEB_IP} '
sudo rm -rf /var/www/reactapp/* mkdir -p ~/reactapp
sudo mkdir -p /var/www/reactapp rm -rf ~/reactapp/*
sudo tar -xzf /tmp/build.tar.gz -C /var/www/reactapp tar -xzf /tmp/build.tar.gz -C ~/reactapp
sudo systemctl reload nginx
' '
echo "✅ Deployment finished" echo "✅ Deployment finished"
@ -80,7 +78,6 @@ pipeline {
} }
} }
} }
}
post { post {
success { echo "✅ Pipeline completed successfully" } success { echo "✅ Pipeline completed successfully" }