Trigger fresh Jenkins build
This commit is contained in:
parent
ba0e4915f5
commit
8003e8992e
35
Jenkinsfile
vendored
35
Jenkinsfile
vendored
@ -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
|
# 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"
|
||||||
"""
|
"""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user