diff --git a/Jenkinsfile b/Jenkinsfile index 602ee6e..2472a59 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,21 +2,23 @@ pipeline { agent any environment { - DEPLOY_HOST = "192.168.178.180" - DEPLOY_USER = "ubuntu" - APP_DIR = "/srv/mitm-webserver" + DEPLOY_HOST = "192.168.178.180" // your VM IP or hostname + DEPLOY_USER = "deployuser" // user on the VM + APP_DIR = "/srv/mitm-webserver" // deploy target directory } stages { stage('Checkout') { steps { - git branch: 'main', url: 'http://192.168.178.96:3000/marcus/mitm-webserver.git' + echo "📦 Checking out source code from Gitea..." + git branch: 'main', url: 'https://gitea.yourdomain.com/youruser/mitm-webserver.git' } } stage('Build Frontend') { steps { dir('frontend') { + echo "⚙️ Building frontend..." sh 'npm ci' sh 'npm run build' } @@ -26,6 +28,7 @@ pipeline { stage('Prepare Backend') { steps { dir('backend') { + echo "🐍 Preparing backend..." sh ''' python3 -m venv venv ./venv/bin/pip install --upgrade pip @@ -37,44 +40,54 @@ pipeline { stage('Deploy to VM') { steps { - withCredentials([usernamePassword(credentialsId: 'deploy-pass-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) { - sh ''' - # Install sshpass if missing + echo "🚀 Deploying mitm-webserver to ${DEPLOY_HOST}..." + + withCredentials([usernamePassword( + credentialsId: 'deploy-pass-id', // Jenkins credential ID + usernameVariable: 'USER', + passwordVariable: 'PASS' + )]) { + + sh ''' + # Ensure sshpass is installed if ! command -v sshpass >/dev/null 2>&1; then - echo "Installing sshpass..." - sudo apt-get update -y && sudo apt-get install -y sshpass + echo "Installing sshpass..." + sudo apt-get update -y && sudo apt-get install -y sshpass fi - echo "Uploading frontend build ..." - sshpass -p "$PASS" rsync -avz --delete \ - -e "ssh -o StrictHostKeyChecking=no" \ - frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/ + echo "🔌 Testing SSH connection..." + sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 $USER@$DEPLOY_HOST "echo '✅ Connected to $HOSTNAME'" - echo "Uploading backend ..." + echo "📤 Uploading frontend build..." sshpass -p "$PASS" rsync -avz --delete \ - -e "ssh -o StrictHostKeyChecking=no" \ - backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/ + -e "ssh -o StrictHostKeyChecking=no" \ + frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/ - echo "Restarting backend service ..." - sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no \ - $USER@$DEPLOY_HOST " + echo "📤 Uploading backend..." + sshpass -p "$PASS" rsync -avz --delete \ + -e "ssh -o StrictHostKeyChecking=no" \ + backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/ + + echo "🔁 Restarting backend service..." + sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $USER@$DEPLOY_HOST " cd $APP_DIR/backend && source venv/bin/activate && sudo systemctl restart mitm-webserver-backend.service " - ''' + + echo "✅ Deployment finished successfully." + ''' } } } - } post { success { - echo '✅ Deployment successful (password-based SSH)!' + echo '✅ mitm-webserver deployed successfully!' } failure { - echo '❌ Deployment failed!' + echo '❌ Deployment failed. Check Jenkins logs for details.' } } }