Trigger fresh Jenkins build
This commit is contained in:
parent
c39a973ad9
commit
cf07732b36
82
Jenkinsfile
vendored
82
Jenkinsfile
vendored
@ -2,82 +2,80 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
tools {
|
tools {
|
||||||
nodejs 'Node' // Jenkins -> Global Tool Config -> NodeJS must be named "Node"
|
nodejs 'Node' // Name of your NodeJS installation in Jenkins
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
WEB_IP = '13.49.223.142' // update if EC2 IP changes
|
WEB_IP = '13.49.223.142' // EC2 Web server IP
|
||||||
SSH_CRED = 'deploy-ec2-key' // Jenkins credential ID for your EC2 SSH key
|
SSH_CRED = 'deploy-ec2-key' // Jenkins credential ID for SSH key
|
||||||
NODE_OPTIONS = "--max_old_space_size=512" // prevent Node from eating all memory
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
|
echo "🔄 Checking out code..."
|
||||||
checkout scm
|
checkout scm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Install') {
|
stage('Install Dependencies') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
echo "📦 Installing npm dependencies..."
|
||||||
echo "📦 Installing dependencies..."
|
sh 'npm ci'
|
||||||
npm install
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
echo "🏗️ Building project..."
|
||||||
echo "🏗️ Building project..."
|
sh 'npm run build'
|
||||||
npm run build
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Package') {
|
stage('Package Build') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
script {
|
||||||
OUT_DIR="build"
|
def outDir = fileExists('dist') ? 'dist' : 'build'
|
||||||
[ -d dist ] && OUT_DIR="dist"
|
if (!fileExists(outDir)) {
|
||||||
|
error "❌ Build output not found in 'build/' or 'dist/'!"
|
||||||
if [ ! -d "$OUT_DIR" ]; then
|
}
|
||||||
echo "❌ ERROR: No build output found (build/ or dist/)"
|
|
||||||
ls -la
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "📦 Packaging build output..."
|
echo "📦 Packaging build output..."
|
||||||
tar -czf build.tar.gz -C "$OUT_DIR" .
|
sh "tar -czf build.tar.gz -C ${outDir} ."
|
||||||
'''
|
archiveArtifacts artifacts: 'build.tar.gz'
|
||||||
archiveArtifacts artifacts: 'build.tar.gz'
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
steps {
|
steps {
|
||||||
sshagent(credentials: [env.SSH_CRED]) {
|
script {
|
||||||
sh '''
|
sshagent(credentials: [env.SSH_CRED]) {
|
||||||
echo "🚀 Deploying to ${WEB_IP} ..."
|
echo "🚀 Deploying build to ${WEB_IP}..."
|
||||||
scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz
|
sh """
|
||||||
|
scp -o StrictHostKeyChecking=no build.tar.gz deploy@${WEB_IP}:/tmp/build.tar.gz
|
||||||
ssh -o StrictHostKeyChecking=no deploy@${WEB_IP} '
|
ssh -o StrictHostKeyChecking=no deploy@${WEB_IP} '
|
||||||
sudo rm -rf /var/www/reactapp/*;
|
sudo rm -rf /var/www/reactapp/*
|
||||||
sudo mkdir -p /var/www/reactapp;
|
sudo mkdir -p /var/www/reactapp
|
||||||
sudo tar -xzf /tmp/build.tar.gz -C /var/www/reactapp;
|
sudo tar -xzf /tmp/build.tar.gz -C /var/www/reactapp
|
||||||
sudo systemctl reload nginx
|
sudo systemctl reload nginx
|
||||||
'
|
'
|
||||||
|
"""
|
||||||
echo "✅ Deployment finished"
|
echo "✅ Deployment finished!"
|
||||||
'''
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success { echo "✅ Pipeline completed successfully" }
|
success { echo "🎉 Pipeline completed successfully!" }
|
||||||
failure { echo "❌ Pipeline failed — check console log" }
|
failure { echo "❌ Pipeline failed — check console log" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user