Add Jenkinsfile for Jenkins pipeline
This commit is contained in:
parent
ac9b5a9731
commit
86a891ad39
47
Jenkinsfile
vendored
Normal file
47
Jenkinsfile
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools { nodejs 'Node18' }
|
||||
environment {
|
||||
WEB_IP = '13.49.223.142' // your EC2 web server IP
|
||||
SSH_CRED = 'deploy-ec2-key' // Jenkins credential ID for SSH key
|
||||
}
|
||||
stages {
|
||||
stage('Checkout') { steps { checkout scm } }
|
||||
stage('Install') { steps { sh 'npm ci || npm install' } }
|
||||
stage('Build') { steps { sh 'npm run build' } }
|
||||
stage('Package') {
|
||||
steps {
|
||||
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
|
||||
tar -czf build.tar.gz -C "$OUT_DIR" .
|
||||
'''
|
||||
archiveArtifacts artifacts: 'build.tar.gz'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sshagent(credentials: [env.SSH_CRED]) {
|
||||
sh '''
|
||||
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
|
||||
'
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success { echo "✅ Deployed successfully" }
|
||||
failure { echo "❌ Failed — check console" }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user