Trigger fresh Jenkins build

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

39
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,25 +59,21 @@ pipeline {
stage('Deploy') { stage('Deploy') {
steps { steps {
script { script {
// Use sshagent for passwordless deployment sh """
sshagent([env.SSH_CRED]) { 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
# 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
'
echo "✅ Deployment finished" # Copy build to remote server
""" scp -i ${SSH_KEY_PATH} -o StrictHostKeyChecking=no build.tar.gz ${SSH_USER}@${WEB_IP}:/tmp/build.tar.gz
}
# 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"
"""
} }
} }
} }