diff --git a/Jenkinsfile b/Jenkinsfile index a4e900e..c4601b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,62 +11,41 @@ pipeline { when { expression { gitBranch == "origin/master" } } steps { script { - try { - withCredentials([usernamePassword(credentialsId: production_server_name, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { - sh """ - sshpass -p \$PASSWORD ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=120 \$USERNAME@${production_server_ip} << 'EOF' - - cd ${project_path} - - echo "⏳ Starting runner.sh in background to prevent timeout..." - - rm -f /tmp/dovodi_backend_deploy_status.txt - rm -f /tmp/dovodi_backend_runner_deploy.log - - nohup bash -c './runner.sh && echo "SUCCESS" > /tmp/dovodi_backend_deploy_status.txt || echo "FAIL" > /tmp/dovodi_backend_deploy_status.txt' > /tmp/dovodi_backend_runner_deploy.log 2>&1 & - - echo "⏳ Process is running. Waiting for build and deploy to finish..." - - while true; do - if [ -f /tmp/dovodi_backend_deploy_status.txt ]; then - STATUS=\$(cat /tmp/dovodi_backend_deploy_status.txt) - if [ "\$STATUS" = "SUCCESS" ]; then - echo "✅ Deployment completed successfully!" - break - else - echo "❌ ERROR: Deployment failed! Last 20 lines of log:" - tail -n 20 /tmp/dovodi_backend_runner_deploy.log - exit 1 - fi + withCredentials([usernamePassword(credentialsId: production_server_name, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + sh """ + sshpass -p \$PASSWORD ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=120 \$USERNAME@${production_server_ip} << 'EOF' + + cd ${project_path} + + echo "⏳ Starting runner.sh in background to prevent timeout..." + + rm -f /tmp/dovodi_backend_deploy_status.txt + rm -f /tmp/dovodi_backend_runner_deploy.log + + nohup bash -c './runner.sh && echo "SUCCESS" > /tmp/dovodi_backend_deploy_status.txt || echo "FAIL" > /tmp/dovodi_backend_deploy_status.txt' > /tmp/dovodi_backend_runner_deploy.log 2>&1 & + + echo "⏳ Process is running. Waiting for build and deploy to finish..." + + while true; do + if [ -f /tmp/dovodi_backend_deploy_status.txt ]; then + STATUS=\$(cat /tmp/dovodi_backend_deploy_status.txt) + if [ "\$STATUS" = "SUCCESS" ]; then + echo "✅ Deployment completed successfully!" + break + else + echo "❌ ERROR: Deployment failed! Last 20 lines of log:" + tail -n 20 /tmp/dovodi_backend_runner_deploy.log + exit 1 fi - sleep 10 - done + fi + sleep 10 + done EOF - """ - } - - def lastCommit = sh(script: 'git log -1 --pretty=format:"%h - %s (%an)"', returnStdout: true).trim() - sh """ - curl -F chat_id=1457670318 \ - -F message_thread_id=6 \ - -F document=@/var/jenkins_home/jobs/${env.JOB_NAME}/builds/${env.BUILD_NUMBER}/log \ - -F caption='🚀 Dovodi Backend Deployment: SUCCESS \n📦 Project: #${env.JOB_NAME} \n🔗 Commit: ${lastCommit} \n🌐 URL: ${env.BUILD_URL}' \ - https://api.telegram.org/bot7207581748:AAFeymryw7S44D86LYfWqYK-tSNeV3TOwBs/sendDocument - """ - } catch (Exception e) { - currentBuild.result = 'FAILURE' - def lastCommit = sh(script: 'git log -1 --pretty=format:"%h - %s (%an)"', returnStdout: true).trim() - sh """ - curl -F chat_id=1457670318 \ - -F message_thread_id=6 \ - -F document=@/var/jenkins_home/jobs/${env.JOB_NAME}/builds/${env.BUILD_NUMBER}/log \ - -F caption='❌ Dovodi Backend Deployment: FAILED \n📦 Project: #${env.JOB_NAME} \n🔗 Commit: ${lastCommit} \n🌐 URL: ${env.BUILD_URL}' \ - https://api.telegram.org/bot7207581748:AAFeymryw7S44D86LYfWqYK-tSNeV3TOwBs/sendDocument """ - throw e } } } } } } +