Trigger fresh Jenkins build
This commit is contained in:
parent
cf07732b36
commit
93e6864431
59
Jenkinsfile
vendored
59
Jenkinsfile
vendored
@ -2,72 +2,77 @@ pipeline {
|
||||
agent any
|
||||
|
||||
tools {
|
||||
nodejs 'Node' // Name of your NodeJS installation in Jenkins
|
||||
nodejs 'Node' // Make sure 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 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
|
||||
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
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
echo "🔄 Checking out code..."
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Dependencies') {
|
||||
stage('Install') {
|
||||
steps {
|
||||
echo "📦 Installing npm dependencies..."
|
||||
sh 'npm ci'
|
||||
sh '''
|
||||
echo "📦 Installing dependencies..."
|
||||
npm ci
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh '''
|
||||
echo "🏗️ Building project..."
|
||||
sh 'npm run build'
|
||||
npm run build
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Package Build') {
|
||||
stage('Package') {
|
||||
steps {
|
||||
script {
|
||||
def outDir = fileExists('dist') ? 'dist' : 'build'
|
||||
if (!fileExists(outDir)) {
|
||||
error "❌ Build output not found in 'build/' or 'dist/'!"
|
||||
}
|
||||
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
|
||||
|
||||
echo "📦 Packaging build output..."
|
||||
sh "tar -czf build.tar.gz -C ${outDir} ."
|
||||
tar -czf build.tar.gz -C "$OUT_DIR" .
|
||||
'''
|
||||
archiveArtifacts artifacts: 'build.tar.gz'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
script {
|
||||
sshagent(credentials: [env.SSH_CRED]) {
|
||||
echo "🚀 Deploying build to ${WEB_IP}..."
|
||||
// Use sshagent in a script block
|
||||
sshagent([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"
|
||||
"""
|
||||
echo "✅ Deployment finished!"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +80,7 @@ pipeline {
|
||||
}
|
||||
|
||||
post {
|
||||
success { echo "🎉 Pipeline completed successfully!" }
|
||||
success { echo "✅ Pipeline completed successfully" }
|
||||
failure { echo "❌ Pipeline failed — check console log" }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user