Trigger fresh Jenkins build

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

35
Jenkinsfile vendored
View File

@ -2,13 +2,14 @@ pipeline {
agent any
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 {
WEB_IP = '13.49.223.142' // EC2 web server IP
SSH_CRED = 'deploy-ec2-key' // Jenkins SSH key credential ID
NODE_OPTIONS = "--max_old_space_size=512" // Prevent Node from consuming all memory
SSH_USER = 'deploy' // Deploy user
SSH_KEY_PATH = '/home/ubuntu/.ssh/jenkins-deploy' // Path to private key on Jenkins server
NODE_OPTIONS = "--max_old_space_size=512"
}
stages {
@ -58,25 +59,21 @@ pipeline {
stage('Deploy') {
steps {
script {
// Use sshagent for passwordless deployment
sshagent([env.SSH_CRED]) {
sh """
echo "🚀 Deploying to ${WEB_IP}..."
sh """
echo "🚀 Deploying to ${WEB_IP}..."
# Copy build archive to web server
scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz
# Copy build to remote server
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)
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
'
# Deploy remotely
ssh -i ${SSH_KEY_PATH} -o StrictHostKeyChecking=no ${SSH_USER}@${WEB_IP} '
mkdir -p ~/reactapp
rm -rf ~/reactapp/*
tar -xzf /tmp/build.tar.gz -C ~/reactapp
'
echo "✅ Deployment finished"
"""
}
echo "✅ Deployment finished"
"""
}
}
}