jenkins update

This commit is contained in:
Marcus Almert
2025-10-29 15:34:00 +01:00
parent 21a1f1043c
commit 2c0744c033

16
Jenkinsfile vendored
View File

@@ -37,32 +37,25 @@ pipeline {
stage('Deploy to VM') { stage('Deploy to VM') {
steps { steps {
// Use Jenkins credentials (username + password)
withCredentials([usernamePassword(credentialsId: 'deploy-pass-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) { withCredentials([usernamePassword(credentialsId: 'deploy-pass-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
// Install sshpass if not available
sh ''' sh '''
# Install sshpass if missing
if ! command -v sshpass >/dev/null 2>&1; then if ! command -v sshpass >/dev/null 2>&1; then
echo "Installing sshpass..." echo "Installing sshpass..."
sudo apt-get update -y && sudo apt-get install -y sshpass sudo apt-get update -y && sudo apt-get install -y sshpass
fi fi
'''
// Upload frontend build echo "Uploading frontend build ..."
sh '''
sshpass -p "$PASS" rsync -avz --delete \ sshpass -p "$PASS" rsync -avz --delete \
-e "ssh -o StrictHostKeyChecking=no" \ -e "ssh -o StrictHostKeyChecking=no" \
frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/ frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/
'''
// Upload backend code echo "Uploading backend ..."
sh '''
sshpass -p "$PASS" rsync -avz --delete \ sshpass -p "$PASS" rsync -avz --delete \
-e "ssh -o StrictHostKeyChecking=no" \ -e "ssh -o StrictHostKeyChecking=no" \
backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/ backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/
'''
// Restart backend service echo "Restarting backend service ..."
sh '''
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no \ sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no \
$USER@$DEPLOY_HOST " $USER@$DEPLOY_HOST "
cd $APP_DIR/backend && cd $APP_DIR/backend &&
@@ -73,6 +66,7 @@ pipeline {
} }
} }
} }
} }
post { post {