diff --git a/Jenkinsfile b/Jenkinsfile index 52a5257..602ee6e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,42 +37,36 @@ pipeline { stage('Deploy to VM') { steps { - // Use Jenkins credentials (username + password) 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 - 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 - ''' - // Upload frontend build - sh ''' + echo "Uploading frontend build ..." sshpass -p "$PASS" rsync -avz --delete \ - -e "ssh -o StrictHostKeyChecking=no" \ - frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/ - ''' + -e "ssh -o StrictHostKeyChecking=no" \ + frontend/dist/ $USER@$DEPLOY_HOST:$APP_DIR/frontend/dist/ - // Upload backend code - sh ''' + echo "Uploading backend ..." sshpass -p "$PASS" rsync -avz --delete \ - -e "ssh -o StrictHostKeyChecking=no" \ - backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/ - ''' + -e "ssh -o StrictHostKeyChecking=no" \ + backend/ $USER@$DEPLOY_HOST:$APP_DIR/backend/ - // Restart backend service - sh ''' + 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 - " - ''' + $USER@$DEPLOY_HOST " + cd $APP_DIR/backend && + source venv/bin/activate && + sudo systemctl restart mitm-webserver-backend.service + " + ''' } } } + } post {