From 3efae68bad90f32483dde3e3921a3c1a1affcbe0 Mon Sep 17 00:00:00 2001 From: mohsentaba Date: Mon, 3 Aug 2026 14:51:44 +0330 Subject: [PATCH] prod --- Jenkinsfile | 77 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c046c2b..a4e900e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,35 +1,72 @@ pipeline { environment { - develop_server_ip = '' - develop_server_name = '' - production_server_ip = "88.99.212.243" - production_server_name = "newhorizon_germany_001_server" - project_path = "/projects/imam-javad/imam-javad_backend" - version = "master" - gitBranch = "origin/master" + production_server_ip = "46.173.16.83" + production_server_name = "4e1f741c-3f7a-407d-904e-6778ec6e6219" + project_path = "/projects/dovodi/dovodi-backend" + gitBranch = "origin/master" } agent any stages { - stage('deploy'){ - steps{ - script{ - if(gitBranch=="origin/master"){ + stage('šŸš€ Deploy Dovodi Backend (Background Build)') { + when { expression { gitBranch == "origin/master" } } + steps { + script { + try { withCredentials([usernamePassword(credentialsId: production_server_name, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { - sh 'sshpass -p $PASSWORD ssh -p 1782 $USERNAME@$production_server_ip -o StrictHostKeyChecking=no "cd $project_path && ./runner.sh"' - - 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='Project name: #${env.JOB_NAME} \nBuild status is ${currentBuild.currentResult} \nBuild url: ${BUILD_URL} \nLast Commit: ${lastCommit}' \ - https://api.telegram.org/bot7207581748:AAFeymryw7S44D86LYfWqYK-tSNeV3TOwBs/sendDocument + 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 + 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 } } } } } } -